Skip to content

Commit

Permalink
Revert "Upgrade to Conan 2 (#55)" (#57)
Browse files Browse the repository at this point in the history
This reverts commit 305246c.
  • Loading branch information
kyllingstad authored Apr 18, 2024
1 parent d28722d commit bd4dc57
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 133 deletions.
64 changes: 28 additions & 36 deletions .github/workflows/ci-conan.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
name: CI
name: libcosimc CI Conan

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

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

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v2
- name: Generate Dockerfile
run: |
mkdir /tmp/osp-builder-docker
cat <<'EOF' >/tmp/osp-builder-docker/Dockerfile
FROM conanio/gcc${{ matrix.compiler_version }}-ubuntu16.04
FROM conanio/gcc${{ matrix.compiler_version }}
USER root
RUN apt-get update && apt-get install -y --force-yes doxygen
ENV CONAN_LOGIN_USERNAME_OSP=${{ secrets.osp_artifactory_usr }}
ENV CONAN_PASSWORD_OSP=${{ secrets.osp_artifactory_pwd }}
ENV LIBCOSIMC_RUN_TESTS_ON_CONAN_BUILD=1
ENV CONAN_REVISIONS_ENABLED=1
ENV CONAN_NON_INTERACTIVE=1
ENV CONAN_USE_ALWAYS_SHORT_PATHS=1
COPY entrypoint.sh /
ENTRYPOINT /entrypoint.sh
EOF
Expand All @@ -43,47 +47,42 @@ jobs:
SHORT_REFNAME="${REFNAME:0:40}"
CHANNEL="testing-${SHORT_REFNAME//\//_}"
fi
conan create \
--settings="build_type=${{ matrix.build_type }}" \
--options="libcosimc/*:${{ matrix.option_shared }}" \
--options="libcosim/*:${{ matrix.option_proxyfmu }}" \
--build=missing \
--user=osp \
--channel="${CHANNEL}" \
.
conan upload --confirm --remote=osp 'libcosimc/*'
conan create -s build_type=${{ matrix.build_type }} -s compiler.version=${{ matrix.compiler_version }} -s compiler.libcxx=${{ matrix.compiler_libcxx }} -o libcosim:${{ matrix.option_proxyfmu }} --build missing . osp/${CHANNEL}
conan upload --all -c -r osp 'libcosimc*'
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 libcosimc
run: docker run --rm --env GITHUB_REF="$GITHUB_REF" -v $(pwd):/mnt/source:ro osp-builder
run: |
docker run --rm --env GITHUB_REF="$GITHUB_REF" -v $(pwd):/mnt/source:ro osp-builder
windows:
name: Windows
conan-on-windows:
name: Conan
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-2019]
build_type: [Debug, Release]
option_shared: ['shared=True', 'shared=False']
option_proxyfmu: ['proxyfmu=True', 'proxyfmu=False']
env:
CONAN_LOGIN_USERNAME_OSP: ${{ secrets.osp_artifactory_usr }}
CONAN_PASSWORD_OSP: ${{ secrets.osp_artifactory_pwd }}
LIBCOSIMC_RUN_TESTS_ON_CONAN_BUILD: 1
CONAN_REVISIONS_ENABLED: 1
CONAN_NON_INTERACTIVE: 1
CONAN_USE_ALWAYS_SHORT_PATHS: 1

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

.idea
cmake-build-*/
build/
CMakeUserPresets.json


### Vim
*.swp
*.swp
28 changes: 25 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.15)
cmake_minimum_required(VERSION 3.13)
file(STRINGS "${CMAKE_SOURCE_DIR}/version.txt" projectVersion)
project("libcosimc"
VERSION "${projectVersion}"
Expand All @@ -16,6 +16,7 @@ option(BUILD_SHARED_LIBS "Build shared libraries instead of static libraries" ON
option(LIBCOSIMC_TREAT_WARNINGS_AS_ERRORS "Treat compiler warnings as errors" ON)
option(LIBCOSIMC_BUILD_TESTS "Build test suite" ON)
option(LIBCOSIMC_STANDALONE_INSTALLATION "Whether to build for a standalone installation (Linux only; sets a relative RPATH)" OFF)
option(LIBCOSIMC_USING_CONAN "Whether Conan is used for package management" OFF)


# ==============================================================================
Expand Down Expand Up @@ -61,10 +62,21 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
string(REPLACE "/W3" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
string(REPLACE "/W3" "" CMAKE_C_FLAGS ${CMAKE_C_FLAGS})
endif()
add_compile_options("/wd4251" "/wd4996")
add_compile_options("/wd4996")
if(LIBCOSIMC_TREAT_WARNINGS_AS_ERRORS)
add_compile_options("/WX")
endif()
if(LIBCOSIMC_USING_CONAN)
# C4251: 'identifier' : class 'type' needs to have dll-interface to be
# used by clients of class 'type2'
#
# This could be a problem if a dependent DLL is compiled against a
# different version or variant of the C++ runtime than the one we
# use. An example would be if Boost was built in release mode and
# we are compiling in release mode. However, when we use Conan, this
# should not be a problem, so we disable the warning.
add_compile_options("/wd4251")
endif()
add_definitions("-D_SCL_SECURE_NO_WARNINGS" "-D_CRT_SECURE_NO_WARNINGS")
endif()

Expand Down Expand Up @@ -94,7 +106,17 @@ set(LIBCOSIMC_EXPORT_TARGET "${PROJECT_NAME}-targets")
# Dependencies
# ==============================================================================

if(LIBCOSIMC_USING_CONAN)
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()
endif()

find_package(libcosim REQUIRED)
find_package(Boost REQUIRED COMPONENTS fiber)

# ==============================================================================
# Targets
Expand All @@ -118,7 +140,7 @@ add_library(cosimc "include/cosim.h" "src/cosim.cpp" ${generatedSourcesFull})

target_compile_features(cosimc PRIVATE "cxx_std_17")
target_include_directories(cosimc PUBLIC "$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include>")
target_link_libraries(cosimc PUBLIC libcosim::cosim)
target_link_libraries(cosimc PUBLIC libcosim::cosim Boost::fiber)
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
target_link_libraries(cosimc PUBLIC stdc++)
endif()
Expand Down
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
libcosimc - OSP C co-simulation API
===================================
![libcosimc CI Conan](https://github.com/open-simulation-platform/libcosimc/workflows/libcosimc%20CI%20Conan/badge.svg)

This repository contains the [OSP] C library for co-simulations, which wraps and
exposes a subset of the [libcosim] C++ library's functions.

This repository contains the OSP C library for co-simulations which wraps and exposes a subset of the [`libcosim`]
library's functions.
See [`CONTRIBUTING.md`] for contributor guidelines and [`LICENSE`] for
terms of use.



How to build
------------
Please read the [libcosim build instructions]. The commands you should run
to build libcosimc are exactly the same, except that the option you need to
add to `conan install` to enable [proxy-fmu] support is
`--options="libcosim/*:proxyfmu=True`.

`libcosimc` can be built in the same way as libcosim with the following differences in [step 2]

To include FMU-proxy support use `-o libcosim:'proxyfmu=True'` when installing dependencies in

conan install .. -o libcosim:'proxyfmu=True' --build=missing

When running cmake use `-DLIBCOSIMC_USING_CONAN=TRUE`

[`CONTRIBUTING.md`]: ./CONTRIBUTING.md
[libcosim]: https://github.com/open-simulation-platform/libcosim
[libcosim build instructions]: https://github.com/open-simulation-platform/libcosim#how-to-build
[`LICENSE`]: ./LICENSE
[OSP]: https://opensimulationplatform.com/
[proxy-fmu]: https://github.com/open-simulation-platform/proxy-fmu/
[Step 2]: https://github.com/open-simulation-platform/libcosim#step-2-prepare-build-system
[`libcosim`]: https://github.com/open-simulation-platform/libcosim
88 changes: 24 additions & 64 deletions conanfile.py
Original file line number Diff line number Diff line change
@@ -1,87 +1,47 @@
import os

from conan import ConanFile
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.env import VirtualRunEnv
from conan.tools.files import load
from conans import ConanFile, CMake, tools
from os import path


class LibCosimCConan(ConanFile):
# Basic package info
name = "libcosimc"

def set_version(self):
self.version = load(self, os.path.join(self.recipe_folder, "version.txt")).strip()

# Metadata
license = "MPL-2.0"
author = "osp"
description = "A C wrapper for libcosim, a co-simulation library for C++"

# Binary configuration
package_type = "library"
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": True,
"fPIC": True,
exports = "version.txt"
scm = {
"type": "git",
"url": "auto",
"revision": "auto"
}

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
self.options["*"].shared = self.options.shared

# Dependencies/requirements
tool_requires = (
"cmake/[>=3.15]",
"doxygen/[>=1.8]",
)
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "virtualrunenv"
requires = (
"libcosim/0.10.3@osp/testing-bugfix_transitive-libs-boost",
)

# Exports
exports = "version.txt"
exports_sources = "*"
"libcosim/0.10.2@osp/stable"
)

# Build steps
generators = "CMakeDeps", "CMakeToolchain"
def set_version(self):
self.version = tools.load(path.join(self.recipe_folder, "version.txt")).strip()

def layout(self):
cmake_layout(self)
def imports(self):
binDir = os.path.join("output", str(self.settings.build_type).lower(), "bin")
self.copy("*.dll", dst=binDir, keep_path=False)
self.copy("*.pdb", dst=binDir, keep_path=False)

def build(self):
def configure_cmake(self):
cmake = CMake(self)
cmake.definitions["LIBCOSIMC_USING_CONAN"] = "ON"
cmake.configure()
return cmake

def build(self):
cmake = self.configure_cmake()
cmake.build()
cmake.build(target="doc")
if self._is_tests_enabled():
env = VirtualRunEnv(self).environment()
env.define("CTEST_OUTPUT_ON_FAILURE", "ON")
with env.vars(self).apply():
cmake.test()

# Packaging
def package(self):
cmake = CMake(self)
cmake = self.configure_cmake()
cmake.install()
cmake.build(target="install-doc")

def package_info(self):
self.cpp_info.libs = [ "cosimc" ]
# Ensure that consumers use our CMake package configuration files
# rather than ones generated by Conan.
self.cpp_info.set_property("cmake_find_mode", "none")
self.cpp_info.builddirs.append(".")

# Helper functions
def _is_tests_enabled(self):
return os.getenv("LIBCOSIMC_RUN_TESTS_ON_CONAN_BUILD", "False").lower() in ("true", "1")
Loading

0 comments on commit bd4dc57

Please sign in to comment.