From 88a1cf4568cd467a555ddadbdfc99186abaa6bf6 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Tue, 31 Oct 2023 10:14:10 +0100 Subject: [PATCH] Update to Conan 2 --- CMakeLists.txt | 18 +++-------- cmake/FindCLI11.cmake | 19 ------------ cmake/FindTHRIFT.cmake | 39 ----------------------- cmake/project-config.cmake.in | 6 ++-- conanfile.py | 55 ++++++++++++++++++++------------- src/CMakeLists.txt | 2 +- src/proxyfmu/fmi/fmicontext.hpp | 2 ++ src/thrift/CMakeLists.txt | 1 + 8 files changed, 43 insertions(+), 99 deletions(-) delete mode 100644 cmake/FindCLI11.cmake delete mode 100644 cmake/FindTHRIFT.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 36d6266..8c90601 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,8 +26,6 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") set(generatedSourcesDir "${CMAKE_BINARY_DIR}/generated") -set(Boost_USE_STATIC_LIBS ON) - if (MSVC) add_definitions("-D_WIN32_WINNT=0x600" "-D_CRT_SECURE_NO_WARNINGS") add_compile_options("/wd4996" "/wd4251" "/wd4244" "/wd4267") @@ -57,13 +55,8 @@ set(PROXYFMU_EXPORT_TARGET "${PROJECT_NAME}-targets") # Dependencies # ============================================================================== -if (CONAN_EXPORTED) # in conan local cache - # standard conan installation, deps will be defined in conanfile.py - # and not necessary to call conan again, conan is already running - # include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) - # conan_basic_setup() -else () - +if (NOT CONAN_EXPORTED) + # Conan is not already running, so run it to get dependencies. include(cmake/conan.cmake) conan_check(REQUIRED) @@ -75,7 +68,6 @@ else () BUILD missing SETTINGS ${settings} BASIC_SETUP) - endif () set(BOOST_COMPONENTS filesystem) @@ -93,8 +85,8 @@ endif () find_package(Boost 1.71 COMPONENTS ${BOOST_COMPONENTS} REQUIRED) find_package(CLI11 REQUIRED) -find_package(THRIFT REQUIRED) -find_package(FMILIB REQUIRED) +find_package(Thrift REQUIRED) +find_package(FMILIB MODULE REQUIRED) # ============================================================================== @@ -147,9 +139,7 @@ install(FILES "${versionFile}" DESTINATION "${PROXYFMU_CMAKE_INSTALL_DIR}") # Install custom find modules install(FILES - "${CMAKE_SOURCE_DIR}/cmake/FindCLI11.cmake" "${CMAKE_SOURCE_DIR}/cmake/FindFMILIB.cmake" - "${CMAKE_SOURCE_DIR}/cmake/FindTHRIFT.cmake" DESTINATION "${PROXYFMU_CMAKE_INSTALL_DIR}" ) diff --git a/cmake/FindCLI11.cmake b/cmake/FindCLI11.cmake deleted file mode 100644 index 28c4c1a..0000000 --- a/cmake/FindCLI11.cmake +++ /dev/null @@ -1,19 +0,0 @@ -# Finds the CLI11 library. -# -# If found, the following is defined: -# - `CLI11_FOUND` and `CLI11_INCLUDE_DIRS` variables. -# - `CLI11::CLI11` target - -find_path(CLI11_INCLUDE_DIR "CLI/CLI.hpp") -if(CLI11_INCLUDE_DIR) - if (NOT TARGET CLI11::CLI11) - set(CLI11_INCLUDE_DIRS "${CLI11_INCLUDE_DIR}") - add_library(CLI11::CLI11 INTERFACE IMPORTED) - set_target_properties(CLI11::CLI11 PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${CLI11_INCLUDE_DIR}" - ) - endif() -endif() - -include(FindPackageHandleStandardArgs) -find_package_handle_standard_args("CLI11" DEFAULT_MSG "CLI11_INCLUDE_DIRS") diff --git a/cmake/FindTHRIFT.cmake b/cmake/FindTHRIFT.cmake deleted file mode 100644 index 1e506ab..0000000 --- a/cmake/FindTHRIFT.cmake +++ /dev/null @@ -1,39 +0,0 @@ -# Find Thrift -# -# Find the native Thrift headers and libraries. -# -# THRIFT_INCLUDE_DIRS - where to find thrift/thrift.h -# THRIFT_LIBRARIES - List of libraries when using Thrift. -# THRIFT_FOUND - True if Thrift found. -# - -find_path(THRIFT_INCLUDE_DIR NAMES thrift/Thrift.h) -mark_as_advanced(THRIFT_INCLUDE_DIR) - -find_library(THRIFT_LIBRARY NAMES thrift thriftd thriftmd thriftmdd) -mark_as_advanced(THRIFT_LIBRARY) - -find_program(THRIFT_EXECUTABLE NAMES thrift HINTS ${CONAN_THRIFT_ROOT} PATH_SUFFIXES bin bin64) -mark_as_advanced(THRIFT_EXECUTABLE) - -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(THRIFT - REQUIRED_VARS THRIFT_LIBRARY THRIFT_INCLUDE_DIR) - -if (THRIFT_FOUND) - - set(THRIFT_INCLUDE_DIRS ${THRIFT_INCLUDE_DIR}) - - if (NOT THRIFT_LIBRARIES) - set(THRIFT_LIBRARIES ${THRIFT_LIBRARY}) - endif () - - if (NOT TARGET thrift::thrift) - add_library(thrift::thrift UNKNOWN IMPORTED) - set_target_properties(thrift::thrift PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES ${THRIFT_INCLUDE_DIR}) - set_property(TARGET thrift::thrift APPEND PROPERTY - IMPORTED_LOCATION "${THRIFT_LIBRARY}") - endif () - -endif () diff --git a/cmake/project-config.cmake.in b/cmake/project-config.cmake.in index f17d072..1996446 100644 --- a/cmake/project-config.cmake.in +++ b/cmake/project-config.cmake.in @@ -6,9 +6,7 @@ include(CMakeFindDependencyMacro) list(APPEND CMAKE_MODULE_PATH "${PACKAGE_PREFIX_DIR}/@PROXYFMU_CMAKE_INSTALL_DIR@") find_dependency(Boost COMPONENTS filesystem REQUIRED) - -find_dependency(FMILIB REQUIRED) -find_dependency(THRIFT REQUIRED) -find_dependency(CLI11 REQUIRED) +find_dependency(FMILIB MODULE REQUIRED) +find_dependency(Thrift REQUIRED) list(REMOVE_AT CMAKE_MODULE_PATH -1) diff --git a/conanfile.py b/conanfile.py index 9f89866..95f29e7 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,41 +1,50 @@ -import os +from os import path from conan import ConanFile -from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.cmake import CMake from conan.tools.files import load class ProxyFmuConan(ConanFile): name = "proxyfmu" + def set_version(self): + self.version = load(self, path.join(self.recipe_folder, "version.txt")).strip() + author = "osp" license = "MIT" - exports = "version.txt" - exports_sources = "CMakeLists.txt", "version.txt", "src/*", "include/*", "cmake/*", "data*", "tests/*", "tool/*" + url = "https://github.com/open-simulation-platform/proxy-fmu" + + package_type = "library" settings = "os", "compiler", "build_type", "arch" - generators = "CMakeDeps" - requires = ( - "cli11/2.3.1", - "fmilibrary/2.3", - "thrift/0.13.0" - ) options = { - "shared": [True, False] + "shared": [True, False], + "fPIC": [True, False] } default_options = { - "shared": True + "shared": True, + "fPIC": True } - def set_version(self): - self.version = load(self, os.path.join(self.recipe_folder, "version.txt")).strip() + tool_requires = "thrift/[~0.13]" # Thrift compiler + requires = ( + "boost/[>=1.71]", + "cli11/[~2.3]", + "fmilibrary/[~2.3]", + "thrift/[~0.13]" + ) + + exports = "version.txt" + exports_sources = "*" + + generators = "CMakeDeps", "CMakeToolchain" - def layout(self): - cmake_layout(self) + def config_options(self): + if self.settings.os == "Windows": + del self.options.fPIC - def generate(self): - tc = CMakeToolchain(self) - tc.cache_variables["BUILD_SHARED_LIBS"] = self.options.shared - tc.cache_variables["CONAN_EXPORTED"] = True - tc.generate() + def configure(self): + if self.options.shared: + self.options.rm_safe("fPIC") def build(self): cmake = CMake(self) @@ -48,4 +57,6 @@ def package(self): def package_info(self): self.cpp_info.libs = ["proxyfmu-client"] - self.cpp_info.defines = ["Boost_USE_STATIC_LIBS=ON"] + # Tell consumers to use "our" CMake package config file. + self.cpp_info.builddirs.append(".") + self.cpp_info.set_property("cmake_find_mode", "none") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 64874b4..190b449 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -121,7 +121,7 @@ target_include_directories(proxyfmu-client target_link_libraries(proxyfmu-client PUBLIC fmilibwrapper - PRIVATE + #PRIVATE # Temporarily disabled due to https://github.com/conan-io/conan/issues/13302 thrift::thrift Boost::filesystem ) diff --git a/src/proxyfmu/fmi/fmicontext.hpp b/src/proxyfmu/fmi/fmicontext.hpp index f0c9420..22da42a 100644 --- a/src/proxyfmu/fmi/fmicontext.hpp +++ b/src/proxyfmu/fmi/fmicontext.hpp @@ -4,6 +4,8 @@ #include "fmilib.h" +#include +#include #include #include diff --git a/src/thrift/CMakeLists.txt b/src/thrift/CMakeLists.txt index 88af012..7e1a542 100644 --- a/src/thrift/CMakeLists.txt +++ b/src/thrift/CMakeLists.txt @@ -45,6 +45,7 @@ set(thriftGenerated ) add_library(proxyfmu-service OBJECT ${thriftGenerated}) +target_link_libraries(proxyfmu-service PUBLIC thrift::thrift) set_target_properties(proxyfmu-service PROPERTIES POSITION_INDEPENDENT_CODE ON)