Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conan v2 #14

Merged
merged 17 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 39 additions & 25 deletions .github/workflows/ci-conan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,56 +3,70 @@ 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:
fail-fast: false
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*'
67 changes: 33 additions & 34 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -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()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest adding tc.variables["FMILIB_GENERATE_DOXYGEN_DOC"] = False to always avoid building and installing documentation.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

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:
Expand Down
7 changes: 3 additions & 4 deletions test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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})
26 changes: 14 additions & 12 deletions test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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/<build_id>" 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")
Loading