Skip to content

Commit b1333ef

Browse files
committed
Upgrade to Conan 2
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.)
1 parent 9dff0ad commit b1333ef

13 files changed

+133
-313
lines changed

CMakeLists.txt

Lines changed: 6 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cmake_minimum_required(VERSION 3.9)
1+
cmake_minimum_required(VERSION 3.19)
22
file(STRINGS "${CMAKE_SOURCE_DIR}/version.txt" projectVersion)
33
project("libcosim" VERSION ${projectVersion})
44
message("Current libcosim version: ${CMAKE_PROJECT_VERSION}\n")
@@ -13,8 +13,6 @@ option(LIBCOSIM_BUILD_TESTS "Build test suite" ON)
1313
option(LIBCOSIM_BUILD_APIDOC "Build API documentation (requires Doxygen)" ON)
1414
option(LIBCOSIM_BUILD_PRIVATE_APIDOC "Build private API documentation (only used if LIBCOSIM_BUILD_APIDOC=ON)" OFF)
1515
option(LIBCOSIM_STANDALONE_INSTALLATION "Whether to build for a standalone installation (Linux only; sets a relative RPATH)" OFF)
16-
option(LIBCOSIM_USING_CONAN "Whether Conan is used for package management" OFF)
17-
option(LIBCOSIM_USING_CONAN_AUTO_CONFIG "Whether Conan should be configured automatically by CMake" OFF)
1816
option(LIBCOSIM_WITH_PROXYFMU "Whether or not to build with proxy-fmu integration" OFF)
1917
option(LIBCOSIM_NO_FMI_LOGGING "Disable FMI logging during simulation" OFF)
2018

@@ -98,44 +96,6 @@ set(LIBCOSIM_EXPORT_TARGET "${PROJECT_NAME}-targets")
9896
# Dependencies
9997
# ==============================================================================
10098

101-
if(LIBCOSIM_USING_CONAN)
102-
if(NOT LIBCOSIM_USING_CONAN_AUTO_CONFIG OR CONAN_EXPORTED)
103-
# Opting for manual invocation of conan install prior to loading CMake
104-
# or conan create has been invoked, setting CONAN_EXPORTED.
105-
if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
106-
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
107-
conan_basic_setup(NO_OUTPUT_DIRS)
108-
else()
109-
message(FATAL_ERROR "The file conanbuildinfo.cmake doesn't exist, you have to run conan install first")
110-
endif()
111-
else()
112-
# Auto config specified and conan create is not running.
113-
# We'll let CMake run the conan commands for us.
114-
115-
# This is where the magic happens.
116-
# The file has been modified to search for the conan executable on linux systems.
117-
include(cmake/conan.cmake)
118-
conan_cmake_autodetect(settings)
119-
120-
set(proxyfmu_option False)
121-
if(LIBCOSIM_WITH_PROXYFMU)
122-
set(proxyfmu_option True)
123-
endif()
124-
125-
# Force add osp remote
126-
conan_add_remote(NAME osp URL https://osp.jfrog.io/artifactory/api/conan/conan-local)
127-
128-
# Run conan install with auto-detected settings and -b missing flag
129-
# and -o proxyfmu=True if LIBCOSIM_WITH_PROXYFMU=ON
130-
conan_cmake_run(
131-
CONANFILE conanfile.py
132-
OPTIONS proxyfmu=${proxyfmu_option}
133-
BUILD missing
134-
SETTINGS ${settings}
135-
BASIC_SETUP NO_OUTPUT_DIRS)
136-
endif()
137-
endif()
138-
13999
set(Boost_components date_time log)
140100
if (LIBCOSIM_BUILD_TESTS)
141101
list(APPEND Boost_components timer unit_test_framework)
@@ -148,11 +108,11 @@ find_package(Boost REQUIRED COMPONENTS ${Boost_components})
148108
if(BUILD_SHARED_LIBS AND NOT DEFINED FMILibrary_USE_SHARED_LIB)
149109
set(FMILibrary_USE_SHARED_LIB TRUE)
150110
endif()
151-
find_package(FMILibrary REQUIRED)
152-
find_package(LIBZIP REQUIRED)
153-
find_package(MS_GSL REQUIRED)
154-
find_package(YAML_CPP REQUIRED)
155-
find_package(XercesC REQUIRED)
111+
find_package(FMILibrary MODULE REQUIRED)
112+
find_package(libzip REQUIRED)
113+
find_package(Microsoft.GSL REQUIRED)
114+
find_package(yaml-cpp REQUIRED)
115+
find_package(XercesC MODULE REQUIRED)
156116
if(LIBCOSIM_WITH_PROXYFMU)
157117
find_package(PROXYFMU CONFIG REQUIRED)
158118
endif()
@@ -244,9 +204,6 @@ install(FILES "${versionFile}" DESTINATION "${LIBCOSIM_CMAKE_INSTALL_DIR}")
244204
# Install custom find modules
245205
install(FILES
246206
"${CMAKE_SOURCE_DIR}/cmake/FindFMILibrary.cmake"
247-
"${CMAKE_SOURCE_DIR}/cmake/FindLIBZIP.cmake"
248-
"${CMAKE_SOURCE_DIR}/cmake/FindMS_GSL.cmake"
249-
"${CMAKE_SOURCE_DIR}/cmake/FindYAML_CPP.cmake"
250207
DESTINATION
251208
"${LIBCOSIM_CMAKE_INSTALL_DIR}"
252209
)

cmake/FindLIBZIP.cmake

Lines changed: 0 additions & 110 deletions
This file was deleted.

cmake/FindMS_GSL.cmake

Lines changed: 0 additions & 17 deletions
This file was deleted.

cmake/FindYAML_CPP.cmake

Lines changed: 0 additions & 36 deletions
This file was deleted.

cmake/project-config.cmake.in

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
@PACKAGE_INIT@
2+
23
include ("@PACKAGE_targetsFile@")
34

45
include(CMakeFindDependencyMacro)
5-
66
list(APPEND CMAKE_MODULE_PATH "${PACKAGE_PREFIX_DIR}/@LIBCOSIM_CMAKE_INSTALL_DIR@")
7-
8-
find_dependency(MS_GSL REQUIRED)
97
find_dependency(Boost REQUIRED COMPONENTS date_time log)
108
set(FMILibrary_USE_SHARED_LIB @FMILibrary_USE_SHARED_LIB@)
11-
find_dependency(FMILibrary REQUIRED)
12-
find_dependency(LIBZIP REQUIRED)
13-
find_dependency(YAML_CPP REQUIRED)
9+
find_dependency(FMILibrary MODULE REQUIRED)
10+
find_dependency(libzip REQUIRED)
11+
find_dependency(Microsoft.GSL REQUIRED)
12+
find_dependency(yaml-cpp REQUIRED)
1413
find_dependency(XercesC REQUIRED)
15-
1614
if(@LIBCOSIM_WITH_PROXYFMU@)
1715
find_dependency(PROXYFMU CONFIG REQUIRED)
1816
endif()
19-
2017
list(REMOVE_AT CMAKE_MODULE_PATH -1)

0 commit comments

Comments
 (0)