Skip to content

Commit

Permalink
Upgrade to Conan 2
Browse files Browse the repository at this point in the history
This fixes issue #718 (and incidentally fixes #702 too).

The modified `<gsl/util>` imports and various changes from `int` to
`std::size_t` are a consequence of using a newer version of MS GSL. I
changed the dependency version so we can use an upstream CMake package
configuration file which is compatible with the one generated by Conan
2's `CMakeDeps` generator. This should enable us to use the same
`find_package()` commands and target names regardless of whether the
build is running under Conan or not.

This also removes the ability to run Conan from within CMake, because
upstream hasn't released a version of the cmake-conan helper script with
full support for all Conan 2 features yet. (Notably, support for the
`CMakeToolchain` generator is missing.)
  • Loading branch information
kyllingstad committed Nov 7, 2023
1 parent 9dff0ad commit b1333ef
Show file tree
Hide file tree
Showing 13 changed files with 133 additions and 313 deletions.
55 changes: 6 additions & 49 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.9)
cmake_minimum_required(VERSION 3.19)
file(STRINGS "${CMAKE_SOURCE_DIR}/version.txt" projectVersion)
project("libcosim" VERSION ${projectVersion})
message("Current libcosim version: ${CMAKE_PROJECT_VERSION}\n")
Expand All @@ -13,8 +13,6 @@ option(LIBCOSIM_BUILD_TESTS "Build test suite" ON)
option(LIBCOSIM_BUILD_APIDOC "Build API documentation (requires Doxygen)" ON)
option(LIBCOSIM_BUILD_PRIVATE_APIDOC "Build private API documentation (only used if LIBCOSIM_BUILD_APIDOC=ON)" OFF)
option(LIBCOSIM_STANDALONE_INSTALLATION "Whether to build for a standalone installation (Linux only; sets a relative RPATH)" OFF)
option(LIBCOSIM_USING_CONAN "Whether Conan is used for package management" OFF)
option(LIBCOSIM_USING_CONAN_AUTO_CONFIG "Whether Conan should be configured automatically by CMake" OFF)
option(LIBCOSIM_WITH_PROXYFMU "Whether or not to build with proxy-fmu integration" OFF)
option(LIBCOSIM_NO_FMI_LOGGING "Disable FMI logging during simulation" OFF)

Expand Down Expand Up @@ -98,44 +96,6 @@ set(LIBCOSIM_EXPORT_TARGET "${PROJECT_NAME}-targets")
# Dependencies
# ==============================================================================

if(LIBCOSIM_USING_CONAN)
if(NOT LIBCOSIM_USING_CONAN_AUTO_CONFIG OR CONAN_EXPORTED)
# Opting for manual invocation of conan install prior to loading CMake
# or conan create has been invoked, setting CONAN_EXPORTED.
if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(NO_OUTPUT_DIRS)
else()
message(FATAL_ERROR "The file conanbuildinfo.cmake doesn't exist, you have to run conan install first")
endif()
else()
# Auto config specified and conan create is not running.
# We'll let CMake run the conan commands for us.

# This is where the magic happens.
# The file has been modified to search for the conan executable on linux systems.
include(cmake/conan.cmake)
conan_cmake_autodetect(settings)

set(proxyfmu_option False)
if(LIBCOSIM_WITH_PROXYFMU)
set(proxyfmu_option True)
endif()

# Force add osp remote
conan_add_remote(NAME osp URL https://osp.jfrog.io/artifactory/api/conan/conan-local)

# Run conan install with auto-detected settings and -b missing flag
# and -o proxyfmu=True if LIBCOSIM_WITH_PROXYFMU=ON
conan_cmake_run(
CONANFILE conanfile.py
OPTIONS proxyfmu=${proxyfmu_option}
BUILD missing
SETTINGS ${settings}
BASIC_SETUP NO_OUTPUT_DIRS)
endif()
endif()

set(Boost_components date_time log)
if (LIBCOSIM_BUILD_TESTS)
list(APPEND Boost_components timer unit_test_framework)
Expand All @@ -148,11 +108,11 @@ find_package(Boost REQUIRED COMPONENTS ${Boost_components})
if(BUILD_SHARED_LIBS AND NOT DEFINED FMILibrary_USE_SHARED_LIB)
set(FMILibrary_USE_SHARED_LIB TRUE)
endif()
find_package(FMILibrary REQUIRED)
find_package(LIBZIP REQUIRED)
find_package(MS_GSL REQUIRED)
find_package(YAML_CPP REQUIRED)
find_package(XercesC REQUIRED)
find_package(FMILibrary MODULE REQUIRED)
find_package(libzip REQUIRED)
find_package(Microsoft.GSL REQUIRED)
find_package(yaml-cpp REQUIRED)
find_package(XercesC MODULE REQUIRED)
if(LIBCOSIM_WITH_PROXYFMU)
find_package(PROXYFMU CONFIG REQUIRED)
endif()
Expand Down Expand Up @@ -244,9 +204,6 @@ install(FILES "${versionFile}" DESTINATION "${LIBCOSIM_CMAKE_INSTALL_DIR}")
# Install custom find modules
install(FILES
"${CMAKE_SOURCE_DIR}/cmake/FindFMILibrary.cmake"
"${CMAKE_SOURCE_DIR}/cmake/FindLIBZIP.cmake"
"${CMAKE_SOURCE_DIR}/cmake/FindMS_GSL.cmake"
"${CMAKE_SOURCE_DIR}/cmake/FindYAML_CPP.cmake"
DESTINATION
"${LIBCOSIM_CMAKE_INSTALL_DIR}"
)
110 changes: 0 additions & 110 deletions cmake/FindLIBZIP.cmake

This file was deleted.

17 changes: 0 additions & 17 deletions cmake/FindMS_GSL.cmake

This file was deleted.

36 changes: 0 additions & 36 deletions cmake/FindYAML_CPP.cmake

This file was deleted.

13 changes: 5 additions & 8 deletions cmake/project-config.cmake.in
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
@PACKAGE_INIT@

include ("@PACKAGE_targetsFile@")

include(CMakeFindDependencyMacro)

list(APPEND CMAKE_MODULE_PATH "${PACKAGE_PREFIX_DIR}/@LIBCOSIM_CMAKE_INSTALL_DIR@")

find_dependency(MS_GSL REQUIRED)
find_dependency(Boost REQUIRED COMPONENTS date_time log)
set(FMILibrary_USE_SHARED_LIB @FMILibrary_USE_SHARED_LIB@)
find_dependency(FMILibrary REQUIRED)
find_dependency(LIBZIP REQUIRED)
find_dependency(YAML_CPP REQUIRED)
find_dependency(FMILibrary MODULE REQUIRED)
find_dependency(libzip REQUIRED)
find_dependency(Microsoft.GSL REQUIRED)
find_dependency(yaml-cpp REQUIRED)
find_dependency(XercesC REQUIRED)

if(@LIBCOSIM_WITH_PROXYFMU@)
find_dependency(PROXYFMU CONFIG REQUIRED)
endif()

list(REMOVE_AT CMAKE_MODULE_PATH -1)
Loading

0 comments on commit b1333ef

Please sign in to comment.