From 10ef51e456e04330d84fcfbd2c755cb633668f40 Mon Sep 17 00:00:00 2001 From: Kristoffer Eide <37700866+eidekrist@users.noreply.github.com> Date: Tue, 5 Mar 2024 13:56:09 +0100 Subject: [PATCH] Conan v2 (#14) Update recipe to Conan 2.x. --------- Co-authored-by: kristoffere Co-authored-by: Lars T. Kyllingstad --- .github/workflows/ci-conan.yml | 64 +++++++++++++++++++------------- conanfile.py | 67 +++++++++++++++++----------------- test_package/CMakeLists.txt | 7 ++-- test_package/conanfile.py | 26 +++++++------ 4 files changed, 89 insertions(+), 75 deletions(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index 7975e65..c84b795 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -3,42 +3,55 @@ name: conan-fmilibrary CI Conan # This workflow is triggered on pushes to the repository. on: [push, workflow_dispatch] -env: - CONAN_LOGIN_USERNAME_OSP: ${{ secrets.osp_artifactory_usr }} - CONAN_PASSWORD_OSP: ${{ secrets.osp_artifactory_pwd }} - CONAN_REVISIONS_ENABLED: 1 - CONAN_NON_INTERACTIVE: True - jobs: conan-on-linux: name: Conan - runs-on: ${{ matrix.os }} - env: - CC: gcc-${{ matrix.compiler_version }} - CXX: g++-${{ matrix.compiler_version }} + runs-on: ubuntu-latest strategy: fail-fast: false matrix: - os: [ubuntu-18.04] build_type: [Debug, Release] - compiler_version: [7, 8, 9] - compiler_libcxx: [libstdc++11] - option_shared: ['True', 'False'] + compiler_version: [9] + option_shared: ['shared=True', 'shared=False'] steps: - - uses: actions/checkout@v2 - - name: Install prerequisites + - uses: actions/checkout@v3 + - name: Generate Dockerfile run: | - sudo apt-get install -y --no-install-recommends g++-8 - sudo pip3 install --upgrade setuptools pip - sudo pip3 install conan - - run: conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force - - run: conan create -s build_type=${{ matrix.build_type }} -s compiler.version=${{ matrix.compiler_version }} -s compiler.libcxx=${{ matrix.compiler_libcxx }} -o fmilibrary:shared=${{ matrix.option_shared }} . _/_ - - run: conan upload --all -c -r osp 'fmilibrary*' + mkdir /tmp/osp-builder-docker + cat <<'EOF' >/tmp/osp-builder-docker/Dockerfile + FROM conanio/gcc${{ matrix.compiler_version }}-ubuntu16.04 + ENV CONAN_LOGIN_USERNAME_OSP=${{ secrets.osp_artifactory_usr }} + ENV CONAN_PASSWORD_OSP=${{ secrets.osp_artifactory_pwd }} + ENV CONAN_REVISIONS_ENABLED=1 + ENV CONAN_NON_INTERACTIVE=1 + COPY entrypoint.sh / + ENTRYPOINT /entrypoint.sh + EOF + - name: Generate entrypoint.sh + run: | + cat <<'EOF' >/tmp/osp-builder-docker/entrypoint.sh + #!/bin/bash -v + set -eu + cp -r /mnt/source build + cd build + conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force + conan create -s build_type=${{ matrix.build_type }} -s compiler.libcxx=libstdc++11 -o "fmilibrary/*:${{ matrix.option_shared }}" . + conan upload --confirm --force --remote=osp 'fmilibrary*' + EOF + chmod 0755 /tmp/osp-builder-docker/entrypoint.sh + - name: Build Docker image + run: docker build -t osp-builder /tmp/osp-builder-docker/ + - name: Build FMI Library + run: docker run --rm --env GITHUB_REF="$GITHUB_REF" -v $(pwd):/mnt/source:ro osp-builder conan-on-windows: name: Conan runs-on: ${{ matrix.os }} env: + CONAN_LOGIN_USERNAME_OSP: ${{ secrets.osp_artifactory_usr }} + CONAN_PASSWORD_OSP: ${{ secrets.osp_artifactory_pwd }} + CONAN_REVISIONS_ENABLED: 1 + CONAN_NON_INTERACTIVE: True CONAN_USER_HOME_SHORT: C:\c CONAN_USE_ALWAYS_SHORT_PATHS: 1 strategy: @@ -46,13 +59,14 @@ jobs: matrix: os: [windows-2019, windows-2022] build_type: [Debug, Release] - option_shared: ['True', 'False'] + option_shared: ['shared=True', 'shared=False'] steps: - uses: actions/checkout@v2 - name: Install prerequisites run: | pip3 install --upgrade setuptools pip pip3 install conan + - run: conan profile detect - run: conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force - - run: conan create -s build_type=${{ matrix.build_type }} -o fmilibrary:shared=${{ matrix.option_shared }} . _/_ - - run: conan upload --all -c -r osp 'fmilibrary*' + - run: conan create -s build_type=${{ matrix.build_type }} -o fmilibrary/*:${{ matrix.option_shared }} . + - run: conan upload --confirm --force --remote=osp 'fmilibrary*' diff --git a/conanfile.py b/conanfile.py index abceabc..599ad77 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,54 +1,53 @@ -from conans import ConanFile, CMake, tools +import os, pathlib + +from conan import ConanFile +from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout +from conan.tools.files import patch, copy +from conan.tools.scm import Git class FMILibraryConan(ConanFile): name = "fmilibrary" version = "2.3" license = "https://github.com/modelon-community/fmi-library/blob/master/LICENSE.md" - url = "https://github.com/kyllingstad/conan-FMILibrary" + url = "https://github.com/open-simulation-platform/conan-fmilibrary" description = "An implementation of the FMI standard which enables FMU import in applications" - scm = { - "type": "git", - "url": "https://github.com/modelon-community/fmi-library.git", - "revision": version, - "subfolder": "src" - } + settings = "os", "compiler", "build_type", "arch" options = {"shared": [True, False]} - default_options = "shared=False" - generators = "cmake" - exports_sources = [ "build-static-c99snprintf.patch" ] + default_options = {"shared": False} + + tool_requires = "cmake/[>=3.15]" + generators = "CMakeDeps" + + exports_sources = "build-static-c99snprintf.patch" def source(self): - tools.patch(base_path="src", patch_file="build-static-c99snprintf.patch") - tools.replace_in_file("src/CMakeLists.txt", "project (FMILibrary)", - '''project (FMILibrary) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup()''') + git = Git(self) + git.clone(url="https://github.com/modelon-community/fmi-library.git", target="src", args=["--branch=2.3"]) + patch(self, base_path="src", patch_file="build-static-c99snprintf.patch") + + def layout(self): + cmake_layout(self) + def generate(self): + tc = CMakeToolchain(self) + tc.cache_variables["FMILIB_BUILD_STATIC_LIB"] = not self.options.shared + tc.cache_variables["FMILIB_BUILD_SHARED_LIB"] = not not self.options.shared + tc.cache_variables["FMILIB_BUILD_TESTS"] = False + tc.cache_variables["FMILIB_GENERATE_DOXYGEN_DOC"] = False + tc.cache_variables["FMILIB_INSTALL_PREFIX"] = pathlib.Path(os.path.join(self.build_folder, "install")).as_posix() + tc.generate() + def build(self): cmake = CMake(self) - cmake.configure( - source_folder="src", - defs={ - "FMILIB_BUILD_STATIC_LIB": "OFF" if self.options.shared else "ON", - "FMILIB_BUILD_SHARED_LIB": "ON" if self.options.shared else "OFF", - "FMILIB_BUILD_TESTS": "OFF", - "FMILIB_INSTALL_PREFIX": self.build_folder + "/install", - }) + cmake.configure(build_script_folder="src") cmake.build() - cmake.install() def package(self): - fmilib_install_dir = self.build_folder + "/install" - self.copy("*.h", dst="include", src=fmilib_install_dir+"/include") - self.copy("*.dll", dst="bin", src=fmilib_install_dir, keep_path=False) - self.copy("*.so", dst="lib", src=fmilib_install_dir, keep_path=False) - self.copy("*.dylib",dst="lib", src=fmilib_install_dir, keep_path=False) - self.copy("*.lib", dst="lib", src=fmilib_install_dir, keep_path=False) - self.copy("*.a", dst="lib", src=fmilib_install_dir, keep_path=False) - self.copy("LICENSE.md", src="src", dst="licenses", keep_path=False) - self.copy("FMILIB_Acknowledgements.txt", src="src", dst="licenses", keep_path=False) + cmake = CMake(self) + cmake.install() + copy(self, "*.dll", os.path.join(self.build_folder, str(self.settings.build_type)), os.path.join(self.package_folder, "bin")) def package_info(self): if self.options.shared: diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt index 2b98ba1..19bb27a 100644 --- a/test_package/CMakeLists.txt +++ b/test_package/CMakeLists.txt @@ -1,8 +1,7 @@ +cmake_minimum_required(VERSION 3.15) project(PackageTest CXX) -cmake_minimum_required(VERSION 2.8.12) -include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) -conan_basic_setup() +find_package(fmilibrary CONFIG REQUIRED) add_executable(test test.cpp) -target_link_libraries(test ${CONAN_LIBS} ${CMAKE_DL_LIBS}) +target_link_libraries(test fmilibrary::fmilibrary ${CMAKE_DL_LIBS}) diff --git a/test_package/conanfile.py b/test_package/conanfile.py index 2ee07bd..27f9105 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -1,25 +1,27 @@ import os -from conans import ConanFile, CMake, tools +from conan import ConanFile +from conan.tools.cmake import CMake, cmake_layout +from conan.tools.files import copy +from conan.tools.build import can_run class FmilibraryTestConan(ConanFile): settings = "os", "compiler", "build_type", "arch" - generators = "cmake" + generators = "CMakeDeps", "CMakeToolchain" + + def requirements(self): + self.requires(self.tested_reference_str) def build(self): cmake = CMake(self) - # Current dir is "test_package/build/" and CMakeLists.txt is - # in "test_package" cmake.configure() cmake.build() - - def imports(self): - self.copy("*.dll", dst="bin", src="bin") - self.copy("*.dylib*", dst="bin", src="lib") - self.copy('*.so*', dst='bin', src='lib') + + def layout(self): + cmake_layout(self) def test(self): - if not tools.cross_building(self.settings): - os.chdir("bin") - self.run(".%stest" % os.sep) + if can_run(self): + cmd = os.path.join(self.cpp.build.bindir, "test") + self.run(cmd, env="conanrun")