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

Upgrade to Conan 2 #747

Merged
merged 15 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from 13 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
142 changes: 41 additions & 101 deletions .github/workflows/ci-cmake.yml
Original file line number Diff line number Diff line change
@@ -1,116 +1,56 @@
name: libcosim CI CMake
name: CI without Conan

# This workflow is triggered on pushes to the repository.
on: [push]

env:
CONAN_LOGIN_USERNAME_OSP: ${{ secrets.osp_artifactory_usr }}
CONAN_PASSWORD_OSP: ${{ secrets.osp_artifactory_pwd }}
CONAN_REVISIONS_ENABLED: 1
CONAN_NON_INTERACTIVE: 1

jobs:
cmake-on-linux:
name: CMake
runs-on: ${{ matrix.os }}
env:
CC: gcc-${{ matrix.compiler_version }}
CXX: g++-${{ matrix.compiler_version }}
linux:
name: Linux
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04]
build_type: [Debug, Release]
compiler_version: [9]
shared_libs: [ON, OFF]
shared_libs: [SHARED_LIBS=ON, SHARED_LIBS=OFF]
timeout-minutes: 35

steps:
- uses: actions/checkout@v3
- name: Install prerequisites
run: |
sudo apt-get install -y --no-install-recommends \
doxygen \
libboost-all-dev \
libmsgsl-dev \
libyaml-cpp-dev \
libxerces-c-dev \
libzip-dev
wget \
- uses: actions/checkout@v4
- name: Generate Dockerfile
run: |
mkdir /tmp/osp-builder-docker
cat <<EOF >/tmp/osp-builder-docker/Dockerfile
FROM debian:bookworm
RUN apt-get update && apt-get install -y --no-install-recommends \
cmake \
build-essential \
doxygen \
wget \
libboost-all-dev \
libmsgsl-dev \
libyaml-cpp-dev \
libxerces-c-dev \
libzip-dev zipcmp zipmerge ziptool
RUN wget \
--no-check-certificate \
"https://github.com/viproma/debian-fmilib/releases/download/debian%2F2.0.3-1/libfmilib2_2.0.3-1_amd64.deb" \
"https://github.com/viproma/debian-fmilib/releases/download/debian%2F2.0.3-1/libfmilib2-dev_2.0.3-1_amd64.deb"
sudo dpkg -i libfmilib2_2.0.3-1_amd64.deb libfmilib2-dev_2.0.3-1_amd64.deb
- name: CMake - configure
run: |
cmake \
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
-DCMAKE_PREFIX_PATH=fmilibrary \
-DCMAKE_INSTALL_PREFIX=install \
-DBUILD_SHARED_LIBS=${{ matrix.shared_libs }} \
-B build
- name: CMake - build
run: cmake --build build
- name: CMake - build doc
run: cmake --build build --target doc
- name: CMake - test
run: |
RUN dpkg -i libfmilib2_2.0.3-1_amd64.deb libfmilib2-dev_2.0.3-1_amd64.deb
COPY entrypoint.sh /
ENTRYPOINT /entrypoint.sh
EOF
- name: Generate entrypoint.sh
run: |
cat <<'EOF' >/tmp/osp-builder-docker/entrypoint.sh
#!/bin/bash
mkdir build
cd build
ctest
- name: CMake - install
run: |
cmake --build build --target install
cmake --build build --target install-doc
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: libcosim-${{ runner.os }}-${{ matrix.build_type }}-gcc${{ matrix.compiler_version }}
path: install


cmake-on-windows:
name: CMake
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-2019]
build_type: [Debug, Release]
shared: ["True", "False"]
timeout-minutes: 35

steps:
- uses: actions/checkout@v3
- name: Install prerequisites
run: |
pip3 install --upgrade setuptools pip
pip3 install conan==1.59
choco install doxygen.install
conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force
conan install . -s build_type=${{ matrix.build_type }} -o shared=${{ matrix.shared }} -g deploy
- name: CMake - configure
shell: bash
run: |
cmake . \
-A x64 \
-DCMAKE_PREFIX_PATH="ms-gsl;boost;fmilibrary;libzip;xerces-c;yaml-cpp;bzip2;zlib;xz_utils" \
-DCMAKE_INSTALL_PREFIX=install \
-DBUILD_SHARED_LIBS=${{ matrix.shared }} \
-B build
- name: CMake - build
run: cmake --build build --config ${{ matrix.build_type }}
- name: CMake - build doc
run: cmake --build build --config ${{ matrix.build_type }} --target doc
- name: CMake - test
run: |
.\activate_run.ps1
cd build
ctest -C ${{ matrix.build_type }}
- name: CMake - install
run: |
cmake --build build --config ${{ matrix.build_type }} --target install
cmake --build build --config ${{ matrix.build_type }} --target install-doc
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: libcosim-${{ runner.os }}-${{ matrix.build_type }}
path: install
cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DBUILD_${{ matrix.shared_libs }} /mnt/source
cmake --build .
ctest --output-on-failure
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 cosim
run: docker run --rm -v $(pwd):/mnt/source:ro osp-builder
57 changes: 32 additions & 25 deletions .github/workflows/ci-conan.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
name: libcosim CI Conan
name: CI with Conan

# This workflow is triggered on pushes to the repository.
on: [push, workflow_dispatch]

jobs:
conan-on-linux:
name: Conan
linux:
name: Linux
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
build_type: [Debug, Release]
compiler_version: [9]
compiler_libcxx: [libstdc++11]
option_proxyfmu: ['proxyfmu=True', 'proxyfmu=False']
option_shared: ['shared=True', 'shared=False']
timeout-minutes: 35

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Generate Dockerfile
run: |
mkdir /tmp/osp-builder-docker
cat <<'EOF' >/tmp/osp-builder-docker/Dockerfile
FROM conanio/gcc${{ matrix.compiler_version }}
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
ENV CONAN_USE_ALWAYS_SHORT_PATHS=1
ENV LIBCOSIM_RUN_TESTS_ON_CONAN_BUILD=1
COPY entrypoint.sh /
ENTRYPOINT /entrypoint.sh
Expand All @@ -48,28 +44,30 @@ jobs:
SHORT_REFNAME="${REFNAME:0:40}"
CHANNEL="testing-${SHORT_REFNAME//\//_}"
fi
conan create -s build_type=${{ matrix.build_type }} -s compiler.version=${{ matrix.compiler_version }} -s compiler.libcxx=${{ matrix.compiler_libcxx }} -o ${{ matrix.option_proxyfmu }} -o ${{ matrix.option_shared }} -b missing . osp/${CHANNEL}
conan upload --all -c -r osp '*'
conan create \
--settings="build_type=${{ matrix.build_type }}" \
--options="${{ matrix.option_proxyfmu }}" \
--options="${{ matrix.option_shared }}" \
--build=missing \
--user=osp \
--channel="${CHANNEL}" \
.
conan upload --confirm --remote=osp '*'
EOF
chmod 0755 /tmp/osp-builder-docker/entrypoint.sh
- name: Build Docker image
run: |
docker build -t osp-builder /tmp/osp-builder-docker/
run: docker build -t osp-builder /tmp/osp-builder-docker/
- name: Build cosim
run: |
docker run --rm --env GITHUB_REF="$GITHUB_REF" -v $(pwd):/mnt/source:ro osp-builder


conan-on-windows:
name: Conan
windows:
name: Windows
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: 1
CONAN_USE_ALWAYS_SHORT_PATHS: 1
CONAN_USER_HOME_SHORT: C:\c
LIBCOSIM_RUN_TESTS_ON_CONAN_BUILD: 1
strategy:
fail-fast: false
Expand All @@ -78,16 +76,18 @@ jobs:
build_type: [Debug, Release]
option_proxyfmu: ['proxyfmu=True', 'proxyfmu=False']
option_shared: ['shared=True', 'shared=False']
timeout-minutes: 35
timeout-minutes: 120

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Install prerequisites
run: |
pip3 install --upgrade setuptools pip
pip3 install conan==1.59
pip3 install conan
- name: Configure Conan
run: conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force
run: |
conan profile detect
conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force
- name: Conan create
shell: bash
run: |
Expand All @@ -99,6 +99,13 @@ jobs:
SHORT_REFNAME="${REFNAME:0:40}"
CHANNEL="testing-${SHORT_REFNAME//\//_}"
fi
conan create -s build_type=${{ matrix.build_type }} -o ${{ matrix.option_proxyfmu }} -o ${{ matrix.option_shared }} -b missing . osp/${CHANNEL}
conan create \
--settings="build_type=${{ matrix.build_type }}" \
--options="${{ matrix.option_proxyfmu }}" \
--options="${{ matrix.option_shared }}" \
--build=missing \
--user=osp \
--channel="${CHANNEL}" \
.
- name: Conan upload
run: conan upload --all -c -r osp '*'
run: conan upload --confirm --remote=osp '*'
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ cmake-build-*/

# Visual Studio Code
.vscode/

CMakeUserPresets.json
55 changes: 6 additions & 49 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.9)
cmake_minimum_required(VERSION 3.19)
file(STRINGS "${CMAKE_SOURCE_DIR}/version.txt" projectVersion)
project("libcosim" VERSION ${projectVersion})
message("Current libcosim version: ${CMAKE_PROJECT_VERSION}\n")
Expand All @@ -13,8 +13,6 @@ option(LIBCOSIM_BUILD_TESTS "Build test suite" ON)
option(LIBCOSIM_BUILD_APIDOC "Build API documentation (requires Doxygen)" ON)
option(LIBCOSIM_BUILD_PRIVATE_APIDOC "Build private API documentation (only used if LIBCOSIM_BUILD_APIDOC=ON)" OFF)
option(LIBCOSIM_STANDALONE_INSTALLATION "Whether to build for a standalone installation (Linux only; sets a relative RPATH)" OFF)
option(LIBCOSIM_USING_CONAN "Whether Conan is used for package management" OFF)
option(LIBCOSIM_USING_CONAN_AUTO_CONFIG "Whether Conan should be configured automatically by CMake" OFF)
option(LIBCOSIM_WITH_PROXYFMU "Whether or not to build with proxy-fmu integration" OFF)
option(LIBCOSIM_NO_FMI_LOGGING "Disable FMI logging during simulation" OFF)

Expand Down Expand Up @@ -98,44 +96,6 @@ set(LIBCOSIM_EXPORT_TARGET "${PROJECT_NAME}-targets")
# Dependencies
# ==============================================================================

if(LIBCOSIM_USING_CONAN)
if(NOT LIBCOSIM_USING_CONAN_AUTO_CONFIG OR CONAN_EXPORTED)
# Opting for manual invocation of conan install prior to loading CMake
# or conan create has been invoked, setting CONAN_EXPORTED.
if(EXISTS ${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(NO_OUTPUT_DIRS)
else()
message(FATAL_ERROR "The file conanbuildinfo.cmake doesn't exist, you have to run conan install first")
endif()
else()
# Auto config specified and conan create is not running.
# We'll let CMake run the conan commands for us.

# This is where the magic happens.
# The file has been modified to search for the conan executable on linux systems.
include(cmake/conan.cmake)
conan_cmake_autodetect(settings)

set(proxyfmu_option False)
if(LIBCOSIM_WITH_PROXYFMU)
set(proxyfmu_option True)
endif()

# Force add osp remote
conan_add_remote(NAME osp URL https://osp.jfrog.io/artifactory/api/conan/conan-local)

# Run conan install with auto-detected settings and -b missing flag
# and -o proxyfmu=True if LIBCOSIM_WITH_PROXYFMU=ON
conan_cmake_run(
CONANFILE conanfile.py
OPTIONS proxyfmu=${proxyfmu_option}
BUILD missing
SETTINGS ${settings}
BASIC_SETUP NO_OUTPUT_DIRS)
endif()
endif()

set(Boost_components date_time log)
if (LIBCOSIM_BUILD_TESTS)
list(APPEND Boost_components timer unit_test_framework)
Expand All @@ -148,11 +108,11 @@ find_package(Boost REQUIRED COMPONENTS ${Boost_components})
if(BUILD_SHARED_LIBS AND NOT DEFINED FMILibrary_USE_SHARED_LIB)
set(FMILibrary_USE_SHARED_LIB TRUE)
endif()
find_package(FMILibrary REQUIRED)
find_package(LIBZIP REQUIRED)
find_package(MS_GSL REQUIRED)
find_package(YAML_CPP REQUIRED)
find_package(XercesC REQUIRED)
find_package(FMILibrary MODULE REQUIRED)
find_package(libzip REQUIRED)
find_package(Microsoft.GSL REQUIRED)
find_package(yaml-cpp REQUIRED)
find_package(XercesC MODULE REQUIRED)
if(LIBCOSIM_WITH_PROXYFMU)
find_package(PROXYFMU CONFIG REQUIRED)
endif()
Expand Down Expand Up @@ -244,9 +204,6 @@ install(FILES "${versionFile}" DESTINATION "${LIBCOSIM_CMAKE_INSTALL_DIR}")
# Install custom find modules
install(FILES
"${CMAKE_SOURCE_DIR}/cmake/FindFMILibrary.cmake"
"${CMAKE_SOURCE_DIR}/cmake/FindLIBZIP.cmake"
"${CMAKE_SOURCE_DIR}/cmake/FindMS_GSL.cmake"
"${CMAKE_SOURCE_DIR}/cmake/FindYAML_CPP.cmake"
DESTINATION
"${LIBCOSIM_CMAKE_INSTALL_DIR}"
)
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ in the section below or you can use conan. As libcosim is made available as a
conan package on https://osp.jfrog.io, you can include it in your application
following these steps:

* Install [Conan] version 1.x
* Install [Conan] version 2.x
* Add the OSP Conan repository as a remote:

conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local
Expand All @@ -35,10 +35,10 @@ How to build

### Required tools

* Compilers: [Visual Studio] >= 16.0/2019 (Windows), GCC >= 7 (Linux)
* Build tool: [CMake]
* Compilers: [Visual Studio] >= 16.0/2019 (Windows), GCC >= 9 (Linux)
* Build tool: [CMake] >= 3.19
* API documentation generator (optional): [Doxygen]
* Package manager (optional): [Conan] 1.x
* Package manager (optional): [Conan] 2.x

Throughout this guide, we will use Conan to manage dependencies. However, it
should be possible to use other package managers as well, such as [vcpkg], and
Expand Down
Loading