-
Notifications
You must be signed in to change notification settings - Fork 5
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
Conversation
CMakeLists.txt
Outdated
@@ -49,13 +53,17 @@ if (gazebo_VERSION_MAJOR LESS 7.0) | |||
endif() | |||
|
|||
find_package(FMILibrary REQUIRED) | |||
if (NOT FMILibary_FOUND}) |
There was a problem hiding this comment.
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
There was a problem hiding this 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.
The compromise we found in iDynTree/YARP/ICUB is: there is always an option |
@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. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FMI_ROOT
--> FMILibrary_ROOT
…ackage and FetchContent
The requested changes addressed in this commit |
Feature #2 |
CMakeLists.txt
Outdated
if (USES_SYSTEM_FMILIBRARY) | ||
find_package(FMILibrary REQUIRED) | ||
else() | ||
message("Could not find FMILIbrary package. Downloading it using FetchContent...") |
There was a problem hiding this comment.
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.
There was a problem hiding this 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:
- For consistency with YCM's superbuild, I would name the option
USE_SYSTEM_FMILIBRARY
. I know in iDynTree we have optionsIDYNTREE_USES_SOMETHING
, butUSE_SYSTEM_
stuff is mostly used in superbuild. - Considering that the internal FMILibrary will also be installed by the project (given how the
add_subdirectory
workflow works), I think it is extremely bad to enable this option by default. Similarly to what we done in iDynTree (https://github.com/robotology/idyntree/blob/master/cmake/iDynTreeDependencies.cmake#L14) and discussed in Use CMake's FetchContent module to (optionally) download and build FMILibrary #23 (comment) , I think the best option is to first search for FMILibrary, and use the presence or not of the library to set the default value of the option, something like:
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()
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. |
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`. | ||
|
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there!
haha ;D sorry for being ignorant. Making the changes. |
Thanks! |
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.