Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CMake's FetchContent module to (optionally) download and build FMILibrary #23

Merged
merged 7 commits into from
Aug 21, 2018

Conversation

prashanthr05
Copy link
Collaborator

Uses CMake 3.11 FetchContent.cmake option to download and compile FMILibrary , if find_package fails to find FMILibrary.

The minimum cmake version is still 3.5. However, the cmake 3.11 specific files are copied into the repository's cmake/cmake-3.11 folder.

@prashanthr05 prashanthr05 requested a review from traversaro August 9, 2018 13:29
CMakeLists.txt Outdated
@@ -49,13 +53,17 @@ if (gazebo_VERSION_MAJOR LESS 7.0)
endif()

find_package(FMILibrary REQUIRED)
if (NOT FMILibary_FOUND})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo, it should be NOT FMILibrary_FOUND

Copy link
Member

@traversaro traversaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, but I think we should never take decision based on the availability of a library at runtime without offering the possibility of toggling this behavior with an option.
Whenever we did that in the past, we had this kind of problems:
When gazebo-fmi library will be integrated in the superbuild, if for some reason the superbuild provided FMILibrary or the system-provided FMILibrary is not found, I want to get a clear error, instead of silently switching to downloading FMILibrary instead.

@traversaro
Copy link
Member

The compromise we found in iDynTree/YARP/ICUB is: there is always an option USE_<dep> or USE_SYSTEM_<dep> , and its default value is initialized to ON or OFF depending on wherever the dep was found in the system or not. However, if the user/superbuild specifies the option, the option is observed. See robotology/idyntree#322 and robotology/idyntree#323 .

@traversaro traversaro changed the title Cmake/fetch content Use CMake's FetchContent.cmake to (optionally) download and build FMILibrary Aug 9, 2018
@traversaro traversaro changed the title Use CMake's FetchContent.cmake to (optionally) download and build FMILibrary Use CMake's FetchContent module to (optionally) download and build FMILibrary Aug 9, 2018
@traversaro
Copy link
Member

@prashanthr05 I edited the title to be more descriptive.

README.md Outdated
See [CGold guide](https://cgold.readthedocs.io/en/latest/first-step.html) if you need some details on how to build a CMake project.

An easier option is provided by the gazebo-fmi repository which downloads and compiles the FMILibrary internally within its build folder using CMake's FetchContent option. This is performed when FMILibrary package is not already existing in the system or if the FMILibrary related environment variable (`FMI_ROOT`) is not set, making gazebo-fmi unable to find FMILibrary package.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FMI_ROOT --> FMILibrary_ROOT

@prashanthr05
Copy link
Collaborator Author

The requested changes addressed in this commit

@prashanthr05
Copy link
Collaborator Author

Feature #2

CMakeLists.txt Outdated
if (USES_SYSTEM_FMILIBRARY)
find_package(FMILibrary REQUIRED)
else()
message("Could not find FMILIbrary package. Downloading it using FetchContent...")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove this message.

Copy link
Member

@traversaro traversaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @prashanthr05 .

Two comments:

find_package(FMILibrary QUIET)
option(USE_SYSTEM_FMILIBRARY "If TRUE/ON use system FMILibrary, otherwise download and compile using FetchContent" ${FMILibrary_FOUND})
if (USE_SYSTEM_FMILIBRARY)
    find_package(FMILibrary REQUIRED)
else()
   include(FetchFMILibrary)
endif()

@traversaro traversaro mentioned this pull request Aug 21, 2018
@traversaro
Copy link
Member

Ok, I just noticed that the default value is not to use the Fetched library. In this case, feel free to decide to stick with the current behavior or to adopt the logic that I suggested in the previous comment.

@prashanthr05
Copy link
Collaborator Author

Addressed the changes. Thanks @traversaro

README.md Outdated
See [CGold guide](https://cgold.readthedocs.io/en/latest/first-step.html) if you need some details on how to build a CMake project.

An easier option is provided by the gazebo-fmi repository which downloads and compiles the FMILibrary internally within its build folder using CMake's FetchContent option. This is performed when FMILibrary package is not already existing in the system or if the FMILibrary related environment variable (`FMILibrary_ROOT`) is not set, making gazebo-fmi unable to find FMILibrary package. To use this option, the CMake option `USES_SYSTEM_FMILIBRARY` should be set to `OFF`.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the docs considering the name variable change.

CMakeLists.txt Outdated
if (USE_SYSTEM_FMILIBRARY)
find_package(FMILibrary REQUIRED)
else()
include(FetchFMILibrary)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 spaces, instead of 4

Copy link
Member

@traversaro traversaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost there!

@prashanthr05
Copy link
Collaborator Author

haha ;D sorry for being ignorant. Making the changes.

@traversaro traversaro merged commit 4a584c6 into master Aug 21, 2018
@traversaro
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants