From 2ee28b56bb13cef10799548b8e20484282a37320 Mon Sep 17 00:00:00 2001 From: Alexander Grund Date: Tue, 14 May 2024 22:36:10 +0200 Subject: [PATCH] CMake: Build tests only on `make test` Add EXCLUDE_FROM_ALL to test binaries as per the Boost convention --- .github/workflows/ci_tests.yml | 9 ++++++--- test/CMakeLists.txt | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index 50c4a39a..dcf90ccf 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -1,4 +1,4 @@ -# Copyright 2019 - 2022 Alexander Grund +# Copyright 2019 - 2024 Alexander Grund # Distributed under the Boost Software License, Version 1.0. # https://www.boost.org/LICENSE_1_0.txt @@ -102,8 +102,8 @@ jobs: extraFlags="$extraFlags -DCMAKE_CXX_FLAGS=-Wundef" fi cmake -DCMAKE_BUILD_TYPE=${{matrix.buildType}} -DBUILD_SHARED_LIBS=${{matrix.shared_lib}} -G "${{matrix.generator}}" $extraFlags .. - - name: Build & Install - run: cmake --build build --config ${{matrix.buildType}} --target install + - name: Build + run: cmake --build build --config ${{matrix.buildType}} --target tests # Run test with both bash and powershell and watch for "Using std::cin" on bash but not on powershell - name: Test @@ -114,6 +114,9 @@ jobs: shell: powershell if: runner.os == 'Windows' run: ctest --output-on-failure -C ${{matrix.buildType}} --verbose + + - name: Install + run: cmake --build build --config ${{matrix.buildType}} --target install - name: Test consumption working-directory: build run: | diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 56f5fdc3..9565b008 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,11 +1,11 @@ -# Copyright 2019 - 2021 Alexander Grund +# Copyright 2019 - 2024 Alexander Grund # Distributed under the Boost Software License, Version 1.0. # https://www.boost.org/LICENSE_1_0.txt include(CheckCXXCompilerFlag) check_cxx_compiler_flag(-Wsuggest-override _BOOST_NOWIDE_SUGGEST_OVERRIDE_SUPPORTED) -add_library(boost_nowide_file_test_helpers STATIC file_test_helpers.cpp) +add_library(boost_nowide_file_test_helpers STATIC EXCLUDE_FROM_ALL file_test_helpers.cpp) target_link_libraries(boost_nowide_file_test_helpers PRIVATE Boost::nowide) target_compile_definitions(boost_nowide_file_test_helpers PRIVATE BOOST_ALL_NO_LIB) @@ -27,7 +27,7 @@ function(boost_nowide_add_test name) endif() set(name ${PROJECT_NAME}-${name}) - add_executable(${name} ${ARG_SRC}) + add_executable(${name} EXCLUDE_FROM_ALL ${ARG_SRC}) add_dependencies(tests ${name}) target_link_libraries(${name} PRIVATE Boost::nowide ${ARG_LIBRARIES}) boost_add_warnings(${name} pedantic ${Boost_NOWIDE_WERROR})