Skip to content

Commit

Permalink
Update to Conan 2
Browse files Browse the repository at this point in the history
  • Loading branch information
kyllingstad committed Oct 31, 2023
1 parent 2156239 commit 88a1cf4
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 99 deletions.
18 changes: 4 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)

Expand All @@ -75,7 +68,6 @@ else ()
BUILD missing
SETTINGS ${settings}
BASIC_SETUP)

endif ()

set(BOOST_COMPONENTS filesystem)
Expand All @@ -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)


# ==============================================================================
Expand Down Expand Up @@ -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}"
)
19 changes: 0 additions & 19 deletions cmake/FindCLI11.cmake

This file was deleted.

39 changes: 0 additions & 39 deletions cmake/FindTHRIFT.cmake

This file was deleted.

6 changes: 2 additions & 4 deletions cmake/project-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)
55 changes: 33 additions & 22 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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")
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
2 changes: 2 additions & 0 deletions src/proxyfmu/fmi/fmicontext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "fmilib.h"

#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <memory>

Expand Down
1 change: 1 addition & 0 deletions src/thrift/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down

0 comments on commit 88a1cf4

Please sign in to comment.