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 6 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
16 changes: 9 additions & 7 deletions .github/workflows/ci-conan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-18.04]
os: [ubuntu-latest]
build_type: [Debug, Release]
compiler_version: [7, 8, 9]
compiler_version: [9]
compiler_libcxx: [libstdc++11]
option_shared: ['True', 'False']

Choose a reason for hiding this comment

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

I suggest using containers when building. This configuration (gcc 9 and ubuntu 22) is unfortunate, since distributions using gcc 9 have an older glibc version than ubuntu 22 and pesky glibc issues are likely.
conanio have (almost) ready-made containers for various compiler versions.

container:
      image: conanio/gcc${{ matrix.compiler_version }}-ubuntu18.04
      options: -u 0

You would need to upgrade conan and either use conan config install or conan profile detect to setup.

Choose a reason for hiding this comment

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

Also note that many conan environment variables, e.g. CONAN_NON_INTERACTIVE are ignored with conan 2 and should be configured with core:non_interactive = False in global.conf . I think in this case it does not make a difference.

Copy link
Member

Choose a reason for hiding this comment

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

I agree, and we actually do use containers in our main repo, libcosim. But since this is going to be just a stop-gap solution until you get fmilibrary into conan-center, let's just leave it as-is for now.

steps:
- uses: actions/checkout@v2

Choose a reason for hiding this comment

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

Should be actions/checkout@v3

- name: Install prerequisites
run: |
sudo apt-get install -y --no-install-recommends g++-8
sudo apt-get install -y --no-install-recommends g++-11
sudo pip3 install --upgrade setuptools pip
sudo 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 }} -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*'
- 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 -c -r osp 'fmilibrary*'

conan-on-windows:
name: Conan
Expand All @@ -53,6 +54,7 @@ jobs:
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/*:shared=${{ matrix.option_shared }} .
- run: conan upload -c -r osp 'fmilibrary*'
65 changes: 31 additions & 34 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,51 @@
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}

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"] = False if self.options.shared else True

Choose a reason for hiding this comment

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

I believe these should be variables instead of cache_variables

Copy link
Member

Choose a reason for hiding this comment

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

Are you sure? According to the variables documentation,

This attribute allows defining CMake variables, for multiple configurations (Debug, Release, etc). These variables should be used to define things related to the toolchain and for the majority of cases cache_variables is what you probably want to use.

tc.cache_variables["FMILIB_BUILD_SHARED_LIB"] = True if self.options.shared else False
tc.cache_variables["FMILIB_BUILD_TESTS"] = 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 @@
project(PackageTest CXX)
cmake_minimum_required(VERSION 2.8.12)

Choose a reason for hiding this comment

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

Minimum required version when using CMakeDeps is 3.15

project(PackageTest CXX)

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)
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")