From 8688293d41d382f485b3fd2aed0c465986775496 Mon Sep 17 00:00:00 2001 From: Master92 Date: Tue, 5 Dec 2023 08:46:40 +0100 Subject: [PATCH 01/14] Add cmake layout to conanfile --- conanfile.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/conanfile.txt b/conanfile.txt index cb01832..8ed230f 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -3,4 +3,7 @@ doctest/[>=2.4] [generators] CMakeDeps -CMakeToolchain \ No newline at end of file +CMakeToolchain + +[layout] +cmake_layout \ No newline at end of file From 13f5a5c916a508f4bd9e87e103b279fab5cf2bb6 Mon Sep 17 00:00:00 2001 From: Master92 Date: Tue, 5 Dec 2023 08:46:50 +0100 Subject: [PATCH 02/14] Fix requirements are only for tests --- conanfile.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conanfile.txt b/conanfile.txt index 8ed230f..f25719b 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,4 +1,4 @@ -[requires] +[test_requires] doctest/[>=2.4] [generators] From 874c013d9e4335e09deedd863034831d9b33711c Mon Sep 17 00:00:00 2001 From: Master92 Date: Tue, 5 Dec 2023 08:47:02 +0100 Subject: [PATCH 03/14] Add CMake as a tool requirement --- conanfile.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/conanfile.txt b/conanfile.txt index f25719b..7df37bf 100644 --- a/conanfile.txt +++ b/conanfile.txt @@ -1,6 +1,9 @@ [test_requires] doctest/[>=2.4] +[tool_requires] +cmake/[>=3.24] + [generators] CMakeDeps CMakeToolchain From 613f9ebbc2f14c665273ee431ddeaf2e82afbbce Mon Sep 17 00:00:00 2001 From: Master92 Date: Tue, 5 Dec 2023 12:48:03 +0100 Subject: [PATCH 04/14] Add install targets --- cmake/CodeCoverage.cmake | 1 + src/CMakeLists.txt | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/cmake/CodeCoverage.cmake b/cmake/CodeCoverage.cmake index 6b3a811..65545ed 100644 --- a/cmake/CodeCoverage.cmake +++ b/cmake/CodeCoverage.cmake @@ -11,3 +11,4 @@ if(CODE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU") ) target_link_options(coverage_config INTERFACE --coverage) endif() +install(TARGETS coverage_config EXPORT ${PROJECT_NAME}-targets) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1cd90d7..a6c813e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -36,3 +36,24 @@ target_include_directories(${PROJECT_NAME} PRIVATE $ ) + +## Install targets +include(GNUInstallDirs) +set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) + +install(EXPORT ${PROJECT_NAME}-targets + FILE ${PROJECT_NAME}Targets.cmake + NAMESPACE ${PROJECT_NAME}:: + DESTINATION ${INSTALL_CONFIGDIR} +) + +install(FILES ${API_HEADERS} ${PROJECT_SOURCE_DIR}/include/${PROJECT_NAME}/${PROJECT_NAME_LOWER}_export.h + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME} +) + +install(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}-targets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} +) From 7d93615b5e2a9c8f3570d9e7eaa436895263e633 Mon Sep 17 00:00:00 2001 From: Master92 Date: Tue, 5 Dec 2023 12:48:26 +0100 Subject: [PATCH 05/14] Default building unit tests to OFF --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f1da020..487bef4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ project(cppIni LANGUAGES CXX VERSION 0.1.0) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) -option(BUILD_TESTING "Build test files" ON) +option(BUILD_TESTING "Build test files" OFF) option(BUILD_SHARED_LIBS "Build shared library files" ON) option(CODE_COVERAGE "Enable coverage reporting" OFF) From 3f25dfe7bc0d8129602d17e23fb4fd4427e7ed42 Mon Sep 17 00:00:00 2001 From: Master92 Date: Tue, 5 Dec 2023 13:22:48 +0100 Subject: [PATCH 06/14] Replace conanfile.txt with python script --- conanfile.py | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++ conanfile.txt | 12 ------- 2 files changed, 89 insertions(+), 12 deletions(-) create mode 100644 conanfile.py delete mode 100644 conanfile.txt diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 0000000..f658a60 --- /dev/null +++ b/conanfile.py @@ -0,0 +1,89 @@ +# cppIni - A C++20 library for reading and writing INI files +# Copyright (C) 2023 Nils Hofmann +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from conan import ConanFile +from conan.tools.build import check_min_cppstd +from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps + + +class cppiniRecipe(ConanFile): + name = "cppini" + version = "0.1.0" + package_type = "library" + + # Optional metadata + license = "GPL-3.0-or-later" + author = "Nils Hofmann " + url = "https://github.com/Master92/cppIni" + description = "A C++20 library for reading and writing INI files" + topics = ("c++20", "configuration", "ini") + + # Binary configuration + settings = "os", "compiler", "build_type", "arch" + options = { + "shared": [True, False], + "fPIC": [True, False], + "testing": [True, False] + } + default_options = { + "shared": False, + "fPIC": True, + "testing": True + } + + # Sources are located in the same place as this recipe, copy them to the recipe + exports_sources = "CMakeLists.txt", "src/*", "include/*", "cmake/*", "tests/*" + + def build_requirements(self): + self.build_requires("cmake/[>=3.24]") + if self.options.testing: + self.test_requires("doctest/[>=2.4]") + + def config_options(self): + if self.settings.os == "Windows": + self.options.rm_safe("fPIC") + + def configure(self): + if self.options.shared: + self.options.rm_safe("fPIC") + + def layout(self): + cmake_layout(self) + + def validate(self): + if self.settings.compiler.cppstd: + check_min_cppstd(self, "20") + + def generate(self): + deps = CMakeDeps(self) + deps.generate() + tc = CMakeToolchain(self) + tc.variables["BUILD_SHARED_LIBS"] = self.options.shared + tc.variables["BUILD_TESTING"] = self.options.testing + tc.generate() + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + cmake.test() + + def package(self): + cmake = CMake(self) + cmake.install() + + def package_info(self): + self.cpp_info.libs = ["cppini"] diff --git a/conanfile.txt b/conanfile.txt deleted file mode 100644 index 7df37bf..0000000 --- a/conanfile.txt +++ /dev/null @@ -1,12 +0,0 @@ -[test_requires] -doctest/[>=2.4] - -[tool_requires] -cmake/[>=3.24] - -[generators] -CMakeDeps -CMakeToolchain - -[layout] -cmake_layout \ No newline at end of file From 330a8dac62c3cf3fc1870f661cd04dedb7ddfbfa Mon Sep 17 00:00:00 2001 From: Master92 Date: Tue, 5 Dec 2023 13:23:06 +0100 Subject: [PATCH 07/14] Add auto-generated test_package --- test_package/CMakeLists.txt | 7 +++++++ test_package/conanfile.py | 26 ++++++++++++++++++++++++++ test_package/src/example.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 test_package/CMakeLists.txt create mode 100644 test_package/conanfile.py create mode 100644 test_package/src/example.cpp diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt new file mode 100644 index 0000000..b981585 --- /dev/null +++ b/test_package/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.15) +project(PackageTest CXX) + +find_package(cppIni CONFIG REQUIRED) + +add_executable(example src/example.cpp) +target_link_libraries(example cppini::cppini) diff --git a/test_package/conanfile.py b/test_package/conanfile.py new file mode 100644 index 0000000..e3cea02 --- /dev/null +++ b/test_package/conanfile.py @@ -0,0 +1,26 @@ +import os + +from conan import ConanFile +from conan.tools.cmake import CMake, cmake_layout +from conan.tools.build import can_run + + +class cppiniTestConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "CMakeDeps", "CMakeToolchain" + + def requirements(self): + self.requires(self.tested_reference_str) + + def build(self): + cmake = CMake(self) + cmake.configure() + cmake.build() + + def layout(self): + cmake_layout(self) + + def test(self): + if can_run(self): + cmd = os.path.join(self.cpp.build.bindir, "example") + self.run(cmd, env="conanrun") diff --git a/test_package/src/example.cpp b/test_package/src/example.cpp new file mode 100644 index 0000000..6ebd2d7 --- /dev/null +++ b/test_package/src/example.cpp @@ -0,0 +1,26 @@ +/* + * cppIni - A C++20 library for reading and writing INI files + * Copyright (C) 2023 Nils Hofmann + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include + +int main() +{ + Section s{"Section1"}; + + return EXIT_SUCCESS; +} From 66df3ece82c656ffde18b7dc7aaeb4ea782421f8 Mon Sep 17 00:00:00 2001 From: Master92 Date: Tue, 5 Dec 2023 13:23:31 +0100 Subject: [PATCH 08/14] Add test_package build folder to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d785328..283d3f3 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /*build* /doc /include/cppIni/cppini_export.h +test_package/build CMakeUserPresets.json From ad20dd09aa70dffe775ae0acad80a8ad0b0fc319 Mon Sep 17 00:00:00 2001 From: Master92 Date: Tue, 5 Dec 2023 13:24:48 +0100 Subject: [PATCH 09/14] Add local python folder to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 283d3f3..6b22081 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ /doc /include/cppIni/cppini_export.h test_package/build +python CMakeUserPresets.json From 3576edab6ce88ff263a1e4be28cde6846c577b48 Mon Sep 17 00:00:00 2001 From: Master92 Date: Tue, 5 Dec 2023 13:43:05 +0100 Subject: [PATCH 10/14] Remove test_package folder from coverage report --- .github/workflows/coverage.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index 135984f..c46f8f6 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -59,7 +59,7 @@ jobs: - name: 📊 Generate coverage reports with lcov run: | lcov --directory . --capture --output-file coverage.info --gcov-tool gcov-13 - lcov --remove coverage.info '/usr/*' --remove coverage.info '**/.conan*' --remove coverage.info '**/test*' --output-file coverage.info + lcov --remove coverage.info '/usr/*' --remove coverage.info '**/.conan*' --remove coverage.info '**/test*' --remove coverage.info '**/test_package*' --output-file coverage.info lcov --list coverage.info - name: ☂️ Upload coverage reports to Codecov From ec51ff3d03f9c1dec32e4bd7e8a1ef65cf824d86 Mon Sep 17 00:00:00 2001 From: Master92 Date: Tue, 5 Dec 2023 14:45:55 +0100 Subject: [PATCH 11/14] Fix build pipeline --- .github/workflows/build.yaml | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 5fcb448..2dd09bf 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -84,21 +84,13 @@ jobs: run: conan profile detect - name: ☁️ Get dependencies - run: conan install ${{ github.workspace }} --build=missing --output-folder=build --settings compiler.cppstd=20 + run: conan install ${{ github.workspace }} --build=missing -s compiler.cppstd=20 -o testing=True - name: 🛠️ Configure CMake - run: > - cmake -B ${{ steps.strings.outputs.build-output-dir }} - -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} - -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} - -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} - -DBUILD_TESTING=ON - -DCODE_COVERAGE=OFF - --toolchain=conan_toolchain.cmake - -S ${{ github.workspace }} + run: cmake --preset conan-release - name: 🔨 Build project - run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} --parallel + run: cmake --build --preset conan-release --parallel - name: 🏃 Run test suite working-directory: build From 82fbf393a13241f9527922e21b0e01b51a296112 Mon Sep 17 00:00:00 2001 From: Master92 Date: Tue, 5 Dec 2023 14:46:23 +0100 Subject: [PATCH 12/14] Add coverage symbol generation to conan recipe --- .github/workflows/coverage.yaml | 15 ++++----------- conanfile.py | 7 +++++-- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/.github/workflows/coverage.yaml b/.github/workflows/coverage.yaml index c46f8f6..4841c68 100644 --- a/.github/workflows/coverage.yaml +++ b/.github/workflows/coverage.yaml @@ -38,23 +38,16 @@ jobs: run: conan profile detect - name: ☁️ Get dependencies - run: conan install ${{ github.workspace }} --build=missing --output-folder=build --settings compiler.cppstd=20 + run: conan install ${{ github.workspace }} --build=missing -s compiler.cppstd=20 -o testing=True -o coverage=True - name: 🛠️ Configure CMake - run: > - cmake -B build - -DCMAKE_BUILD_TYPE=Release - -DBUILD_TESTING=ON - -DCODE_COVERAGE=ON - --toolchain=conan_toolchain.cmake - -S ${{ github.workspace }} + run: cmake --preset conan-release - name: 🔨 Build project - run: cmake --build build --config Release --parallel + run: cmake --build --preset conan-release --parallel - name: 🏃 Run test suite - working-directory: build - run: ctest --build-config Release + run: ctest --preset conan-release - name: 📊 Generate coverage reports with lcov run: | diff --git a/conanfile.py b/conanfile.py index f658a60..e36f11b 100644 --- a/conanfile.py +++ b/conanfile.py @@ -36,12 +36,14 @@ class cppiniRecipe(ConanFile): options = { "shared": [True, False], "fPIC": [True, False], - "testing": [True, False] + "testing": [True, False], + "coverage": [True, False] } default_options = { "shared": False, "fPIC": True, - "testing": True + "testing": True, + "coverage": False } # Sources are located in the same place as this recipe, copy them to the recipe @@ -73,6 +75,7 @@ def generate(self): tc = CMakeToolchain(self) tc.variables["BUILD_SHARED_LIBS"] = self.options.shared tc.variables["BUILD_TESTING"] = self.options.testing + tc.variables["CODE_COVERAGE"] = self.options.coverage tc.generate() def build(self): From e163b86a4241db0df500874b3f771e8e1912ce05 Mon Sep 17 00:00:00 2001 From: Master92 Date: Tue, 5 Dec 2023 15:00:47 +0100 Subject: [PATCH 13/14] Fix preset name based on runner os --- .github/workflows/build.yaml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 2dd09bf..87efaa5 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -78,7 +78,13 @@ jobs: # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. id: strings shell: bash - run: echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + run: | + echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + if [ "${{ matrix.os }}" == "windows-latest" ]; then + echo "preset-name=conan-default" >> "$GITHUB_OUTPUT" + else + echo "preset-name=conan-release" >> "$GITHUB_OUTPUT" + fi - name: 🐸 Create default Conan profile run: conan profile detect @@ -87,11 +93,10 @@ jobs: run: conan install ${{ github.workspace }} --build=missing -s compiler.cppstd=20 -o testing=True - name: 🛠️ Configure CMake - run: cmake --preset conan-release + run: cmake --preset ${{ steps.strings.outputs.preset-name }} - name: 🔨 Build project - run: cmake --build --preset conan-release --parallel + run: cmake --build --preset ${{ steps.strings.outputs.preset-name }} --parallel - name: 🏃 Run test suite - working-directory: build - run: ctest --build-config ${{ matrix.build_type }} + run: ctest --preset ${{ steps.strings.outputs.preset-name }} From 14178fc562f9d0dd72fad9d47a1244a186e61632 Mon Sep 17 00:00:00 2001 From: Master92 Date: Tue, 5 Dec 2023 15:07:28 +0100 Subject: [PATCH 14/14] Fix different profile names --- .github/workflows/build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 87efaa5..52976c4 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -96,7 +96,7 @@ jobs: run: cmake --preset ${{ steps.strings.outputs.preset-name }} - name: 🔨 Build project - run: cmake --build --preset ${{ steps.strings.outputs.preset-name }} --parallel + run: cmake --build --preset conan-release --parallel - name: 🏃 Run test suite - run: ctest --preset ${{ steps.strings.outputs.preset-name }} + run: ctest --preset conan-release