From e9b94ceee1384387e41bac6b3ab0f2682ac49823 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Thu, 21 Nov 2024 05:16:24 +0100 Subject: [PATCH 01/16] Export cmake config package Fix windows build Add CI for macos and windows --- .cmake-format | 19 ++++ .github/workflows/macos.yml | 46 ++++++++ .github/workflows/windows.yml | 48 ++++++++ .gitignore | 1 + CMakeLists.txt | 104 +++++++++++++---- CMakePresets.json | 107 ++++++++++++++++++ cmake/CMakeDarwinPresets.json | 48 ++++++++ cmake/CMakeGenericPresets.json | 23 ++++ cmake/CMakeLinuxPresets.json | 49 ++++++++ cmake/CMakeWindowsPresets.json | 32 ++++++ cmake/Config.cmake.in | 7 ++ examples/CMakeLists.txt | 4 +- .../beman/inplace_vector/inplace_vector.hpp | 4 +- tests/beman/inplace_vector/CMakeLists.txt | 5 +- 14 files changed, 468 insertions(+), 29 deletions(-) create mode 100644 .cmake-format create mode 100644 .github/workflows/macos.yml create mode 100644 .github/workflows/windows.yml create mode 100644 CMakePresets.json create mode 100644 cmake/CMakeDarwinPresets.json create mode 100644 cmake/CMakeGenericPresets.json create mode 100644 cmake/CMakeLinuxPresets.json create mode 100644 cmake/CMakeWindowsPresets.json create mode 100644 cmake/Config.cmake.in diff --git a/.cmake-format b/.cmake-format new file mode 100644 index 0000000..e38f9f3 --- /dev/null +++ b/.cmake-format @@ -0,0 +1,19 @@ +format: + line_width: 119 + tab_size: 4 + max_subgroups_hwrap: 4 + max_rows_cmdline: 8 + separate_ctrl_name_with_space: false + separate_fn_name_with_space: false + dangle_parens: true + dangle_align: prefix + line_ending: unix + keyword_case: upper + always_wrap: + - file + - install + - project + - write_basic_package_version_file + +markup: + enable_markup: false diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml new file mode 100644 index 0000000..fca3e26 --- /dev/null +++ b/.github/workflows/macos.yml @@ -0,0 +1,46 @@ +# .github/workflows/macos.yml +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +name: Macos Build + +on: + push: + branches: ["main", "develop"] + pull_request: + branches: ["main", "develop"] + +jobs: + build: + runs-on: macos-15 + strategy: + fail-fast: false + + matrix: + preset: [debug, release] + # TODO: compiler: [g++, clang++-19] + compiler: [g++, clang++-18] + + steps: + - uses: actions/checkout@v4 + + - name: Setup Cpp + # if: startsWith(matrix.compiler, 'clang') + uses: aminya/setup-cpp@v1 + with: + # TODO: compiler: llvm-19 + # clangtidy: true + # cmake: true + ninja: true + + - name: Install llvm-19 + if: startsWith(matrix.compiler, 'clang') + run: | + brew install llvm@19 || echo ignored + + - name: macos clang++-18 ${{ matrix.preset }} + if: startsWith(matrix.compiler, 'clang') + run: CXX=$(brew --prefix llvm@18)/bin/clang++ cmake --workflow --preset ${{ matrix.preset }} + + - name: macos g++ ${{ matrix.preset }} + if: startsWith(matrix.compiler, 'g++') + run: CXX=${{ matrix.compiler }} cmake --workflow --preset ${{ matrix.preset }} diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml new file mode 100644 index 0000000..0b2bb0f --- /dev/null +++ b/.github/workflows/windows.yml @@ -0,0 +1,48 @@ +# .github/workflows/windows.yml +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +name: Windows Build + +on: + push: + branches: ["main", "develop"] + pull_request: + branches: ["main", "develop"] + +jobs: + build: + runs-on: windows-latest + strategy: + fail-fast: false + + matrix: + preset: [debug, release] + # TODO: compiler: [cl, clang-cl] + compiler: [cl] + + steps: + - uses: actions/checkout@v4 + + # see https://github.com/marketplace/actions/enable-developer-command-prompt + - uses: ilammy/msvc-dev-cmd@v1 + with: + vsversion: 2022 + + # - name: build environment + # run: pip install -r requirements.txt + + - name: cmake workflow ${{ matrix.preset }} + shell: bash + run: | + cmake --version + ninja --version + CXX=${{ matrix.compiler }} cmake --workflow --preset ${{ matrix.preset }} + + # - name: configure + # run: CXX=${{ matrix.compiler }} cmake --preset ${{ matrix.preset }} + + # - name: build + # run: cmake --build --preset ${{ matrix.preset }} + + # - name: ctest + # run: ctest --preset ${{ matrix.preset }} diff --git a/.gitignore b/.gitignore index 172d4ef..2696a73 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/stagedir /build /out CMakeUserPresets.json diff --git a/CMakeLists.txt b/CMakeLists.txt index e7d6744..1ab5210 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,16 +3,22 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # cmake-format: on -cmake_minimum_required(VERSION 3.23) +set(CMAKE_SKIP_TEST_ALL_DEPENDENCY FALSE) + +cmake_minimum_required(VERSION 3.25...3.31) project( - beman.inplace_vector + beman_inplace_vector VERSION 1.0.0 DESCRIPTION "A dynamically-resizable vector with fixed capacity and embedded storage" LANGUAGES CXX ) +if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) + message(FATAL_ERROR "In-source builds are not allowed!") +endif() + # [CMAKE.SKIP_EXAMPLES] option( BEMAN_EXEMPLAR_BUILD_EXAMPLES @@ -28,37 +34,87 @@ option( ) include(GNUInstallDirs) +include(CMakePackageConfigHelpers) -add_library(beman.inplace_vector INTERFACE) +add_library(beman_inplace_vector INTERFACE) # [CMAKE.LIBRARY_ALIAS] -add_library(beman::inplace_vector ALIAS beman.inplace_vector) +add_library(beman::inplace_vector ALIAS beman_inplace_vector) + +#XXX target_include_directories(beman.inplace_vector ... ? -target_include_directories( - beman.inplace_vector +target_sources( + beman_inplace_vector + PUBLIC + FILE_SET inplace_vector_public_headers + TYPE HEADERS + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include + FILES + "${CMAKE_CURRENT_SOURCE_DIR}/include/beman/inplace_vector/inplace_vector.hpp" +) +set_target_properties( + beman_inplace_vector + PROPERTIES VERIFY_INTERFACE_HEADER_SETS ON +) +target_compile_features( + beman_inplace_vector INTERFACE - $ - $ + "$<$:cxx_std_23>" + "$<$>:cxx_std_20>" ) -# Install the InplaceVector library to the appropriate destination -install( - TARGETS beman.inplace_vector - EXPORT ${TARGETS_EXPORT_NAME} - DESTINATION - ${CMAKE_INSTALL_LIBDIR} -) +block() + # copied from execution26: + set(TARGET_NAME beman_inplace_vector) + set(TARGET_NAMESPACE beman) + # set(TARGET_PREFIX ${TARGET_NAMESPACE}.${TARGET_NAME}) # FIXME: not used yet? CK + # set(TARGET_LIBRARY ${PROJECT_NAME}) + # set(TARGET_ALIAS ${TARGET_LIBRARY}::${TARGET_LIBRARY}) + set(TARGET_PACKAGE_NAME ${PROJECT_NAME}-config) + set(TARGETS_EXPORT_NAME ${PROJECT_NAME}-targets) + set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) -# Install the header files to the appropriate destination -install( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ - DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${CMAKE_PROJECT_NAME} - FILES_MATCHING - PATTERN - "${CMAKE_CURRENT_SOURCE_DIR}/include/beman/inplace_vector/inplace_vector.hpp" -) + # Install the InplaceVector library to the appropriate destination + install( + TARGETS beman_inplace_vector + EXPORT ${TARGETS_EXPORT_NAME} + FILE_SET inplace_vector_public_headers + # DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) + + if(EXISTS cmake/Config.cmake.in) + write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}-version.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY AnyNewerVersion + ) + + configure_package_config_file( + cmake/Config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}.cmake + INSTALL_DESTINATION ${INSTALL_CONFIGDIR} + ) + + install( + FILES + ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}-version.cmake + DESTINATION ${INSTALL_CONFIGDIR} + ) + + install( + EXPORT ${TARGETS_EXPORT_NAME} + FILE ${TARGETS_EXPORT_NAME}.cmake + DESTINATION "${INSTALL_CONFIGDIR}" + NAMESPACE beman:: + ) + + set(CPACK_GENERATOR TGZ) + include(CPack) + endif() +endblock() if(BEMAN_INPLACE_VECTOR_BUILD_TESTS) - include(CTest) + enable_testing() add_subdirectory(tests/beman/inplace_vector) endif() diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..2fd4ebd --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,107 @@ +{ + "version": 9, + "cmakeMinimumRequired": { + "major": 3, + "minor": 30, + "patch": 0 + }, + "include": [ + "cmake/CMake${hostSystemName}Presets.json" + ], + "buildPresets": [ + { + "name": "debug", + "configurePreset": "debug", + "configuration": "Debug", + "targets": [ + "install" + ] + }, + { + "name": "release", + "configurePreset": "release", + "configuration": "Release", + "targets": [ + "all_verify_interface_header_sets", + "install" + ] + } + ], + "testPresets": [ + { + "name": "test_base", + "hidden": true, + "output": { + "outputOnFailure": true + }, + "execution": { + "noTestsAction": "error", + "stopOnFailure": false + } + }, + { + "name": "debug", + "inherits": "test_base", + "configuration": "Debug", + "configurePreset": "debug" + }, + { + "name": "release", + "inherits": "test_base", + "configuration": "Release", + "configurePreset": "release" + } + ], + "packagePresets": [ + { + "name": "release", + "configurePreset": "release", + "configurations": [ + "Release" + ], + "generators": [ + "TGZ" + ] + } + ], + "workflowPresets": [ + { + "name": "debug", + "steps": [ + { + "type": "configure", + "name": "debug" + }, + { + "type": "build", + "name": "debug" + }, + { + "type": "test", + "name": "debug" + } + ] + }, + { + "name": "release", + "steps": [ + { + "type": "configure", + "name": "release" + }, + { + "type": "build", + "name": "release" + }, + { + "type": "test", + "name": "release" + }, + { + "type": "package", + "name": "release" + } + ] + } + ] +} diff --git a/cmake/CMakeDarwinPresets.json b/cmake/CMakeDarwinPresets.json new file mode 100644 index 0000000..78efdf4 --- /dev/null +++ b/cmake/CMakeDarwinPresets.json @@ -0,0 +1,48 @@ +{ + "version": 6, + "include": [ + "CMakeGenericPresets.json" + ], + "configurePresets": [ + { + "name": "debug-base-Darwin", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Darwin" + } + }, + { + "name": "release-base-Darwin", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Darwin" + } + }, + { + "name": "debug", + "displayName": "Debug Build", + "inherits": [ + "root-config", + "debug-base-Darwin" + ] + }, + { + "name": "release", + "displayName": "Release Build", + "inherits": [ + "root-config", + "release-base-Darwin" + ] + } + ] +} diff --git a/cmake/CMakeGenericPresets.json b/cmake/CMakeGenericPresets.json new file mode 100644 index 0000000..7014512 --- /dev/null +++ b/cmake/CMakeGenericPresets.json @@ -0,0 +1,23 @@ +{ + "version": 6, + "configurePresets": [ + { + "name": "root-config", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/${presetName}", + "installDir": "${sourceDir}/stagedir", + "cacheVariables": { + "CMAKE_PREFIX_PATH": { + "type": "path", + "value": "${sourceDir}/stagedir" + }, + "CMAKE_CXX_EXTENSIONS": false, + "CMAKE_CXX_STANDARD": "23", + "CMAKE_CXX_STANDARD_REQUIRED": true, + "CMAKE_EXPORT_COMPILE_COMMANDS": true, + "CMAKE_SKIP_TEST_ALL_DEPENDENCY": false + } + } + ] +} diff --git a/cmake/CMakeLinuxPresets.json b/cmake/CMakeLinuxPresets.json new file mode 100644 index 0000000..beb1c48 --- /dev/null +++ b/cmake/CMakeLinuxPresets.json @@ -0,0 +1,49 @@ +{ + "version": 6, + "include": [ + "CMakeGenericPresets.json" + ], + "configurePresets": [ + { + "name": "debug-base-Linux", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Linux" + } + }, + { + "name": "release-base-Linux", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo", + "CMAKE_CXX_FLAGS": "-Wall -Wextra -Wpedantic -Wno-shadow -Wconversion -Wsign-conversion -Wcast-align -Wcast-qual -Woverloaded-virtual -Wformat=2 -Wno-error" + }, + "condition": { + "type": "notEquals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "debug", + "displayName": "Debug Build", + "inherits": [ + "root-config", + "debug-base-Linux" + ] + }, + { + "name": "release", + "displayName": "Release Build", + "inherits": [ + "root-config", + "release-base-Linux" + ] + } + ] +} diff --git a/cmake/CMakeWindowsPresets.json b/cmake/CMakeWindowsPresets.json new file mode 100644 index 0000000..d8834f2 --- /dev/null +++ b/cmake/CMakeWindowsPresets.json @@ -0,0 +1,32 @@ +{ + "version": 6, + "include": [ + "CMakeGenericPresets.json" + ], + "configurePresets": [ + { + "name": "release", + "description": "Windows preset for library developers", + "generator": "Ninja Multi-Config", + "binaryDir": "${sourceDir}/build", + "inherits": [ + "root-config" + ], + "cacheVariables": { + "CMAKE_CXX_COMPILER": "cl" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "debug", + "description": "Windows preset for library developers", + "inherits": [ + "release" + ] + } + ] +} diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in new file mode 100644 index 0000000..40463a3 --- /dev/null +++ b/cmake/Config.cmake.in @@ -0,0 +1,7 @@ +# cmake/Config.cmake.in -*-makefile-*- +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") +check_required_components("@TARGET_LIBRARY@") diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 496bc08..9e83c1e 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -2,7 +2,7 @@ set(ALL_EXAMPLES fibonacci) -message("Examples to be built: ${ALL_EXAMPLES}") +message(STATUS "Examples to be built: ${ALL_EXAMPLES}") foreach(example ${ALL_EXAMPLES}) add_executable(beman.inplace_vector.examples.${example}) @@ -12,6 +12,6 @@ foreach(example ${ALL_EXAMPLES}) ) target_link_libraries( beman.inplace_vector.examples.${example} - beman.inplace_vector + beman::inplace_vector ) endforeach() diff --git a/include/beman/inplace_vector/inplace_vector.hpp b/include/beman/inplace_vector/inplace_vector.hpp index 70fbf8b..f8d41e1 100644 --- a/include/beman/inplace_vector/inplace_vector.hpp +++ b/include/beman/inplace_vector/inplace_vector.hpp @@ -74,7 +74,7 @@ struct inplace_vector_destruct_base { inplace_vector_destruct_base( const inplace_vector_destruct_base &&other) noexcept(std::is_nothrow_move_constructible_v) - : elems(), size_(other.size()) {} + : elems(), size_(other.size_) {} inplace_vector_destruct_base & operator=(const inplace_vector_destruct_base &other) noexcept( @@ -565,7 +565,7 @@ class inplace_vector : public inplace_vector_base { for (; this->size() != Capacity && first != last; ++first) { emplace_back(*first); } - return frist; + return first; }; */ diff --git a/tests/beman/inplace_vector/CMakeLists.txt b/tests/beman/inplace_vector/CMakeLists.txt index 0dc7351..fea199a 100644 --- a/tests/beman/inplace_vector/CMakeLists.txt +++ b/tests/beman/inplace_vector/CMakeLists.txt @@ -6,6 +6,9 @@ # Tests add_executable(beman.inplace_vector.test inplace_vector.test.cpp) -target_link_libraries(beman.inplace_vector.test PRIVATE beman.inplace_vector) +target_link_libraries( + beman.inplace_vector.test + PRIVATE beman::beman_inplace_vector +) add_test(NAME beman.inplace_vector.test COMMAND beman.inplace_vector.test) From 67a3b6a4c81a4f26ae12e6443eb5f4a2d94f9d55 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Thu, 21 Nov 2024 06:16:49 +0100 Subject: [PATCH 02/16] Add find-package-test using examples --- CMakeLists.txt | 8 ++++---- cmake/Config.cmake.in | 2 +- examples/CMakeLists.txt | 17 ++++++++++++++++- tests/beman/inplace_vector/CMakeLists.txt | 15 +++++++++++++++ 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ab5210..90cca57 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,14 +33,13 @@ option( ${PROJECT_IS_TOP_LEVEL} ) +# includes include(GNUInstallDirs) include(CMakePackageConfigHelpers) add_library(beman_inplace_vector INTERFACE) # [CMAKE.LIBRARY_ALIAS] -add_library(beman::inplace_vector ALIAS beman_inplace_vector) - -#XXX target_include_directories(beman.inplace_vector ... ? +add_library(beman::beman_inplace_vector ALIAS beman_inplace_vector) target_sources( beman_inplace_vector @@ -62,13 +61,14 @@ target_compile_features( "$<$>:cxx_std_20>" ) +# export cmake config package block() # copied from execution26: set(TARGET_NAME beman_inplace_vector) set(TARGET_NAMESPACE beman) # set(TARGET_PREFIX ${TARGET_NAMESPACE}.${TARGET_NAME}) # FIXME: not used yet? CK # set(TARGET_LIBRARY ${PROJECT_NAME}) - # set(TARGET_ALIAS ${TARGET_LIBRARY}::${TARGET_LIBRARY}) + # set(TARGET_ALIAS ${TARGET_NAMESPACE}::${TARGET_LIBRARY}) set(TARGET_PACKAGE_NAME ${PROJECT_NAME}-config) set(TARGETS_EXPORT_NAME ${PROJECT_NAME}-targets) set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) diff --git a/cmake/Config.cmake.in b/cmake/Config.cmake.in index 40463a3..050aedb 100644 --- a/cmake/Config.cmake.in +++ b/cmake/Config.cmake.in @@ -4,4 +4,4 @@ @PACKAGE_INIT@ include("${CMAKE_CURRENT_LIST_DIR}/@TARGETS_EXPORT_NAME@.cmake") -check_required_components("@TARGET_LIBRARY@") +check_required_components("@PROJECT_NAME@") diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 9e83c1e..a05f43e 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,5 +1,14 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +cmake_minimum_required(VERSION 3.27...3.31) + +project(beman_inplace_vector_example LANGUAGES CXX) + +if(PROJECT_IS_TOP_LEVEL) + find_package(beman_inplace_vector 1.0.0 EXACT REQUIRED) + enable_testing() +endif() + set(ALL_EXAMPLES fibonacci) message(STATUS "Examples to be built: ${ALL_EXAMPLES}") @@ -12,6 +21,12 @@ foreach(example ${ALL_EXAMPLES}) ) target_link_libraries( beman.inplace_vector.examples.${example} - beman::inplace_vector + beman::beman_inplace_vector ) + if(PROJECT_IS_TOP_LEVEL) + add_test( + NAME ${example} + COMMAND beman.inplace_vector.examples.${example} + ) + endif() endforeach() diff --git a/tests/beman/inplace_vector/CMakeLists.txt b/tests/beman/inplace_vector/CMakeLists.txt index fea199a..b2bd7f2 100644 --- a/tests/beman/inplace_vector/CMakeLists.txt +++ b/tests/beman/inplace_vector/CMakeLists.txt @@ -12,3 +12,18 @@ target_link_libraries( ) add_test(NAME beman.inplace_vector.test COMMAND beman.inplace_vector.test) + +# test if the targets are findable from the build directory +# NOTE: for an INTERFACE library, we may always use the -C Debug! CK +add_test( + NAME find-package-test + COMMAND + ${CMAKE_CTEST_COMMAND} --verbose --output-on-failure -C $ + --build-and-test "${PROJECT_SOURCE_DIR}/examples" + "${CMAKE_CURRENT_BINARY_DIR}/find-package-test" --build-generator + ${CMAKE_GENERATOR} --build-makeprogram ${CMAKE_MAKE_PROGRAM} + --build-options "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" + "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}" + "-DCMAKE_BUILD_TYPE=$" + "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" +) From 25b04eb9b8a036268ca8c5fb60ae3ade584369cd Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Thu, 21 Nov 2024 06:33:29 +0100 Subject: [PATCH 03/16] Add an implementation note --- tests/beman/inplace_vector/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/beman/inplace_vector/CMakeLists.txt b/tests/beman/inplace_vector/CMakeLists.txt index b2bd7f2..63514af 100644 --- a/tests/beman/inplace_vector/CMakeLists.txt +++ b/tests/beman/inplace_vector/CMakeLists.txt @@ -14,7 +14,8 @@ target_link_libraries( add_test(NAME beman.inplace_vector.test COMMAND beman.inplace_vector.test) # test if the targets are findable from the build directory -# NOTE: for an INTERFACE library, we may always use the -C Debug! CK +# NOTE: For an INTERFACE library and multi config generators, +# we may always use the -C Debug config type to prevent problems! CK add_test( NAME find-package-test COMMAND From 3a030e0ab45518d0a052ea1447d5c8c96585fc09 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Thu, 21 Nov 2024 06:40:08 +0100 Subject: [PATCH 04/16] Set CMake minimum version to 3.25 --- examples/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index a05f43e..d24c9b7 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,6 +1,6 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -cmake_minimum_required(VERSION 3.27...3.31) +cmake_minimum_required(VERSION 3.25...3.31) project(beman_inplace_vector_example LANGUAGES CXX) From 192312555935a56ba17009d558fadfa5d4238696 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Thu, 21 Nov 2024 06:55:14 +0100 Subject: [PATCH 05/16] Need to set CMAKE_PREFIX_PATH on Linux CI --- .github/workflows/ci_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index e330c5b..860a509 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -82,7 +82,7 @@ jobs: ninja --version - name: Configure CMake run: | - cmake -B build -S . "-DCMAKE_CXX_STANDARD=${{ matrix.cpp_version }} ${{ matrix.cmake_args.args }}" + cmake -B build -S . -DCMAKE_PREFIX_PATH=/tmp/beman.inplace_vector "-DCMAKE_CXX_STANDARD=${{ matrix.cpp_version }} ${{ matrix.cmake_args.args }}" env: CC: ${{ matrix.compiler.c }} CXX: ${{ matrix.compiler.cpp }} From f9c6d1a282213704e75694548eb34700ca1d370b Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Fri, 22 Nov 2024 23:14:12 +0100 Subject: [PATCH 06/16] Use Ninja Multi-Config generator --- CMakeLists.txt | 12 +- CMakePresets.json | 115 ++++++++++++++++++++ cmake/CMakeDarwinPresets.json | 127 +++++++++++++++++++--- cmake/CMakeGenericPresets.json | 12 +- cmake/CMakeLinuxPresets.json | 126 ++++++++++++++++++--- cmake/gcovr.cfg.in | 11 ++ cmake/toolchains/default.cmake | 1 + tests/beman/inplace_vector/CMakeLists.txt | 9 +- 8 files changed, 376 insertions(+), 37 deletions(-) create mode 100644 cmake/gcovr.cfg.in create mode 100644 cmake/toolchains/default.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 90cca57..b1846bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,7 +78,6 @@ block() TARGETS beman_inplace_vector EXPORT ${TARGETS_EXPORT_NAME} FILE_SET inplace_vector_public_headers - # DESTINATION ${CMAKE_INSTALL_LIBDIR} ) if(EXISTS cmake/Config.cmake.in) @@ -121,3 +120,14 @@ endif() if(BEMAN_EXEMPLAR_BUILD_EXAMPLES) add_subdirectory(examples) endif() + +# Coverage +configure_file(cmake/gcovr.cfg.in gcovr.cfg @ONLY) + +add_custom_target( + process_coverage + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Running gcovr to process coverage results" + COMMAND mkdir -p coverage + COMMAND gcovr --config gcovr.cfg . +) diff --git a/CMakePresets.json b/CMakePresets.json index 2fd4ebd..aa54f88 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -9,6 +9,39 @@ "cmake/CMake${hostSystemName}Presets.json" ], "buildPresets": [ + { + "name": "asan", + "configurePreset": "asan", + "configuration": "Asan", + "targets": [ + "all" + ] + }, + { + "name": "lsan", + "configurePreset": "lsan", + "configuration": "Lsan", + "targets": [ + "all" + ] + }, + { + "name": "usan", + "configurePreset": "usan", + "configuration": "Usan", + "targets": [ + "all" + ] + }, + { + "name": "gcov", + "configurePreset": "gcov", + "configuration": "Coverage", + "targets": [ + "test", + "process_coverage" + ] + }, { "name": "debug", "configurePreset": "debug", @@ -39,6 +72,24 @@ "stopOnFailure": false } }, + { + "name": "asan", + "inherits": "test_base", + "configuration": "Asan", + "configurePreset": "asan" + }, + { + "name": "lsan", + "inherits": "test_base", + "configuration": "Lsan", + "configurePreset": "lsan" + }, + { + "name": "usan", + "inherits": "test_base", + "configuration": "Usan", + "configurePreset": "usan" + }, { "name": "debug", "inherits": "test_base", @@ -65,6 +116,70 @@ } ], "workflowPresets": [ + { + "name": "asan", + "steps": [ + { + "type": "configure", + "name": "asan" + }, + { + "type": "build", + "name": "asan" + }, + { + "type": "test", + "name": "asan" + } + ] + }, + { + "name": "lsan", + "steps": [ + { + "type": "configure", + "name": "lsan" + }, + { + "type": "build", + "name": "lsan" + }, + { + "type": "test", + "name": "lsan" + } + ] + }, + { + "name": "usan", + "steps": [ + { + "type": "configure", + "name": "usan" + }, + { + "type": "build", + "name": "usan" + }, + { + "type": "test", + "name": "usan" + } + ] + }, + { + "name": "gcov", + "steps": [ + { + "type": "configure", + "name": "gcov" + }, + { + "type": "build", + "name": "gcov" + } + ] + }, { "name": "debug", "steps": [ diff --git a/cmake/CMakeDarwinPresets.json b/cmake/CMakeDarwinPresets.json index 78efdf4..457c73a 100644 --- a/cmake/CMakeDarwinPresets.json +++ b/cmake/CMakeDarwinPresets.json @@ -5,34 +5,106 @@ ], "configurePresets": [ { - "name": "debug-base-Darwin", + "name": "base-Darwin", "hidden": true, - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - }, "condition": { "type": "equals", "lhs": "${hostSystemName}", "rhs": "Darwin" + }, + "inherits": [ + "root-config" + ], + "cacheVariables": { + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++", + "CMAKE_CONFIGURATION_TYPES": "Debug;RelWithDebInfo;Coverage;Asan;Lsan;Usan", + "CMAKE_CXX_FLAGS": "-Wall -Wextra -Wpedantic", + "CMAKE_C_FLAGS": "-Wall -Wextra -Wpedantic", + "GCOV_EXECUTABLE": "llvm-cov gcov" } }, { - "name": "release-base-Darwin", + "name": "debug-base-Darwin", "hidden": true, + "inherits": [ + "base-Darwin" + ], "cacheVariables": { - "CMAKE_BUILD_TYPE": "RelWithDebInfo" - }, - "condition": { - "type": "equals", - "lhs": "${hostSystemName}", - "rhs": "Darwin" + "CMAKE_CXX_FLAGS_DEBUG": "-g -O0", + "CMAKE_C_FLAGS_DEBUG": "-g -O0", + "CMAKE_LD_FLAGS_DEBUG": "" + } + }, + { + "name": "relwithdebinfo-base-Darwin", + "hidden": true, + "inherits": [ + "base-Darwin" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo", + "CMAKE_CXX_FLAGS_RELWITHDEBINFO": "-O2 -g", + "CMAKE_C_FLAGS_RELWITHDEBINFO": "-O2 -g", + "CMAKE_LD_FLAGS_RELWITHDEBINFO": "" + } + }, + { + "name": "gcov-base-Darwin", + "hidden": true, + "inherits": [ + "base-Darwin" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Coverage", + "CMAKE_CXX_FLAGS_COVERAGE": "-g --coverage", + "CMAKE_C_FLAGS_COVERAGE": "-g --coverage", + "CMAKE_LD_FLAGS_COVERAGE": "--coverage" + } + }, + { + "name": "asan-base-Darwin", + "hidden": true, + "inherits": [ + "base-Darwin" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Asan", + "CMAKE_CXX_FLAGS_ASAN": "-g -fsanitize=address", + "CMAKE_C_FLAGS_ASAN": "-g -fsanitize=address", + "CMAKE_LD_FLAGS_ASAN": "-fsanitize=address" + } + }, + { + "name": "lsan-base-Darwin", + "hidden": true, + "inherits": [ + "base-Darwin" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Lsan", + "CMAKE_CXX_FLAGS_LSAN": "-g -fsanitize=leak", + "CMAKE_C_FLAGS_LSAN": "-g -fsanitize=leak", + "CMAKE_LD_FLAGS_LSAN": "-fsanitize=leak" + } + }, + { + "name": "usan-base-Darwin", + "hidden": true, + "inherits": [ + "base-Darwin" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Usan", + "CMAKE_CXX_FLAGS_USAN": "-g -fsanitize=undefined", + "CMAKE_C_FLAGS_USAN": "-g -fsanitize=undefined", + "CMAKE_LD_FLAGS_USAN": "-fsanitize=undefined" } }, { "name": "debug", "displayName": "Debug Build", "inherits": [ - "root-config", "debug-base-Darwin" ] }, @@ -40,8 +112,35 @@ "name": "release", "displayName": "Release Build", "inherits": [ - "root-config", - "release-base-Darwin" + "relwithdebinfo-base-Darwin" + ] + }, + { + "name": "gcov", + "displayName": "Coverage Build", + "inherits": [ + "gcov-base-Darwin" + ] + }, + { + "name": "asan", + "displayName": "AddressSanitizer Build", + "inherits": [ + "asan-base-Darwin" + ] + }, + { + "name": "lsan", + "displayName": "LeakSanitizer Build", + "inherits": [ + "lsan-base-Darwin" + ] + }, + { + "name": "usan", + "displayName": "UndefinedSanitizer Build", + "inherits": [ + "usan-base-Darwin" ] } ] diff --git a/cmake/CMakeGenericPresets.json b/cmake/CMakeGenericPresets.json index 7014512..6024c80 100644 --- a/cmake/CMakeGenericPresets.json +++ b/cmake/CMakeGenericPresets.json @@ -4,8 +4,8 @@ { "name": "root-config", "hidden": true, - "generator": "Ninja", - "binaryDir": "${sourceDir}/build/${presetName}", + "generator": "Ninja Multi-Config", + "binaryDir": "${sourceDir}/build", "installDir": "${sourceDir}/stagedir", "cacheVariables": { "CMAKE_PREFIX_PATH": { @@ -16,7 +16,13 @@ "CMAKE_CXX_STANDARD": "23", "CMAKE_CXX_STANDARD_REQUIRED": true, "CMAKE_EXPORT_COMPILE_COMMANDS": true, - "CMAKE_SKIP_TEST_ALL_DEPENDENCY": false + "CMAKE_SKIP_TEST_ALL_DEPENDENCY": false, + "CMAKE_CONFIGURATION_TYPES": "Debug;Release;RelWithDebInfo;Coverage;Asan;Lsan;Usan", + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_TOOLCHAIN_FILE": { + "type": "path", + "value": "${sourceDir}/cmake/toolchains/default.cmake" + } } } ] diff --git a/cmake/CMakeLinuxPresets.json b/cmake/CMakeLinuxPresets.json index beb1c48..07a6324 100644 --- a/cmake/CMakeLinuxPresets.json +++ b/cmake/CMakeLinuxPresets.json @@ -5,35 +5,106 @@ ], "configurePresets": [ { - "name": "debug-base-Linux", + "name": "base-Linux", "hidden": true, - "cacheVariables": { - "CMAKE_BUILD_TYPE": "Debug" - }, "condition": { "type": "equals", "lhs": "${hostSystemName}", "rhs": "Linux" + }, + "inherits": [ + "root-config" + ], + "cacheVariables": { + "CMAKE_C_COMPILER": "clang", + "CMAKE_CXX_COMPILER": "clang++", + "CMAKE_CONFIGURATION_TYPES": "Debug;RelWithDebInfo;Coverage;Asan;Lsan;Usan", + "CMAKE_CXX_FLAGS": "-Wall -Wextra -Wpedantic", + "CMAKE_C_FLAGS": "-Wall -Wextra -Wpedantic", + "GCOV_EXECUTABLE": "llvm-cov gcov" } }, { - "name": "release-base-Linux", + "name": "debug-base-Linux", "hidden": true, + "inherits": [ + "base-Linux" + ], + "cacheVariables": { + "CMAKE_CXX_FLAGS_DEBUG": "-g -O0", + "CMAKE_C_FLAGS_DEBUG": "-g -O0", + "CMAKE_LD_FLAGS_DEBUG": "" + } + }, + { + "name": "relwithdebinfo-base-Linux", + "hidden": true, + "inherits": [ + "base-Linux" + ], "cacheVariables": { "CMAKE_BUILD_TYPE": "RelWithDebInfo", - "CMAKE_CXX_FLAGS": "-Wall -Wextra -Wpedantic -Wno-shadow -Wconversion -Wsign-conversion -Wcast-align -Wcast-qual -Woverloaded-virtual -Wformat=2 -Wno-error" - }, - "condition": { - "type": "notEquals", - "lhs": "${hostSystemName}", - "rhs": "Windows" + "CMAKE_CXX_FLAGS_RELWITHDEBINFO": "-O2 -g", + "CMAKE_C_FLAGS_RELWITHDEBINFO": "-O2 -g", + "CMAKE_LD_FLAGS_RELWITHDEBINFO": "" + } + }, + { + "name": "gcov-base-Linux", + "hidden": true, + "inherits": [ + "base-Linux" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Coverage", + "CMAKE_CXX_FLAGS_COVERAGE": "-g --coverage", + "CMAKE_C_FLAGS_COVERAGE": "-g --coverage", + "CMAKE_LD_FLAGS_COVERAGE": "--coverage" + } + }, + { + "name": "asan-base-Linux", + "hidden": true, + "inherits": [ + "base-Linux" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Asan", + "CMAKE_CXX_FLAGS_ASAN": "-g -fsanitize=address", + "CMAKE_C_FLAGS_ASAN": "-g -fsanitize=address", + "CMAKE_LD_FLAGS_ASAN": "-fsanitize=address" + } + }, + { + "name": "lsan-base-Linux", + "hidden": true, + "inherits": [ + "base-Linux" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Lsan", + "CMAKE_CXX_FLAGS_LSAN": "-g -fsanitize=leak", + "CMAKE_C_FLAGS_LSAN": "-g -fsanitize=leak", + "CMAKE_LD_FLAGS_LSAN": "-fsanitize=leak" + } + }, + { + "name": "usan-base-Linux", + "hidden": true, + "inherits": [ + "base-Linux" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Usan", + "CMAKE_CXX_FLAGS_USAN": "-g -fsanitize=undefined", + "CMAKE_C_FLAGS_USAN": "-g -fsanitize=undefined", + "CMAKE_LD_FLAGS_USAN": "-fsanitize=undefined" } }, { "name": "debug", "displayName": "Debug Build", "inherits": [ - "root-config", "debug-base-Linux" ] }, @@ -41,8 +112,35 @@ "name": "release", "displayName": "Release Build", "inherits": [ - "root-config", - "release-base-Linux" + "relwithdebinfo-base-Linux" + ] + }, + { + "name": "gcov", + "displayName": "Coverage Build", + "inherits": [ + "gcov-base-Linux" + ] + }, + { + "name": "asan", + "displayName": "AddressSanitizer Build", + "inherits": [ + "asan-base-Linux" + ] + }, + { + "name": "lsan", + "displayName": "LeakSanitizer Build", + "inherits": [ + "lsan-base-Linux" + ] + }, + { + "name": "usan", + "displayName": "UndefinedSanitizer Build", + "inherits": [ + "usan-base-Linux" ] } ] diff --git a/cmake/gcovr.cfg.in b/cmake/gcovr.cfg.in new file mode 100644 index 0000000..22de2b1 --- /dev/null +++ b/cmake/gcovr.cfg.in @@ -0,0 +1,11 @@ +root = @CMAKE_SOURCE_DIR@ +cobertura = @CMAKE_BINARY_DIR@/coverage/cobertura.xml +sonarqube = @CMAKE_BINARY_DIR@/coverage/sonarqube.xml +html-details = @CMAKE_BINARY_DIR@/coverage/coverage.html +gcov-executable = @GCOV_EXECUTABLE@ +gcov-parallel = yes +html-theme = github.dark-blue +html-self-contained = yes +print-summary = yes +filter = .*/beman/inplace_vector/.* +exclude = .*\.t\.cpp diff --git a/cmake/toolchains/default.cmake b/cmake/toolchains/default.cmake new file mode 100644 index 0000000..1bb8bf6 --- /dev/null +++ b/cmake/toolchains/default.cmake @@ -0,0 +1 @@ +# empty diff --git a/tests/beman/inplace_vector/CMakeLists.txt b/tests/beman/inplace_vector/CMakeLists.txt index 63514af..1539fbf 100644 --- a/tests/beman/inplace_vector/CMakeLists.txt +++ b/tests/beman/inplace_vector/CMakeLists.txt @@ -14,17 +14,16 @@ target_link_libraries( add_test(NAME beman.inplace_vector.test COMMAND beman.inplace_vector.test) # test if the targets are findable from the build directory -# NOTE: For an INTERFACE library and multi config generators, -# we may always use the -C Debug config type to prevent problems! CK +# NOTE: For an INTERFACE library and multi config generators, we may always use +# the -C Debug config type instead of $ to prevent problems! CK add_test( NAME find-package-test COMMAND - ${CMAKE_CTEST_COMMAND} --verbose --output-on-failure -C $ + ${CMAKE_CTEST_COMMAND} --verbose --output-on-failure -C Debug --build-and-test "${PROJECT_SOURCE_DIR}/examples" "${CMAKE_CURRENT_BINARY_DIR}/find-package-test" --build-generator ${CMAKE_GENERATOR} --build-makeprogram ${CMAKE_MAKE_PROGRAM} --build-options "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" - "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}" - "-DCMAKE_BUILD_TYPE=$" + "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}" "-DCMAKE_BUILD_TYPE=Debug" "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" ) From 75935e970d033386c153fb4c7e5541636104499f Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Fri, 22 Nov 2024 23:48:11 +0100 Subject: [PATCH 07/16] Use environment to get compiler on CI --- .github/workflows/macos.yml | 8 ++++---- CMakePresets.json | 6 +++--- cmake/CMakeDarwinPresets.json | 4 ++-- cmake/CMakeLinuxPresets.json | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index fca3e26..43d29c6 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -16,9 +16,9 @@ jobs: fail-fast: false matrix: - preset: [debug, release] + preset: [debug, release, gcov, asan, lsan, usan] # TODO: compiler: [g++, clang++-19] - compiler: [g++, clang++-18] + compiler: [clang++-19] steps: - uses: actions/checkout@v4 @@ -37,9 +37,9 @@ jobs: run: | brew install llvm@19 || echo ignored - - name: macos clang++-18 ${{ matrix.preset }} + - name: macos clang++-19 ${{ matrix.preset }} if: startsWith(matrix.compiler, 'clang') - run: CXX=$(brew --prefix llvm@18)/bin/clang++ cmake --workflow --preset ${{ matrix.preset }} + run: CXX=$(brew --prefix llvm@19)/bin/clang++ cmake --workflow --preset ${{ matrix.preset }} - name: macos g++ ${{ matrix.preset }} if: startsWith(matrix.compiler, 'g++') diff --git a/CMakePresets.json b/CMakePresets.json index aa54f88..c918f23 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -53,7 +53,7 @@ { "name": "release", "configurePreset": "release", - "configuration": "Release", + "configuration": "RelWithDebInfo", "targets": [ "all_verify_interface_header_sets", "install" @@ -99,7 +99,7 @@ { "name": "release", "inherits": "test_base", - "configuration": "Release", + "configuration": "RelWithDebInfo", "configurePreset": "release" } ], @@ -108,7 +108,7 @@ "name": "release", "configurePreset": "release", "configurations": [ - "Release" + "RelWithDebInfo" ], "generators": [ "TGZ" diff --git a/cmake/CMakeDarwinPresets.json b/cmake/CMakeDarwinPresets.json index 457c73a..856ffc2 100644 --- a/cmake/CMakeDarwinPresets.json +++ b/cmake/CMakeDarwinPresets.json @@ -16,8 +16,8 @@ "root-config" ], "cacheVariables": { - "CMAKE_C_COMPILER": "clang", - "CMAKE_CXX_COMPILER": "clang++", + "CMAKE_C_COMPILER": "$env{CC}", + "CMAKE_CXX_COMPILER": "$env{CXX}", "CMAKE_CONFIGURATION_TYPES": "Debug;RelWithDebInfo;Coverage;Asan;Lsan;Usan", "CMAKE_CXX_FLAGS": "-Wall -Wextra -Wpedantic", "CMAKE_C_FLAGS": "-Wall -Wextra -Wpedantic", diff --git a/cmake/CMakeLinuxPresets.json b/cmake/CMakeLinuxPresets.json index 07a6324..7dbbe70 100644 --- a/cmake/CMakeLinuxPresets.json +++ b/cmake/CMakeLinuxPresets.json @@ -16,8 +16,8 @@ "root-config" ], "cacheVariables": { - "CMAKE_C_COMPILER": "clang", - "CMAKE_CXX_COMPILER": "clang++", + "CMAKE_C_COMPILER": "$env{CC}", + "CMAKE_CXX_COMPILER": "$env{CXX}", "CMAKE_CONFIGURATION_TYPES": "Debug;RelWithDebInfo;Coverage;Asan;Lsan;Usan", "CMAKE_CXX_FLAGS": "-Wall -Wextra -Wpedantic", "CMAKE_C_FLAGS": "-Wall -Wextra -Wpedantic", From ee3d65bf82ad6731aa7c00f7a9470f24ebf151b0 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Fri, 22 Nov 2024 23:59:01 +0100 Subject: [PATCH 08/16] Add find-package-test onyl for Debug builds on CI --- tests/beman/inplace_vector/CMakeLists.txt | 25 +++++++++++++---------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/tests/beman/inplace_vector/CMakeLists.txt b/tests/beman/inplace_vector/CMakeLists.txt index 1539fbf..8b4b54f 100644 --- a/tests/beman/inplace_vector/CMakeLists.txt +++ b/tests/beman/inplace_vector/CMakeLists.txt @@ -16,14 +16,17 @@ add_test(NAME beman.inplace_vector.test COMMAND beman.inplace_vector.test) # test if the targets are findable from the build directory # NOTE: For an INTERFACE library and multi config generators, we may always use # the -C Debug config type instead of $ to prevent problems! CK -add_test( - NAME find-package-test - COMMAND - ${CMAKE_CTEST_COMMAND} --verbose --output-on-failure -C Debug - --build-and-test "${PROJECT_SOURCE_DIR}/examples" - "${CMAKE_CURRENT_BINARY_DIR}/find-package-test" --build-generator - ${CMAKE_GENERATOR} --build-makeprogram ${CMAKE_MAKE_PROGRAM} - --build-options "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" - "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}" "-DCMAKE_BUILD_TYPE=Debug" - "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" -) +if(CMAKE_BUILD_TYPE STREQUAL Debug) + add_test( + NAME find-package-test + COMMAND + ${CMAKE_CTEST_COMMAND} --verbose --output-on-failure -C Debug + --build-and-test "${PROJECT_SOURCE_DIR}/examples" + "${CMAKE_CURRENT_BINARY_DIR}/find-package-test" --build-generator + ${CMAKE_GENERATOR} --build-makeprogram ${CMAKE_MAKE_PROGRAM} + --build-options "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" + "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}" + "-DCMAKE_BUILD_TYPE=Debug" + "-DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}" + ) +endif() From a28d0a82b62dfb5fa58486691288ff7a686be32c Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sat, 23 Nov 2024 00:14:15 +0100 Subject: [PATCH 09/16] Run examples as test too --- .github/workflows/macos.yml | 6 ++---- examples/CMakeLists.txt | 7 +------ 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 43d29c6..4cb9581 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -24,18 +24,16 @@ jobs: - uses: actions/checkout@v4 - name: Setup Cpp - # if: startsWith(matrix.compiler, 'clang') uses: aminya/setup-cpp@v1 with: - # TODO: compiler: llvm-19 - # clangtidy: true # cmake: true ninja: true + gcovr: true - name: Install llvm-19 if: startsWith(matrix.compiler, 'clang') run: | - brew install llvm@19 || echo ignored + brew install llvm@19 - name: macos clang++-19 ${{ matrix.preset }} if: startsWith(matrix.compiler, 'clang') diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index d24c9b7..7f364af 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -23,10 +23,5 @@ foreach(example ${ALL_EXAMPLES}) beman.inplace_vector.examples.${example} beman::beman_inplace_vector ) - if(PROJECT_IS_TOP_LEVEL) - add_test( - NAME ${example} - COMMAND beman.inplace_vector.examples.${example} - ) - endif() + add_test(NAME ${example} COMMAND beman.inplace_vector.examples.${example}) endforeach() From 0ee9ae7b059a5910dc28e730701505acac794679 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sat, 23 Nov 2024 00:26:20 +0100 Subject: [PATCH 10/16] Add missing depends to test for gcovr run --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b1846bd..4dfda7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,6 +127,7 @@ configure_file(cmake/gcovr.cfg.in gcovr.cfg @ONLY) add_custom_target( process_coverage WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + DEPENDS test COMMENT "Running gcovr to process coverage results" COMMAND mkdir -p coverage COMMAND gcovr --config gcovr.cfg . From 7b8857833d8ded75a3b352e1322dac11110aefec Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sat, 23 Nov 2024 18:22:40 +0100 Subject: [PATCH 11/16] Set gcov program from environment on CI --- .github/workflows/macos.yml | 2 +- CMakeLists.txt | 64 +++++++++++++++++------------------ cmake/CMakeDarwinPresets.json | 2 +- cmake/CMakeLinuxPresets.json | 2 +- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 4cb9581..9065fb7 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -37,7 +37,7 @@ jobs: - name: macos clang++-19 ${{ matrix.preset }} if: startsWith(matrix.compiler, 'clang') - run: CXX=$(brew --prefix llvm@19)/bin/clang++ cmake --workflow --preset ${{ matrix.preset }} + run: GCOV=$(brew --prefix llvm@19)/bin/llvm-cov CXX=$(brew --prefix llvm@19)/bin/clang++ cmake --workflow --preset ${{ matrix.preset }} - name: macos g++ ${{ matrix.preset }} if: startsWith(matrix.compiler, 'g++') diff --git a/CMakeLists.txt b/CMakeLists.txt index 4dfda7c..f9a6d42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,12 +63,14 @@ target_compile_features( # export cmake config package block() - # copied from execution26: - set(TARGET_NAME beman_inplace_vector) - set(TARGET_NAMESPACE beman) - # set(TARGET_PREFIX ${TARGET_NAMESPACE}.${TARGET_NAME}) # FIXME: not used yet? CK + # NOTE: copied from execution26: + # FIXME: but not yet used? CK + # set(TARGET_NAME inplace_vector) + # set(TARGET_NAMESPACE beman) + # set(TARGET_PREFIX ${TARGET_NAMESPACE}.${TARGET_NAME}) # set(TARGET_LIBRARY ${PROJECT_NAME}) # set(TARGET_ALIAS ${TARGET_NAMESPACE}::${TARGET_LIBRARY}) + set(TARGET_PACKAGE_NAME ${PROJECT_NAME}-config) set(TARGETS_EXPORT_NAME ${PROJECT_NAME}-targets) set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) @@ -80,36 +82,34 @@ block() FILE_SET inplace_vector_public_headers ) - if(EXISTS cmake/Config.cmake.in) - write_basic_package_version_file( - ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}-version.cmake - VERSION ${PROJECT_VERSION} - COMPATIBILITY AnyNewerVersion - ) + write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}-version.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY AnyNewerVersion + ) - configure_package_config_file( - cmake/Config.cmake.in + configure_package_config_file( + cmake/Config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}.cmake + INSTALL_DESTINATION ${INSTALL_CONFIGDIR} + ) + + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}.cmake - INSTALL_DESTINATION ${INSTALL_CONFIGDIR} - ) - - install( - FILES - ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}.cmake - ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}-version.cmake - DESTINATION ${INSTALL_CONFIGDIR} - ) - - install( - EXPORT ${TARGETS_EXPORT_NAME} - FILE ${TARGETS_EXPORT_NAME}.cmake - DESTINATION "${INSTALL_CONFIGDIR}" - NAMESPACE beman:: - ) - - set(CPACK_GENERATOR TGZ) - include(CPack) - endif() + ${CMAKE_CURRENT_BINARY_DIR}/${TARGET_PACKAGE_NAME}-version.cmake + DESTINATION ${INSTALL_CONFIGDIR} + ) + + install( + EXPORT ${TARGETS_EXPORT_NAME} + FILE ${TARGETS_EXPORT_NAME}.cmake + DESTINATION "${INSTALL_CONFIGDIR}" + NAMESPACE beman:: + ) + + set(CPACK_GENERATOR TGZ) + include(CPack) endblock() if(BEMAN_INPLACE_VECTOR_BUILD_TESTS) diff --git a/cmake/CMakeDarwinPresets.json b/cmake/CMakeDarwinPresets.json index 856ffc2..9491dd7 100644 --- a/cmake/CMakeDarwinPresets.json +++ b/cmake/CMakeDarwinPresets.json @@ -21,7 +21,7 @@ "CMAKE_CONFIGURATION_TYPES": "Debug;RelWithDebInfo;Coverage;Asan;Lsan;Usan", "CMAKE_CXX_FLAGS": "-Wall -Wextra -Wpedantic", "CMAKE_C_FLAGS": "-Wall -Wextra -Wpedantic", - "GCOV_EXECUTABLE": "llvm-cov gcov" + "GCOV_EXECUTABLE": "$env{GCOV} gcov" } }, { diff --git a/cmake/CMakeLinuxPresets.json b/cmake/CMakeLinuxPresets.json index 7dbbe70..8d4072c 100644 --- a/cmake/CMakeLinuxPresets.json +++ b/cmake/CMakeLinuxPresets.json @@ -21,7 +21,7 @@ "CMAKE_CONFIGURATION_TYPES": "Debug;RelWithDebInfo;Coverage;Asan;Lsan;Usan", "CMAKE_CXX_FLAGS": "-Wall -Wextra -Wpedantic", "CMAKE_C_FLAGS": "-Wall -Wextra -Wpedantic", - "GCOV_EXECUTABLE": "llvm-cov gcov" + "GCOV_EXECUTABLE": "$env{GCOV} gcov" } }, { From 9b163210144d996ced875f332dcf745800fd1b11 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sat, 23 Nov 2024 22:10:03 +0100 Subject: [PATCH 12/16] Add missing Windows presets gcov, asan, lsan, and usan presets added --- cmake/CMakeWindowsPresets.json | 148 ++++++++++++++++++++++++++++++--- 1 file changed, 136 insertions(+), 12 deletions(-) diff --git a/cmake/CMakeWindowsPresets.json b/cmake/CMakeWindowsPresets.json index d8834f2..ecb54c9 100644 --- a/cmake/CMakeWindowsPresets.json +++ b/cmake/CMakeWindowsPresets.json @@ -5,27 +5,151 @@ ], "configurePresets": [ { - "name": "release", - "description": "Windows preset for library developers", - "generator": "Ninja Multi-Config", - "binaryDir": "${sourceDir}/build", - "inherits": [ - "root-config" - ], - "cacheVariables": { - "CMAKE_CXX_COMPILER": "cl" - }, + "name": "base-Windows-ClangCL", + "hidden": true, "condition": { "type": "equals", "lhs": "${hostSystemName}", "rhs": "Windows" + }, + "inherits": [ + "root-config" + ], + "cacheVariables": { + "CMAKE_C_COMPILER": "cl", + "CMAKE_CXX_COMPILER": "cl", + "CMAKE_CONFIGURATION_TYPES": "Debug;RelWithDebInfo;Coverage;Asan;Lsan;Usan", + "CMAKE_CXX_FLAGS": "/Wall /WX", + "CMAKE_C_FLAGS": "/Wall /WX" + } + }, + { + "name": "debug-base-Windows-ClangCL", + "hidden": true, + "inherits": [ + "base-Windows-ClangCL" + ], + "cacheVariables": { + "CMAKE_CXX_FLAGS_DEBUG": "/Zi /Od /MDd", + "CMAKE_C_FLAGS_DEBUG": "/Zi /Od /MDd" + } + }, + { + "name": "relwithdebinfo-base-Windows-ClangCL", + "hidden": true, + "inherits": [ + "base-Windows-ClangCL" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "RelWithDebInfo", + "CMAKE_CXX_FLAGS_RELWITHDEBINFO": "/O2 /Zi /MD", + "CMAKE_C_FLAGS_RELWITHDEBINFO": "/O2 /Zi /MD" + } + }, + { + "name": "release-base-Windows-ClangCL", + "hidden": true, + "inherits": [ + "base-Windows-ClangCL" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "CMAKE_CXX_FLAGS_RELEASE": "/O2 /DNDEBUG /MD", + "CMAKE_C_FLAGS_RELEASE": "/O2 /DNDEBUG /MD" + } + }, + { + "name": "coverage-base-Windows-ClangCL", + "hidden": true, + "inherits": [ + "base-Windows-ClangCL" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Coverage", + "CMAKE_CXX_FLAGS_COVERAGE": "-fprofile-instr-generate -fcoverage-mapping", + "CMAKE_C_FLAGS_COVERAGE": "-fprofile-instr-generate -fcoverage-mapping", + "CMAKE_LD_FLAGS_COVERAGE": "-fprofile-instr-generate" + } + }, + { + "name": "asan-base-Windows-ClangCL", + "hidden": true, + "inherits": [ + "base-Windows-ClangCL" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Asan", + "CMAKE_CXX_FLAGS_ASAN": "-fsanitize=address", + "CMAKE_C_FLAGS_ASAN": "-fsanitize=address", + "CMAKE_LD_FLAGS_ASAN": "-fsanitize=address" + } + }, + { + "name": "lsan-base-Windows-ClangCL", + "hidden": true, + "inherits": [ + "base-Windows-ClangCL" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Lsan", + "CMAKE_CXX_FLAGS_LSAN": "-fsanitize=leak", + "CMAKE_C_FLAGS_LSAN": "-fsanitize=leak", + "CMAKE_LD_FLAGS_LSAN": "-fsanitize=leak" + } + }, + { + "name": "usan-base-Windows-ClangCL", + "hidden": true, + "inherits": [ + "base-Windows-ClangCL" + ], + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Usan", + "CMAKE_CXX_FLAGS_USAN": "-fsanitize=undefined", + "CMAKE_C_FLAGS_USAN": "-fsanitize=undefined", + "CMAKE_LD_FLAGS_USAN": "-fsanitize=undefined" } }, { "name": "debug", - "description": "Windows preset for library developers", + "displayName": "Debug Build", + "inherits": [ + "debug-base-Windows-ClangCL" + ] + }, + { + "name": "gcov", + "displayName": "Coverage Build", + "inherits": [ + "coverage-base-Windows-ClangCL" + ] + }, + { + "name": "release", + "displayName": "Release Build", + "inherits": [ + "relwithdebinfo-base-Windows-ClangCL" + ] + }, + { + "name": "asan", + "displayName": "AddressSanitizer Build", + "inherits": [ + "asan-base-Windows-ClangCL" + ] + }, + { + "name": "lsan", + "displayName": "LeakSanitizer Build", + "inherits": [ + "lsan-base-Windows-ClangCL" + ] + }, + { + "name": "usan", + "displayName": "UndefinedSanitizer Build", "inherits": [ - "release" + "usan-base-Windows-ClangCL" ] } ] From 4ec37c33054bb867ea9e07fbaba3017f514426e8 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sun, 24 Nov 2024 04:29:20 +0100 Subject: [PATCH 13/16] Test cmake presets on Linux CI too with clang-19 and gcc-14 on ubuntu-24.04 --- .github/workflows/ci_tests.yml | 45 ++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 860a509..3ad4f67 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -11,21 +11,36 @@ on: - cron: '30 15 * * *' jobs: - # preset-test: - # runs-on: ubuntu-latest - # strategy: - # matrix: - # preset: [] - # name: "Preset Test: ${{ matrix.preset }}" - # steps: - # - uses: actions/checkout@v4 - # - name: Setup build environment - # uses: lukka/get-cmake@latest - # with: - # cmakeVersion: "~3.25.0" - # ninjaVersion: "^1.11.1" - # - name: Run preset - # run: cmake --workflow --preset ${{ matrix.preset }} + preset-test: + runs-on: ubuntu-24.04 + strategy: + matrix: + preset: [debug, release, gcov, asan, lsan, usan] + compiler: + - cpp: g++-14 + c: gcc-14 + gcov: "" + - cpp: clang++-18 + c: clang-18 + gcov: llvm-cov + name: "Preset Test: ${{ matrix.preset }}" + steps: + - uses: actions/checkout@v4 + + - name: Setup build environment + uses: aminya/setup-cpp@v1 + with: + # cmake: true + ninja: true + gcovr: true + + - name: Run preset ${{ matrix.preset }} ${{ matrix.compiler.cpp }} + run: | + cmake --workflow --preset ${{ matrix.preset }} + env: + CC: ${{ matrix.compiler.c }} + CXX: ${{ matrix.compiler.cpp }} + GCOV: ${{ matrix.compiler.gcov }} test: strategy: From 821293ab63229438d437a995044283e0b474f0a3 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sun, 24 Nov 2024 04:40:19 +0100 Subject: [PATCH 14/16] Fix gcov config options --- .github/workflows/ci_tests.yml | 3 ++- cmake/gcovr.cfg.in | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 3ad4f67..8ed1fdc 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -14,6 +14,7 @@ jobs: preset-test: runs-on: ubuntu-24.04 strategy: + fail-fast: false matrix: preset: [debug, release, gcov, asan, lsan, usan] compiler: @@ -23,7 +24,7 @@ jobs: - cpp: clang++-18 c: clang-18 gcov: llvm-cov - name: "Preset Test: ${{ matrix.preset }}" + name: "Preset Test: ${{ matrix.preset }} ${{ matrix.compiler.cpp }}" steps: - uses: actions/checkout@v4 diff --git a/cmake/gcovr.cfg.in b/cmake/gcovr.cfg.in index 22de2b1..93858c5 100644 --- a/cmake/gcovr.cfg.in +++ b/cmake/gcovr.cfg.in @@ -4,7 +4,7 @@ sonarqube = @CMAKE_BINARY_DIR@/coverage/sonarqube.xml html-details = @CMAKE_BINARY_DIR@/coverage/coverage.html gcov-executable = @GCOV_EXECUTABLE@ gcov-parallel = yes -html-theme = github.dark-blue +html-theme = blue html-self-contained = yes print-summary = yes filter = .*/beman/inplace_vector/.* From a75dccb03a4cdd5893cd4b1c8941df5079c79e8d Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sun, 24 Nov 2024 05:02:32 +0100 Subject: [PATCH 15/16] Try to check gcov on linux CI --- .github/workflows/ci_tests.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 8ed1fdc..5b6d941 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -23,7 +23,7 @@ jobs: gcov: "" - cpp: clang++-18 c: clang-18 - gcov: llvm-cov + gcov: llvm-cov-18 name: "Preset Test: ${{ matrix.preset }} ${{ matrix.compiler.cpp }}" steps: - uses: actions/checkout@v4 @@ -37,6 +37,7 @@ jobs: - name: Run preset ${{ matrix.preset }} ${{ matrix.compiler.cpp }} run: | + which llvm-cov gcov gcovr || echo ignored cmake --workflow --preset ${{ matrix.preset }} env: CC: ${{ matrix.compiler.c }} From e7071c736d24d1aa3c0882e6d35e614c332cf6ff Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Sun, 24 Nov 2024 17:34:41 +0100 Subject: [PATCH 16/16] cleanup --- .github/workflows/ci_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 5b6d941..203f3aa 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -37,7 +37,7 @@ jobs: - name: Run preset ${{ matrix.preset }} ${{ matrix.compiler.cpp }} run: | - which llvm-cov gcov gcovr || echo ignored + which llvm-cov-18 gcov gcovr || echo ignored cmake --workflow --preset ${{ matrix.preset }} env: CC: ${{ matrix.compiler.c }}