From 8cccdd14b63234373d14c0b1e23f7a5b54da9985 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 23 Nov 2023 11:09:34 +0100 Subject: [PATCH 01/29] Upgrade to Conan 2 --- .github/workflows/ci-conan.yml | 66 +++++++++++------------------- .gitignore | 1 + CMakeLists.txt | 13 ++---- conanfile.py | 74 ++++++++++++++++++++++++++++++++++ conanfile.txt | 54 ------------------------- 5 files changed, 102 insertions(+), 106 deletions(-) create mode 100644 conanfile.py delete mode 100644 conanfile.txt diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index e53c0e4..e8c0d29 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -1,11 +1,11 @@ -name: cosim CI Conan +name: Build cosim-cli # 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 @@ -16,59 +16,42 @@ jobs: option_proxyfmu: ['proxyfmu=True', 'proxyfmu=False'] steps: - - uses: actions/checkout@v2 + - 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 }} - USER root - RUN apt-get update && apt-get install -y --force-yes patchelf - 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 + FROM conanio/gcc${{ matrix.compiler_version }}-ubuntu16.04 COPY entrypoint.sh / ENTRYPOINT /entrypoint.sh EOF - name: Generate entrypoint.sh run: | - mkdir build - chmod 777 build cat <<'EOF' >/tmp/osp-builder-docker/entrypoint.sh #!/bin/bash -v set -eu - cd /mnt/source/build + cd /mnt/source conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force - conan install -s build_type=${{ matrix.build_type }} -s compiler.version=${{ matrix.compiler_version }} -s compiler.libcxx=${{ matrix.compiler_libcxx }} -o libcosim:${{ matrix.option_proxyfmu }} -b missing .. - for f in dist/lib/*; do patchelf --set-rpath \$ORIGIN $f; done - cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} .. - cmake --build . - cmake --build . --target install + conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -s compiler.libcxx=${{ matrix.compiler_libcxx }} -o libcosim:${{ matrix.option_proxyfmu }} --build=missing + cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + cmake --build build + cmake --build build --target install EOF chmod 0777 /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 osp-builder - name: Upload artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: cosim-${{ runner.os }}-${{ matrix.build_type }}-${{ matrix.compiler_version }}-${{ matrix.option_proxyfmu }} path: build/dist - 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 strategy: fail-fast: false matrix: @@ -77,24 +60,23 @@ jobs: option_proxyfmu: ['proxyfmu=True', 'proxyfmu=False'] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Install prerequisites run: | pip3 install --upgrade setuptools pip - pip3 install conan --force-reinstall -v "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: Build - shell: bash run: | - mkdir build - cd build - conan install -s build_type=${{ matrix.build_type }} -o libcosim:${{ matrix.option_proxyfmu }} -b missing ../ - cmake -A x64 ../ - cmake --build . --config ${{ matrix.build_type }} - cmake --build . --config ${{ matrix.build_type }} --target install + conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -o libcosim:${{ matrix.option_proxyfmu }} --build=missing + cmake -A x64 -B build -S . "-DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake" + cmake --build build --config ${{ matrix.build_type }} + cmake --build build --config ${{ matrix.build_type }} --target install - name: Upload artifact - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: cosim-${{ runner.os }}-${{ matrix.build_type }}-${{ matrix.option_proxyfmu }} path: build/dist diff --git a/.gitignore b/.gitignore index b59ca6f..2311650 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.swp build/ +CMakeUserPresets.json # JetBrains CLion: .idea/ diff --git a/CMakeLists.txt b/CMakeLists.txt index ec0fb64..ab2bb77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.9) +cmake_minimum_required(VERSION 3.15) project("cosim" VERSION "0.8.0") set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/dist") @@ -33,15 +33,8 @@ endif() # Dependencies # ============================================================================== -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() - find_package(libcosim REQUIRED) -find_package(Boost REQUIRED COMPONENTS program_options) +find_package(Boost REQUIRED COMPONENTS log program_options) # ============================================================================== # Targets @@ -77,7 +70,7 @@ add_executable(cosim "src/version_option.cpp" ) target_include_directories(cosim PRIVATE "${generatedFilesDir}") -target_link_libraries(cosim PRIVATE libcosim::cosim Boost::program_options) +target_link_libraries(cosim PRIVATE libcosim::cosim Boost::log Boost::program_options) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # This makes the linker set RPATH rather than RUNPATH for the resulting diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 0000000..1d2f89e --- /dev/null +++ b/conanfile.py @@ -0,0 +1,74 @@ +import os + +from conan import ConanFile +from conan.tools.cmake import CMakeDeps, CMakeToolchain +from conan.tools.env import VirtualBuildEnv +from conan.tools.files import copy + +class CosimCLIConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + default_options = { "*:shared": True } + + def requirements(self): + self.tool_requires("cmake/[>=3.19]") + if self.settings.os == "Linux": + self.tool_requires("patchelf/[>=0.18]") + self.requires("libcosim/0.11.0@osp/testing-feature_conan-2") + self.requires("boost/[>=1.71]") + + def generate(self): + bindir = os.path.join(self.build_folder, "dist", "bin") + dldir = (bindir if self.settings.os == "Windows" else + os.path.join(self.build_folder, "dist", "lib")) + self._import_dynamic_libs("boost", dldir, [ + "boost_atomic*", + "boost_chrono*", + "boost_container*", + "boost_context*", + "boost_date_time*", + "boost_filesystem*", + "boost_locale*", + "boost_log*", + "boost_log_setup*", + "boost_program_options*", + "boost_random*", + "boost_regex*", + "boost_serialization*", + "boost_system*", + "boost_thread*", + ]) + self._import_dynamic_libs("libcosim", dldir) + self._import_dynamic_libs("openssl", dldir) + self._import_dynamic_libs("fmilibrary", dldir) + self._import_dynamic_libs("xerces-c", dldir) + self._import_dynamic_libs("yaml-cpp", dldir) + self._import_dynamic_libs("libzip", dldir) + if self.dependencies["libcosim"].options.proxyfmu: + self._import_dynamic_libs("proxyfmu", dldir) + self._import_dynamic_libs("thrift", dldir, ["thrift", "thriftd"]) + self._import_executables("proxyfmu", bindir) + CMakeToolchain(self).generate() + CMakeDeps(self).generate() + + def _import_executables(self, dependency_name, target_dir, exenames=["*"]): + dep = self.dependencies[dependency_name] + for bindir in dep.cpp_info.bindirs: + for exename in exenames: + pattern = exename+".exe" if self.settings.os == "Windows" else exename + files = copy(self, pattern, bindir, target_dir, keep_path=False) + self._update_rpath(files, "$ORIGIN/../lib") + + def _import_dynamic_libs(self, dependency_name, target_dir, libnames=["*"]): + dep = self.dependencies[dependency_name] + if dep.options.get_safe("shared", False): + depdirs = dep.cpp_info.bindirs if self.settings.os == "Windows" else dep.cpp_info.libdirs + for depdir in depdirs: + for libname in libnames: + pattern = libname+".dll" if self.settings.os == "Windows" else "lib"+libname+".so*" + files = copy(self, pattern, depdir, target_dir, keep_path=False) + self._update_rpath(files, "$ORIGIN") + + def _update_rpath(self, files, new_rpath): + if files and self.settings.os == "Linux": + with VirtualBuildEnv(self).environment().vars(self).apply(): + self.run("patchelf --set-rpath '" + new_rpath + "' '" + ("' '".join(files)) + "'") diff --git a/conanfile.txt b/conanfile.txt deleted file mode 100644 index ee2d2fd..0000000 --- a/conanfile.txt +++ /dev/null @@ -1,54 +0,0 @@ -[requires] -libcosim/0.10.2@osp/stable - -[generators] -cmake -virtualrunenv - -[imports] -bin, boost_atomic*.dll -> ./dist/bin -bin, boost_chrono*.dll -> ./dist/bin -bin, boost_context*.dll -> ./dist/bin -bin, boost_date_time*.dll -> ./dist/bin -bin, boost_filesystem*.dll -> ./dist/bin -bin, boost_log*.dll -> ./dist/bin -bin, boost_log_setup*.dll -> ./dist/bin -bin, boost_program_options*.dll -> ./dist/bin -bin, boost_regex*.dll -> ./dist/bin -bin, boost_system*.dll -> ./dist/bin -bin, boost_thread*.dll -> ./dist/bin -bin, cosim.dll -> ./dist/bin -bin, fmilib_shared.dll -> ./dist/bin -bin, xerces-c*.dll -> ./dist/bin -bin, yaml-cpp*.dll -> ./dist/bin -bin, zip.dll -> ./dist/bin -bin, proxyfmu* -> ./dist/bin -bin, fmilibwrapper*.dll -> ./dist/bin - -lib, libboost_atomic.so.* -> ./dist/lib -lib, libboost_chrono.so.* -> ./dist/lib -lib, libboost_context.so.* -> ./dist/lib -lib, libboost_date_time.so.* -> ./dist/lib -lib, libboost_filesystem.so.* -> ./dist/lib -lib, libboost_log.so.* -> ./dist/lib -lib, libboost_log_setup.so.* -> ./dist/lib -lib, libboost_program_options.so.* -> ./dist/lib -lib, libboost_regex.so.* -> ./dist/lib -lib, libboost_system.so.* -> ./dist/lib -lib, libboost_thread.so.* -> ./dist/lib -lib, libcosim.so -> ./dist/lib -lib, libfmilib_shared.so -> ./dist/lib -lib, libxerces-c*.so -> ./dist/lib -lib, libyaml-cpp*.so.* -> ./dist/lib -lib, libzip.so.* -> ./dist/lib -lib, libfmilibwrapper*.so -> ./dist/lib -lib, libproxyfmu-client*.so -> ./dist/lib - -., license* -> ./dist/doc/licenses @ folder=True, ignore_case=True, keep_path=False -., */license* -> ./dist/doc/licenses @ folder=True, ignore_case=True, keep_path=False -., copying* -> ./dist/doc/licenses @ folder=True, ignore_case=True, keep_path=False -., */copying* -> ./dist/doc/licenses @ folder=True, ignore_case=True, keep_path=False -., notice* -> ./dist/doc/licenses @ folder=True, ignore_case=True, keep_path=False -., */notice* -> ./dist/doc/licenses @ folder=True, ignore_case=True, keep_path=False -., authors* -> ./dist/doc/licenses @ folder=True, ignore_case=True, keep_path=False -., */authors* -> ./dist/doc/licenses @ folder=True, ignore_case=True, keep_path=False From efe6f155dc57fc4ff253a7cd4051974eaf7b8c28 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 23 Nov 2023 11:15:57 +0100 Subject: [PATCH 02/29] Fix options specification in CI --- .github/workflows/ci-conan.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index e8c0d29..51311b2 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -32,7 +32,7 @@ jobs: set -eu cd /mnt/source conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force - conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -s compiler.libcxx=${{ matrix.compiler_libcxx }} -o libcosim:${{ matrix.option_proxyfmu }} --build=missing + conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -s compiler.libcxx=${{ matrix.compiler_libcxx }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} cmake --build build cmake --build build --target install @@ -71,7 +71,7 @@ jobs: conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force - name: Build run: | - conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -o libcosim:${{ matrix.option_proxyfmu }} --build=missing + conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing cmake -A x64 -B build -S . "-DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake" cmake --build build --config ${{ matrix.build_type }} cmake --build build --config ${{ matrix.build_type }} --target install From a41825ba73950fdf01a77bc242249a8573afa3d8 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 23 Nov 2023 12:36:14 +0100 Subject: [PATCH 03/29] Iterate over dependencies, don't specify manually --- conanfile.py | 56 +++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/conanfile.py b/conanfile.py index 1d2f89e..7553809 100644 --- a/conanfile.py +++ b/conanfile.py @@ -17,10 +17,14 @@ def requirements(self): self.requires("boost/[>=1.71]") def generate(self): + # Import shared libraries and executables from dependency packages + # to the 'dist/' folder. bindir = os.path.join(self.build_folder, "dist", "bin") dldir = (bindir if self.settings.os == "Windows" else os.path.join(self.build_folder, "dist", "lib")) - self._import_dynamic_libs("boost", dldir, [ + dependency_libs = { + # For some dependencies, we only want a subset of the libraries + "boost" : [ "boost_atomic*", "boost_chrono*", "boost_container*", @@ -35,39 +39,37 @@ def generate(self): "boost_regex*", "boost_serialization*", "boost_system*", - "boost_thread*", - ]) - self._import_dynamic_libs("libcosim", dldir) - self._import_dynamic_libs("openssl", dldir) - self._import_dynamic_libs("fmilibrary", dldir) - self._import_dynamic_libs("xerces-c", dldir) - self._import_dynamic_libs("yaml-cpp", dldir) - self._import_dynamic_libs("libzip", dldir) + "boost_thread*"], + "thrift": ["thrift", "thriftd"], + } + for req, dep in self.dependencies.items(): + self._import_dynamic_libs(dep, dldir, dependency_libs.get(req.ref.name, ["*"])) if self.dependencies["libcosim"].options.proxyfmu: - self._import_dynamic_libs("proxyfmu", dldir) - self._import_dynamic_libs("thrift", dldir, ["thrift", "thriftd"]) - self._import_executables("proxyfmu", bindir) + self._import_executables(self.dependencies["proxyfmu"], bindir, ["*"]) + + # Generate build system CMakeToolchain(self).generate() CMakeDeps(self).generate() - def _import_executables(self, dependency_name, target_dir, exenames=["*"]): - dep = self.dependencies[dependency_name] - for bindir in dep.cpp_info.bindirs: - for exename in exenames: - pattern = exename+".exe" if self.settings.os == "Windows" else exename - files = copy(self, pattern, bindir, target_dir, keep_path=False) - self._update_rpath(files, "$ORIGIN/../lib") - - def _import_dynamic_libs(self, dependency_name, target_dir, libnames=["*"]): - dep = self.dependencies[dependency_name] - if dep.options.get_safe("shared", False): - depdirs = dep.cpp_info.bindirs if self.settings.os == "Windows" else dep.cpp_info.libdirs + def _import_dynamic_libs(self, dependency, target_dir, patterns): + if dependency.options.get_safe("shared", False): + if self.settings.os == "Windows": + depdirs = dependency.cpp_info.bindirs + else: + depdirs = dependency.cpp_info.libdirs for depdir in depdirs: - for libname in libnames: - pattern = libname+".dll" if self.settings.os == "Windows" else "lib"+libname+".so*" - files = copy(self, pattern, depdir, target_dir, keep_path=False) + for pattern in patterns: + patternx = pattern+".dll" if self.settings.os == "Windows" else "lib"+pattern+".so*" + files = copy(self, patternx, depdir, target_dir, keep_path=False) self._update_rpath(files, "$ORIGIN") + def _import_executables(self, dependency, target_dir, patterns=["*"]): + for bindir in dependency.cpp_info.bindirs: + for pattern in patterns: + patternx = pattern+".exe" if self.settings.os == "Windows" else pattern + files = copy(self, patternx, bindir, target_dir, keep_path=False) + self._update_rpath(files, "$ORIGIN/../lib") + def _update_rpath(self, files, new_rpath): if files and self.settings.os == "Linux": with VirtualBuildEnv(self).environment().vars(self).apply(): From 0e785158a2ae0f7db9ba7cb20e12107299660f1e Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 23 Nov 2023 12:55:36 +0100 Subject: [PATCH 04/29] Specify compiler.cppstd=17, required by patchelf --- .github/workflows/ci-conan.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index 51311b2..8fb17f2 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -32,7 +32,7 @@ jobs: set -eu cd /mnt/source conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force - conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -s compiler.libcxx=${{ matrix.compiler_libcxx }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing + conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -s compiler.libcxx=${{ matrix.compiler_libcxx }} -s compiler.cppstd=17 -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} cmake --build build cmake --build build --target install @@ -41,8 +41,7 @@ jobs: - name: Build Docker image 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 osp-builder + run: docker run --rm --env GITHUB_REF="$GITHUB_REF" -v $(pwd):/mnt/source osp-builder - name: Upload artifact uses: actions/upload-artifact@v3 with: From 97458d9f4608fb4a517564f1c7d7c64bf334f949 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 23 Nov 2023 13:04:28 +0100 Subject: [PATCH 05/29] More CI build settings adjustments --- .github/workflows/ci-conan.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index 8fb17f2..88b9506 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -12,7 +12,6 @@ jobs: matrix: build_type: [Debug, Release] compiler_version: [9] - compiler_libcxx: [libstdc++11] option_proxyfmu: ['proxyfmu=True', 'proxyfmu=False'] steps: @@ -32,7 +31,7 @@ jobs: set -eu cd /mnt/source conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force - conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -s compiler.libcxx=${{ matrix.compiler_libcxx }} -s compiler.cppstd=17 -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing + conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -s:a compiler.cppstd=17 -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} cmake --build build cmake --build build --target install From 4bef9d832064a41c9b06082f32cf198b5b3e9bb6 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 23 Nov 2023 13:09:15 +0100 Subject: [PATCH 06/29] Apparently the Conan -s:a switch doesn't work yet --- .github/workflows/ci-conan.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index 88b9506..8334d3e 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -31,7 +31,7 @@ jobs: set -eu cd /mnt/source conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force - conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -s:a compiler.cppstd=17 -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing + conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -s:b compiler.cppstd=17 -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} cmake --build build cmake --build build --target install From 306f9d53131d62b28478016e901fd9db19ac3c75 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 23 Nov 2023 13:23:35 +0100 Subject: [PATCH 07/29] Use a CI container in the right way --- .github/workflows/ci-conan.yml | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index 8334d3e..ad05b9d 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -1,4 +1,4 @@ -name: Build cosim-cli +name: CI # This workflow is triggered on pushes to the repository. on: [push, workflow_dispatch] @@ -13,34 +13,20 @@ jobs: build_type: [Debug, Release] compiler_version: [9] option_proxyfmu: ['proxyfmu=True', 'proxyfmu=False'] - + container: + image: conanio/gcc${{ matrix.compiler_version }}-ubuntu16.04 steps: - 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 }}-ubuntu16.04 - COPY entrypoint.sh / - ENTRYPOINT /entrypoint.sh - EOF - - name: Generate entrypoint.sh + - name: Configure Conan + run: conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force + - name: Install dependencies + run: conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -s:b compiler.cppstd=17 -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing + - name: Generate build system + run: cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + - name: Build run: | - cat <<'EOF' >/tmp/osp-builder-docker/entrypoint.sh - #!/bin/bash -v - set -eu - cd /mnt/source - conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force - conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -s:b compiler.cppstd=17 -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing - cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} cmake --build build cmake --build build --target install - EOF - chmod 0777 /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 --env GITHUB_REF="$GITHUB_REF" -v $(pwd):/mnt/source osp-builder - name: Upload artifact uses: actions/upload-artifact@v3 with: From 8b560bd4b6cce60f01fc659c738a01298168b67c Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 23 Nov 2023 13:27:22 +0100 Subject: [PATCH 08/29] Workaround for Docker/GLIBC interaction issue --- .github/workflows/ci-conan.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index ad05b9d..d2a70f6 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -15,6 +15,7 @@ jobs: option_proxyfmu: ['proxyfmu=True', 'proxyfmu=False'] container: image: conanio/gcc${{ matrix.compiler_version }}-ubuntu16.04 + options: --privileged steps: - uses: actions/checkout@v4 - name: Configure Conan From c966a62cb483f39e6ba89c3b49328e8e954fc851 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 23 Nov 2023 13:35:02 +0100 Subject: [PATCH 09/29] Try running container on older GitHub runner --- .github/workflows/ci-conan.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index d2a70f6..abc63d7 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -6,7 +6,7 @@ on: [push, workflow_dispatch] jobs: linux: name: Linux - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 strategy: fail-fast: false matrix: From 2f0551cd96a473c54836d7a6de87011886594a7b Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 23 Nov 2023 13:40:25 +0100 Subject: [PATCH 10/29] Try older version of checkout action ...to fix glibc incompatibility issues between conanio container and Node.js runtime. --- .github/workflows/ci-conan.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index abc63d7..6f97962 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -17,7 +17,7 @@ jobs: image: conanio/gcc${{ matrix.compiler_version }}-ubuntu16.04 options: --privileged steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@v3 - name: Configure Conan run: conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force - name: Install dependencies From 7bdebfd783a75a86e0731c69a975cc9eb01abac2 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 23 Nov 2023 13:54:14 +0100 Subject: [PATCH 11/29] Revert to old container generation, build outside src --- .github/workflows/ci-conan.yml | 37 +++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index 6f97962..2c8cddf 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -6,28 +6,41 @@ on: [push, workflow_dispatch] jobs: linux: name: Linux - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: fail-fast: false matrix: build_type: [Debug, Release] compiler_version: [9] option_proxyfmu: ['proxyfmu=True', 'proxyfmu=False'] - container: - image: conanio/gcc${{ matrix.compiler_version }}-ubuntu16.04 - options: --privileged + steps: - - uses: actions/checkout@v3 - - name: Configure Conan - run: conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force - - name: Install dependencies - run: conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -s:b compiler.cppstd=17 -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing - - name: Generate build system - run: cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} - - name: Build + - 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 }}-ubuntu16.04 + 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 + conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force + conan install /mnt/source --output-folder=build -s build_type=${{ matrix.build_type }} -s:b compiler.cppstd=17 -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing + cmake -B build -S /mnt/source -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} cmake --build build cmake --build build --target install + EOF + chmod 0777 /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 --env GITHUB_REF="$GITHUB_REF" -v $(pwd):/mnt/source osp-builder - name: Upload artifact uses: actions/upload-artifact@v3 with: From 6c4ef58762ba7c77ed30b8b0d3904fcf985af832 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 23 Nov 2023 14:48:35 +0100 Subject: [PATCH 12/29] Try yet another tack to get patchelf to work --- .github/workflows/ci-conan.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index 2c8cddf..15c5e98 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -11,7 +11,7 @@ jobs: fail-fast: false matrix: build_type: [Debug, Release] - compiler_version: [9] + compiler_version: [11] option_proxyfmu: ['proxyfmu=True', 'proxyfmu=False'] steps: @@ -30,7 +30,7 @@ jobs: #!/bin/bash -v set -eu conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force - conan install /mnt/source --output-folder=build -s build_type=${{ matrix.build_type }} -s:b compiler.cppstd=17 -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing + conan install /mnt/source --output-folder=build -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing cmake -B build -S /mnt/source -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} cmake --build build cmake --build build --target install From e430d3e530d1ad9c3f60dc81b80d7bed71d773c4 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 23 Nov 2023 14:56:03 +0100 Subject: [PATCH 13/29] Suppress generation of CMakeUserPresets.json --- conanfile.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/conanfile.py b/conanfile.py index 7553809..5342b3b 100644 --- a/conanfile.py +++ b/conanfile.py @@ -48,7 +48,9 @@ def generate(self): self._import_executables(self.dependencies["proxyfmu"], bindir, ["*"]) # Generate build system - CMakeToolchain(self).generate() + tc = CMakeToolchain(self) + tc.user_presets_path = False # Don't touch source directory. + tc.generate() CMakeDeps(self).generate() def _import_dynamic_libs(self, dependency, target_dir, patterns): From 9570a9c6ba1e113976a6a2a5c027e7e7399fd5ca Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 23 Nov 2023 15:01:34 +0100 Subject: [PATCH 14/29] CMAKE_TOOLCHAIN_FILE is relative to build dir --- .github/workflows/ci-conan.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index 15c5e98..e95e1cf 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -31,7 +31,7 @@ jobs: set -eu conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force conan install /mnt/source --output-folder=build -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing - cmake -B build -S /mnt/source -DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + cmake -B build -S /mnt/source -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} cmake --build build cmake --build build --target install EOF @@ -70,7 +70,7 @@ jobs: - name: Build run: | conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing - cmake -A x64 -B build -S . "-DCMAKE_TOOLCHAIN_FILE=build/conan_toolchain.cmake" + cmake -A x64 -B build -S . "-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake" cmake --build build --config ${{ matrix.build_type }} cmake --build build --config ${{ matrix.build_type }} --target install - name: Upload artifact From 2e1eeb28e60522f3a424f123d92030e7cf1a1949 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 23 Nov 2023 15:19:53 +0100 Subject: [PATCH 15/29] Allow build artifacts to be extracted from container --- .github/workflows/ci-conan.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index e95e1cf..ed55633 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -30,8 +30,9 @@ jobs: #!/bin/bash -v set -eu conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force - conan install /mnt/source --output-folder=build -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing - cmake -B build -S /mnt/source -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + cd /mnt/source + conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing + cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} cmake --build build cmake --build build --target install EOF @@ -40,6 +41,7 @@ jobs: run: docker build -t osp-builder /tmp/osp-builder-docker/ - name: Build cosim run: | + mkdir -m 0777 -p build/dist docker run --rm --env GITHUB_REF="$GITHUB_REF" -v $(pwd):/mnt/source osp-builder - name: Upload artifact uses: actions/upload-artifact@v3 From 8d5fe14d01a8d1d486ece3ea2bf1d6d9d83bae0c Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 23 Nov 2023 15:35:44 +0100 Subject: [PATCH 16/29] Build as root --- .github/workflows/ci-conan.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index ed55633..09ed053 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -23,6 +23,7 @@ jobs: FROM conanio/gcc${{ matrix.compiler_version }}-ubuntu16.04 COPY entrypoint.sh / ENTRYPOINT /entrypoint.sh + USER root EOF - name: Generate entrypoint.sh run: | @@ -40,9 +41,7 @@ jobs: - name: Build Docker image run: docker build -t osp-builder /tmp/osp-builder-docker/ - name: Build cosim - run: | - mkdir -m 0777 -p build/dist - docker run --rm --env GITHUB_REF="$GITHUB_REF" -v $(pwd):/mnt/source osp-builder + run: docker run --rm -v $(pwd):/mnt/source osp-builder - name: Upload artifact uses: actions/upload-artifact@v3 with: From 6c77de830a1e792ff2d3eafdb0813b2fb3d03b4a Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 23 Nov 2023 15:40:45 +0100 Subject: [PATCH 17/29] Adjust permissions of build folder --- .github/workflows/ci-conan.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index 09ed053..c553038 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -41,7 +41,9 @@ jobs: - 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 osp-builder + run: | + mkdir -m 0777 build + docker run --rm -v $(pwd):/mnt/source osp-builder - name: Upload artifact uses: actions/upload-artifact@v3 with: From e250a146821c163a8d2359037c44ce45e1df7156 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 23 Nov 2023 15:41:53 +0100 Subject: [PATCH 18/29] Don't run as root --- .github/workflows/ci-conan.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index c553038..39c4758 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -23,7 +23,6 @@ jobs: FROM conanio/gcc${{ matrix.compiler_version }}-ubuntu16.04 COPY entrypoint.sh / ENTRYPOINT /entrypoint.sh - USER root EOF - name: Generate entrypoint.sh run: | From d2b6c1d8239270d15c59e5f88150fa18fa2fd7c0 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 23 Nov 2023 16:05:06 +0100 Subject: [PATCH 19/29] Revert to older patchelf version so we can use GCC 9 --- .github/workflows/ci-conan.yml | 2 +- conanfile.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index 39c4758..c909693 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -11,7 +11,7 @@ jobs: fail-fast: false matrix: build_type: [Debug, Release] - compiler_version: [11] + compiler_version: [9] option_proxyfmu: ['proxyfmu=True', 'proxyfmu=False'] steps: diff --git a/conanfile.py b/conanfile.py index 5342b3b..205ebe6 100644 --- a/conanfile.py +++ b/conanfile.py @@ -12,7 +12,7 @@ class CosimCLIConan(ConanFile): def requirements(self): self.tool_requires("cmake/[>=3.19]") if self.settings.os == "Linux": - self.tool_requires("patchelf/[>=0.18]") + self.tool_requires("patchelf/[<0.18]") self.requires("libcosim/0.11.0@osp/testing-feature_conan-2") self.requires("boost/[>=1.71]") From 41683218d2d61c8525553ebdfe5d0df8f51938f2 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 22 Feb 2024 08:42:50 +0100 Subject: [PATCH 20/29] Simplify and document build steps --- CMakeLists.txt | 5 +++- README.md | 62 +++++++++++++++++++++++++++++--------------------- conanfile.py | 6 +++-- 3 files changed, 44 insertions(+), 29 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ab2bb77..73f603a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,9 @@ cmake_minimum_required(VERSION 3.15) project("cosim" VERSION "0.8.0") -set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/dist") + +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/dist" CACHE PATH "Install prefix" FORCE) +endif() # To enable verbose when needed set(CMAKE_VERBOSE_MAKEFILE OFF) diff --git a/README.md b/README.md index de5794b..fcb239f 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ cosim `cosim` is a command-line co-simulation tool based on [libcosim]. It has three primary use cases: - * Running simulations from other programs or scripts + * Running co-simulations from a command-line environment + * Running co-simulations from other programs or scripts * FMU testing and debugging - * Users who simply prefer to work from the command line Specifically, `cosim` can be used to perform the following tasks: @@ -15,7 +15,7 @@ Specifically, `cosim` can be used to perform the following tasks: * Show information about an FMU The output from the simulations is in the form of CSV files that can be easily -parsed by other programs, for example Microsoft Excel. +parsed by other programs. Usage ----- @@ -30,8 +30,8 @@ extra information (e.g. progress) to the user's terminal: cosim run path/to/my_system --output-dir=path/to/my_results -v -The documentation is built into the program itself, by means of the `help` subcommand. - +The documentation is built into the program itself and can be accessed by +means of the `help` subcommand. How to build ------------ @@ -40,30 +40,40 @@ The tools and steps required to build `cosim` are more or less the same as those required for libcosim, so we refer to the [libcosim README] for this information. There are some noteworthy differences, though: - * Conan is a *mandatory* requirement for the time being. + * Conan 2.x is a *mandatory* requirement for the time being. * Doxygen is not needed, as there is no API documentation to generate. To summarise, a typical configure–build–run session might look like the following. -On Linux: - - mkdir build - cd build - conan install .. - cmake .. -DCMAKE_BUILD_TYPE=Debug - cmake --build . - ./cosim help - +On Linux, starting from the root source directory (the one that contains this +README): +```sh +conan install -s build_type=Release --build=missing . # Install dependencies +cmake --preset=conan-release # Configure build system +cmake --build --preset=conan-release # Build +cmake --build --preset=conan-release --target=install # Install to dist/ +build/Release/dist/bin/cosim help # Run +``` And on Windows: - - mkdir build - cd build - conan install .. -s build_type=Debug - cmake .. -A x64 - cmake --build . - activate_run.bat - Debug\cosim help - deactivate_run.bat - - +```bat +conan install -s build_type=Release --build=missing . &:: Install dependencies +cmake --preset=conan-default &:: Configure build system +cmake --build --preset=conan-release &:: Build +cmake --build --preset=conan-release --target=install &:: Install to dist/ +build/Release/dist/bin/cosim help &:: Run +``` +In both cases, `Release` and `conan-release` can be replaced with `Debug` and +`conan-debug`, respectively, if you're building for development purposes. + +The `cmake --target=install` command will copy the resulting `cosim` +executable to the `build/Release/dist/bin` directory. The shared libraries +that `cosim` depends on will be copied to the same directory or to +`build/Release/lib`, depending on platform, by the `conan install` command. +Thus, the `dist` directory contains the entire release bundle. You may also +choose to install to a different directory by setting the +[`CMAKE_INSTALL_PREFIX`] variable, but note that dependencies won't be +included in the installation then. + + +[`CMAKE_INSTALL_PREFIX`]: https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html [libcosim]: https://github.com/open-simulation-platform/libcosim [libcosim README]: https://github.com/open-simulation-platform/libcosim#readme diff --git a/conanfile.py b/conanfile.py index 205ebe6..77d07a0 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,7 +1,7 @@ import os from conan import ConanFile -from conan.tools.cmake import CMakeDeps, CMakeToolchain +from conan.tools.cmake import CMakeDeps, CMakeToolchain, cmake_layout from conan.tools.env import VirtualBuildEnv from conan.tools.files import copy @@ -16,6 +16,9 @@ def requirements(self): self.requires("libcosim/0.11.0@osp/testing-feature_conan-2") self.requires("boost/[>=1.71]") + def layout(self): + cmake_layout(self) + def generate(self): # Import shared libraries and executables from dependency packages # to the 'dist/' folder. @@ -49,7 +52,6 @@ def generate(self): # Generate build system tc = CMakeToolchain(self) - tc.user_presets_path = False # Don't touch source directory. tc.generate() CMakeDeps(self).generate() From 5caa6e8db19ad5892f4ce2ca19d68b293b98ed31 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 22 Feb 2024 08:49:06 +0100 Subject: [PATCH 21/29] Use newest libcosim release --- conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conanfile.py b/conanfile.py index 77d07a0..f040da2 100644 --- a/conanfile.py +++ b/conanfile.py @@ -13,7 +13,7 @@ def requirements(self): self.tool_requires("cmake/[>=3.19]") if self.settings.os == "Linux": self.tool_requires("patchelf/[<0.18]") - self.requires("libcosim/0.11.0@osp/testing-feature_conan-2") + self.requires("libcosim/0.10.3@osp/stable") self.requires("boost/[>=1.71]") def layout(self): From dd6d31f77737302cd8b1b57450a5866ccc1abdd3 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 22 Feb 2024 09:17:41 +0100 Subject: [PATCH 22/29] Fix CMake commands in GitHub Actions workflow --- .github/workflows/ci-conan.yml | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index c909693..3da9dbe 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -15,6 +15,10 @@ jobs: option_proxyfmu: ['proxyfmu=True', 'proxyfmu=False'] steps: + - id: build_type_string + uses: ASzc/change-string-case-action@v6 + with: + string: ${{ matrix.build_type }} - uses: actions/checkout@v4 - name: Generate Dockerfile run: | @@ -31,10 +35,10 @@ jobs: set -eu conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force cd /mnt/source - conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing - cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} - cmake --build build - cmake --build build --target install + conan install . -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing + cmake --preset=conan-${{ steps.build_type_string.outputs.lowercase }} + cmake --build --preset=conan-${{ steps.build_type_string.outputs.lowercase }} + cmake --build --preset=conan-${{ steps.build_type_string.outputs.lowercase }} --target install EOF chmod 0777 /tmp/osp-builder-docker/entrypoint.sh - name: Build Docker image @@ -46,8 +50,8 @@ jobs: - name: Upload artifact uses: actions/upload-artifact@v3 with: - name: cosim-${{ runner.os }}-${{ matrix.build_type }}-${{ matrix.compiler_version }}-${{ matrix.option_proxyfmu }} - path: build/dist + name: cosim-${{ runner.os }}-${{ steps.build_type_string.outputs.lowercase }}-${{ matrix.compiler_version }}-${{ matrix.option_proxyfmu }} + path: build/${{ matrix.build_type }}/dist windows: name: Windows @@ -60,6 +64,10 @@ jobs: option_proxyfmu: ['proxyfmu=True', 'proxyfmu=False'] steps: + - id: build_type_string + uses: ASzc/change-string-case-action@v6 + with: + string: ${{ matrix.build_type }} - uses: actions/checkout@v4 - name: Install prerequisites run: | @@ -71,12 +79,12 @@ jobs: conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force - name: Build run: | - conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing - cmake -A x64 -B build -S . "-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake" - cmake --build build --config ${{ matrix.build_type }} - cmake --build build --config ${{ matrix.build_type }} --target install + conan install . -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing + cmake --preset=conan-default + cmake --build --preset=conan-${{ steps.build_type_string.outputs.lowercase }} + cmake --build --preset=conan-${{ steps.build_type_string.outputs.lowercase }} --target install - name: Upload artifact uses: actions/upload-artifact@v3 with: name: cosim-${{ runner.os }}-${{ matrix.build_type }}-${{ matrix.option_proxyfmu }} - path: build/dist + path: build/${{ matrix.build_type }}/dist From 9efbcd0c5a4edad6a9179f4e8935532ed170704b Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 22 Feb 2024 09:42:00 +0100 Subject: [PATCH 23/29] Debugging problems with Linux CI workflow --- .github/workflows/ci-conan.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index 3da9dbe..c711769 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -34,6 +34,7 @@ jobs: #!/bin/bash -v set -eu conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force + ls -l /mnt/source cd /mnt/source conan install . -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing cmake --preset=conan-${{ steps.build_type_string.outputs.lowercase }} @@ -45,6 +46,8 @@ jobs: run: docker build -t osp-builder /tmp/osp-builder-docker/ - name: Build cosim run: | + ls -l .. + ls -l . mkdir -m 0777 build docker run --rm -v $(pwd):/mnt/source osp-builder - name: Upload artifact From 1cab6ae159b3e25deb5a079c378554e36b01f065 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 22 Feb 2024 09:47:21 +0100 Subject: [PATCH 24/29] Make source folder writable by docker containers --- .github/workflows/ci-conan.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index c711769..acaa67f 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -34,7 +34,6 @@ jobs: #!/bin/bash -v set -eu conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force - ls -l /mnt/source cd /mnt/source conan install . -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing cmake --preset=conan-${{ steps.build_type_string.outputs.lowercase }} @@ -46,8 +45,7 @@ jobs: run: docker build -t osp-builder /tmp/osp-builder-docker/ - name: Build cosim run: | - ls -l .. - ls -l . + chmod 0777 $(pwd) # because the conanio Docker images are set up to run commands as an unprivileged user mkdir -m 0777 build docker run --rm -v $(pwd):/mnt/source osp-builder - name: Upload artifact From 5bfe7825392d991fe2d298cddc3f714a855b3f1e Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 22 Feb 2024 09:51:41 +0100 Subject: [PATCH 25/29] Revert "Make source folder writable by docker containers" This reverts commit 1cab6ae159b3e25deb5a079c378554e36b01f065. --- .github/workflows/ci-conan.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index acaa67f..c711769 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -34,6 +34,7 @@ jobs: #!/bin/bash -v set -eu conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force + ls -l /mnt/source cd /mnt/source conan install . -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing cmake --preset=conan-${{ steps.build_type_string.outputs.lowercase }} @@ -45,7 +46,8 @@ jobs: run: docker build -t osp-builder /tmp/osp-builder-docker/ - name: Build cosim run: | - chmod 0777 $(pwd) # because the conanio Docker images are set up to run commands as an unprivileged user + ls -l .. + ls -l . mkdir -m 0777 build docker run --rm -v $(pwd):/mnt/source osp-builder - name: Upload artifact From 9920f613beff9660fc12fc1505e952d1157c0390 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 22 Feb 2024 09:51:51 +0100 Subject: [PATCH 26/29] Revert "Debugging problems with Linux CI workflow" This reverts commit 9efbcd0c5a4edad6a9179f4e8935532ed170704b. --- .github/workflows/ci-conan.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index c711769..3da9dbe 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -34,7 +34,6 @@ jobs: #!/bin/bash -v set -eu conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force - ls -l /mnt/source cd /mnt/source conan install . -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing cmake --preset=conan-${{ steps.build_type_string.outputs.lowercase }} @@ -46,8 +45,6 @@ jobs: run: docker build -t osp-builder /tmp/osp-builder-docker/ - name: Build cosim run: | - ls -l .. - ls -l . mkdir -m 0777 build docker run --rm -v $(pwd):/mnt/source osp-builder - name: Upload artifact From b0d31bfc90d7dc8f85358c94611fd5390b0aba77 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 22 Feb 2024 09:52:35 +0100 Subject: [PATCH 27/29] Revert "Fix CMake commands in GitHub Actions workflow" This reverts commit dd6d31f77737302cd8b1b57450a5866ccc1abdd3. --- .github/workflows/ci-conan.yml | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index 3da9dbe..c909693 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -15,10 +15,6 @@ jobs: option_proxyfmu: ['proxyfmu=True', 'proxyfmu=False'] steps: - - id: build_type_string - uses: ASzc/change-string-case-action@v6 - with: - string: ${{ matrix.build_type }} - uses: actions/checkout@v4 - name: Generate Dockerfile run: | @@ -35,10 +31,10 @@ jobs: set -eu conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force cd /mnt/source - conan install . -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing - cmake --preset=conan-${{ steps.build_type_string.outputs.lowercase }} - cmake --build --preset=conan-${{ steps.build_type_string.outputs.lowercase }} - cmake --build --preset=conan-${{ steps.build_type_string.outputs.lowercase }} --target install + conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing + cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + cmake --build build + cmake --build build --target install EOF chmod 0777 /tmp/osp-builder-docker/entrypoint.sh - name: Build Docker image @@ -50,8 +46,8 @@ jobs: - name: Upload artifact uses: actions/upload-artifact@v3 with: - name: cosim-${{ runner.os }}-${{ steps.build_type_string.outputs.lowercase }}-${{ matrix.compiler_version }}-${{ matrix.option_proxyfmu }} - path: build/${{ matrix.build_type }}/dist + name: cosim-${{ runner.os }}-${{ matrix.build_type }}-${{ matrix.compiler_version }}-${{ matrix.option_proxyfmu }} + path: build/dist windows: name: Windows @@ -64,10 +60,6 @@ jobs: option_proxyfmu: ['proxyfmu=True', 'proxyfmu=False'] steps: - - id: build_type_string - uses: ASzc/change-string-case-action@v6 - with: - string: ${{ matrix.build_type }} - uses: actions/checkout@v4 - name: Install prerequisites run: | @@ -79,12 +71,12 @@ jobs: conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force - name: Build run: | - conan install . -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing - cmake --preset=conan-default - cmake --build --preset=conan-${{ steps.build_type_string.outputs.lowercase }} - cmake --build --preset=conan-${{ steps.build_type_string.outputs.lowercase }} --target install + conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing + cmake -A x64 -B build -S . "-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake" + cmake --build build --config ${{ matrix.build_type }} + cmake --build build --config ${{ matrix.build_type }} --target install - name: Upload artifact uses: actions/upload-artifact@v3 with: name: cosim-${{ runner.os }}-${{ matrix.build_type }}-${{ matrix.option_proxyfmu }} - path: build/${{ matrix.build_type }}/dist + path: build/dist From 288cb1a6e6ca425c87f8fd15083f6bf14d27d30b Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 22 Feb 2024 10:15:27 +0100 Subject: [PATCH 28/29] Fix build instructions --- .github/workflows/ci-conan.yml | 15 ++++++++------- README.md | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index c909693..1ca458c 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -31,23 +31,24 @@ jobs: set -eu conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force cd /mnt/source - conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing - cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} - cmake --build build - cmake --build build --target install + conan install . -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing + cmake -S . -B build/${{ matrix.build_type }} -DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake -DCMAKE_POLICY_DEFAULT_CMP0091=NEW -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + cmake --build build/${{ matrix.build_type }} + cmake --build build/${{ matrix.build_type }} --target install EOF chmod 0777 /tmp/osp-builder-docker/entrypoint.sh - name: Build Docker image run: docker build -t osp-builder /tmp/osp-builder-docker/ - name: Build cosim run: | + chmod 0777 $(pwd) # because commands in conanio containers run as an unprivileged user mkdir -m 0777 build docker run --rm -v $(pwd):/mnt/source osp-builder - name: Upload artifact uses: actions/upload-artifact@v3 with: name: cosim-${{ runner.os }}-${{ matrix.build_type }}-${{ matrix.compiler_version }}-${{ matrix.option_proxyfmu }} - path: build/dist + path: build/${{ matrix.build_type }}/dist windows: name: Windows @@ -71,8 +72,8 @@ jobs: conan remote add osp https://osp.jfrog.io/artifactory/api/conan/conan-local --force - name: Build run: | - conan install . --output-folder=build -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing - cmake -A x64 -B build -S . "-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake" + conan install . -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing + cmake -S . -B build "-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake" -DCMAKE_POLICY_DEFAULT_CMP0091=NEW cmake --build build --config ${{ matrix.build_type }} cmake --build build --config ${{ matrix.build_type }} --target install - name: Upload artifact diff --git a/README.md b/README.md index fcb239f..36f66f6 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ conan install -s build_type=Release --build=missing . &:: Install dependencies cmake --preset=conan-default &:: Configure build system cmake --build --preset=conan-release &:: Build cmake --build --preset=conan-release --target=install &:: Install to dist/ -build/Release/dist/bin/cosim help &:: Run +build/dist/bin/cosim help &:: Run ``` In both cases, `Release` and `conan-release` can be replaced with `Debug` and `conan-debug`, respectively, if you're building for development purposes. From f3de05329749fc003f9a75652dd897c0f0374734 Mon Sep 17 00:00:00 2001 From: "Lars T. Kyllingstad" Date: Thu, 22 Feb 2024 10:24:55 +0100 Subject: [PATCH 29/29] More fixes to build instructions --- .github/workflows/ci-conan.yml | 2 +- README.md | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci-conan.yml b/.github/workflows/ci-conan.yml index 1ca458c..0eda638 100644 --- a/.github/workflows/ci-conan.yml +++ b/.github/workflows/ci-conan.yml @@ -73,7 +73,7 @@ jobs: - name: Build run: | conan install . -s build_type=${{ matrix.build_type }} -o "libcosim/*:${{ matrix.option_proxyfmu }}" --build=missing - cmake -S . -B build "-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake" -DCMAKE_POLICY_DEFAULT_CMP0091=NEW + cmake -S . -B build "-DCMAKE_TOOLCHAIN_FILE=generators/conan_toolchain.cmake" -DCMAKE_POLICY_DEFAULT_CMP0091=NEW cmake --build build --config ${{ matrix.build_type }} cmake --build build --config ${{ matrix.build_type }} --target install - name: Upload artifact diff --git a/README.md b/README.md index 36f66f6..2739e9a 100644 --- a/README.md +++ b/README.md @@ -63,17 +63,20 @@ build/dist/bin/cosim help &:: Run ``` In both cases, `Release` and `conan-release` can be replaced with `Debug` and `conan-debug`, respectively, if you're building for development purposes. +See the [Conan CMakeToolchain documentation] for more information about CMake +presets (and what to do if your CMake version doesn't allow you to use them). The `cmake --target=install` command will copy the resulting `cosim` -executable to the `build/Release/dist/bin` directory. The shared libraries +executable to the `build[/Release]/dist/bin` directory. The shared libraries that `cosim` depends on will be copied to the same directory or to -`build/Release/lib`, depending on platform, by the `conan install` command. -Thus, the `dist` directory contains the entire release bundle. You may also -choose to install to a different directory by setting the +`build/Release/dist/lib`, depending on platform, by the `conan install` +command. Thus, the `dist` directory contains the entire release bundle. You +may also choose to install to a different directory by setting the [`CMAKE_INSTALL_PREFIX`] variable, but note that dependencies won't be included in the installation then. [`CMAKE_INSTALL_PREFIX`]: https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html +[Conan CMakeToolchain documentation]: https://docs.conan.io/2/examples/tools/cmake/cmake_toolchain/build_project_cmake_presets.html [libcosim]: https://github.com/open-simulation-platform/libcosim [libcosim README]: https://github.com/open-simulation-platform/libcosim#readme