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
20 changes: 14 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (C) 2018 Fondazione Istituto Italiano di Tecnologia
#
# Licensed under either the GNU Lesser General Public License v3.0 :
#
# Licensed under either the GNU Lesser General Public License v3.0 :
# https://www.gnu.org/licenses/lgpl-3.0.html
# or the GNU Lesser General Public License v2.1 :
# https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
Expand All @@ -24,6 +24,9 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}"
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}")

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
if (CMAKE_VERSION VERSION_LESS 3.11)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake-3.11)
endif()

option(BUILD_SHARED_LIBS "Build libraries as shared as opposed to static" ON)

Expand All @@ -33,6 +36,7 @@ if(BUILD_TESTING)
enable_testing()
endif()


# Encourage user to specify a build type (e.g. Release, Debug, etc.), otherwise set it to Release.
if(NOT CMAKE_CONFIGURATION_TYPES)
if(NOT CMAKE_BUILD_TYPE)
Expand All @@ -48,14 +52,20 @@ if (gazebo_VERSION_MAJOR LESS 7.0)
message(FATAL_ERROR "Your Gazebo version is older than Gazebo 7.0. Gazebo Yarp plugins are supported with gazebo versions >= 7.0. Please update to a newer version")
endif()

find_package(FMILibrary REQUIRED)
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)
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

endif()

# Add extern libraries vendored (only used for the tests)
if(BUILD_TESTING)
add_subdirectory(extern)
endif()

# Add plugins
# Add plugins
add_subdirectory(plugins)

include(InstallBasicPackageFiles)
Expand All @@ -69,5 +79,3 @@ install_basic_package_files(${PROJECT_NAME}

# Add the uninstall target
include(AddUninstallTarget)


11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


# About versioning
The project is undergoing _heavy_ development: APIs may still be subject to changes, and some functionalities may be broken.
The project is undergoing _heavy_ development: APIs may still be subject to changes, and some functionalities may be broken.


# Background
Expand All @@ -28,10 +28,12 @@ gazebo-fmi depends on
- [Gazebo](http://gazebosim.org/) - `version >= 7`
- [FMILibrary](https://jmodelica.org/) (see https://github.com/svn2github/FMILibrary for an updated GitHub mirror) - `version >= 2.0.3`

We recommend to install Gazebo as described in [official documentation](http://gazebosim.org/tutorials?cat=install),
while for FMILibrary the easiest option is to compile it as any CMake project and then add its installation prefix to [`CMAKE_PREFIX_PATH`](https://cmake.org/cmake/help/v3.10/variable/CMAKE_PREFIX_PATH.html).
We recommend to install Gazebo as described in [official documentation](http://gazebosim.org/tutorials?cat=install).
For FMILibrary, one option is to compile it as any CMake project and then add its installation prefix to [`CMAKE_PREFIX_PATH`](https://cmake.org/cmake/help/v3.10/variable/CMAKE_PREFIX_PATH.html).
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.

FMI_ROOT --> FMILibrary_ROOT

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.

# Build the plugins
Use the following commands to build and install the plugin.

Expand Down Expand Up @@ -66,7 +68,8 @@ See plugin-specific documentation on how to use each plugin:
# Test the plugins
For running the automatic tests of the plugins contained in this repo, you need the additional dependency of the [OpenModelica](https://openmodelica.org/) compiler. The OpenModelica compiler is used to generate test FMUs from [Modelica](https://www.modelica.org/) models. We recommend to use OpenModelica at least version 1.13 (the `nightly` version as of August 2018) as OpenModelica 1.12 has several bugs related to FMU generation (see https://github.com/robotology/gazebo-fmi/issues/5 and https://trac.openmodelica.org/OpenModelica/ticket/4135 ).

Once you installed OpenModelica on your system, you can regenerated the project with the `BUILD_TESTING` CMake option set to `ON` to compile the tests. Once test are compiled, you can run them using [ctest](https://cmake.org/cmake/help/latest/manual/ctest.1.html), for example run:

Once you installed OpenModelica on your system, you can regenerated the project with the `BUILD_TESTING` CMake option set to `ON` to compile the tests. Once test are compiled, you can run them using [ctest](https://cmake.org/cmake/help/latest/manual/ctest.1.html), for example run:
```cmake
$ ctest [-VV]
```
Expand Down
34 changes: 34 additions & 0 deletions cmake/FetchFMILibrary.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright (C) 2018 Fondazione Istituto Italiano di Tecnologia
#
# Licensed under either the GNU Lesser General Public License v3.0 :
# https://www.gnu.org/licenses/lgpl-3.0.html
# or the GNU Lesser General Public License v2.1 :
# https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
# at your option.

# Fetch FMI library for downloading and installing
include(FetchContent)
FetchContent_Declare(FMILibrary
GIT_REPOSITORY https://github.com/svn2github/FMILibrary.git)

FetchContent_GetProperties(FMILibrary)
if(NOT FMILibrary_POPULATED)
FetchContent_Populate(FMILibrary)
set(BUILD_SHARED_LIBS OFF)
option (FMILIB_BUILD_TESTS "Build tests" OFF)
add_subdirectory(${fmilibrary_SOURCE_DIR} ${fmilibrary_BINARY_DIR})
set(BUILD_SHARED_LIBS ON)
endif()

add_library(FMILibrary_FMILibrary INTERFACE)
target_include_directories(FMILibrary_FMILibrary INTERFACE ${fmilibrary_SOURCE_DIR}/src/CAPI/include
${fmilibrary_SOURCE_DIR}/src/Import/include
${fmilibrary_SOURCE_DIR}/src/Util/include
${fmilibrary_SOURCE_DIR}/src/XML/include
${fmilibrary_SOURCE_DIR}/src/ZIP/include
${fmilibrary_SOURCE_DIR}/ThirdParty/FMI/default
${fmilibrary_SOURCE_DIR}/Config.cmake
${fmilibrary_BINARY_DIR})
target_link_libraries(FMILibrary_FMILibrary INTERFACE fmilib)
add_library(FMILibrary::FMILibrary ALIAS FMILibrary_FMILibrary)

20 changes: 10 additions & 10 deletions cmake/FindFMILibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ if(FMILibrary_LIBRARY AND FMILibrary_INCLUDE_DIR AND NOT TARGET FMILibrary::FMIL

set(FMILibrary_LIBRARIES FMILibrary::FMILibrary)
set(FMILibrary_INCLUDE_DIRS "${FMILibrary_INCLUDE_DIR}")
endif()


include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FMILibrary
FOUND_VAR FMILibrary_FOUND
REQUIRED_VARS FMILibrary_LIBRARIES FMILibrary_INCLUDE_DIRS)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FMILibrary
FOUND_VAR FMILibrary_FOUND
REQUIRED_VARS FMILibrary_LIBRARIES FMILibrary_INCLUDE_DIRS)

# Set package properties if FeatureSummary was included
if(COMMAND set_package_properties)
set_package_properties(FMILibrary PROPERTIES DESCRIPTION "FMILibrary"
URL "http://www.jmodelica.org/FMILibrary")
# Set package properties if FeatureSummary was included
if(COMMAND set_package_properties)
set_package_properties(FMILibrary PROPERTIES DESCRIPTION "FMILibrary"
URL "http://www.jmodelica.org/FMILibrary")
endif()
endif()

Loading