NTNU-IHB / FMI4cpp

FMI 2.0 implementation written in modern C++.
MIT License
96 stars 35 forks source link

Feature/vcpkg support #17

Closed markaren closed 5 years ago

markaren commented 5 years ago

Updates the CMake files so that it can be cleanly installed by vcpkg. To use the library, client applications just need to add

find_package(FMI4cpp CONFIG REQUIRED)
target_link_libraries(main PRIVATE FMI4cpp::FMI4cpp)

Note: when building fmi4cpp on windows -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON needs to be passed to CMake (this is done by the vcpkg port)

@traversaro I basically had to rewrite the install code as I was following this example. Please have a look.

Relates to #4

markaren commented 5 years ago

There might be an issue on linux. Will investigate and update the pull request later.

traversaro commented 5 years ago

I tried this branch.

Note: when building fmi4cpp on windows -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON needs to be passed to CMake (this is done by the vcpkg port)

I suggest to move this to the main CMakeLists.txt, to simplify the process of building this library with BUILD_SHARED_LIBS outside of vcpkg, for using ExternalProject (useful for CMake-based superbuilds) of for including this library inside of another project using FetchContent and add_subdirectory.

Furthermore, on an empty build on Ubuntu 18.04, I have this error:

 CMake Error at CMakeLists.txt:18 (string):
   string sub-command COMPARE, mode EQUAL needs at least 5 arguments total to
   command.

this is because the line string(COMPARE EQUAL ${CMAKE_BUILD_TYPE} "Debug" DEBUG_MODE) is equivalent to string(COMPARE EQUAL "Debug" DEBUG_MODE) if CMAKE_BUILD_TYPE is empty (the default value). Substituting it with string(COMPARE EQUAL "${CMAKE_BUILD_TYPE}" "Debug" DEBUG_MODE) fixes this specific problem, but that logic is still broken for multiple-config generators such as Visual Studio. You may be interested in substuting all that logic with a simple target_compile_definitions call once the ${FMI4CPP_LIB} library has been created:

target_compile_definitions(${FMI4CPP_LIB} PRIVATE $<$<CONFIG:Debug>:DEBUG_LOGGING_ENABLED>)

See https://cmake.org/cmake/help/v3.12/manual/cmake-generator-expressions.7.html for more info on the generator expressions.

markaren commented 5 years ago

this is because the line string(COMPARE EQUAL ${CMAKE_BUILD_TYPE} "Debug" DEBUG_MODE) is equivalent to string(COMPARE EQUAL "Debug" DEBUG_MODE) if CMAKE_BUILD_TYPE is empty (the default value). Substituting it with string(COMPARE EQUAL "${CMAKE_BUILD_TYPE}" "Debug" DEBUG_MODE) fixes this specific problem, but that logic is still broken for multiple-config generators such as Visual Studio. You may be interested in substuting all that logic with a simple target_compile_definitions call once the ${FMI4CPP_LIB} library has been created:

target_compile_definitions(${FMI4CPP_LIB} PRIVATE $<$<CONFIG:Debug>:DEBUG_LOGGING_ENABLED>)

Thanks, tested the target_compile_definitionssolution. Seems more elegant, applying to dev directly.

markaren commented 5 years ago

Note: when building fmi4cpp on windows -DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON needs to be passed to CMake (this is done by the vcpkg port)

I suggest to move this to the main CMakeLists.txt, to simplify the process of building this library with BUILD_SHARED_LIBS outside of vcpkg, for using ExternalProject (useful for CMake-based superbuilds) of for including this library inside of another project using FetchContent and add_subdirectory.

I'm adding this directly to the project's CMakeList.txt as suggested.