From 52f43b2b336713a09abcdb4aa0db1c5b6079f4b2 Mon Sep 17 00:00:00 2001 From: Darius Neatu Date: Sat, 29 Jun 2024 01:28:35 +0300 Subject: [PATCH] Split build production vs testing --- .github/workflows/ci.yml | 4 ++-- .gitmodules | 3 --- CMakeLists.txt | 18 +++++++++++++++--- CMakePresets.json | 4 +++- extern/CMakeLists.txt | 6 ------ extern/googletest | 1 - src/Beman/Optional26/CMakeLists.txt | 17 +++-------------- src/Beman/Optional26/tests/CMakeLists.txt | 19 +++++++++++++++++++ 8 files changed, 42 insertions(+), 30 deletions(-) delete mode 100644 extern/CMakeLists.txt delete mode 160000 extern/googletest create mode 100644 src/Beman/Optional26/tests/CMakeLists.txt diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0a5a38bf..5f7c5df9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,11 +62,11 @@ jobs: cd .build echo ${{ matrix.config.cmake_args }} echo ${{ matrix.config.toolchain }} - cmake ${{ matrix.config.cmake_args }} -DCMAKE_TOOLCHAIN_FILE=etc/${{ matrix.config.toolchain }} -B . -S .. + cmake ${{ matrix.config.cmake_args }} -DCMAKE_TOOLCHAIN_FILE=etc/${{ matrix.config.toolchain }} -DCMAKE_BUILD_TESTS=true -B . -S .. - name: Build run: | cmake --build .build --config Asan --target all -- -k 0 - name: Test run: | cd .build - ctest --output-on-failure + ctest --output-on-failure --build-config Asan diff --git a/.gitmodules b/.gitmodules index 9c4e4556..b44d8c09 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ [submodule "papers/wg21"] path = papers/P2988/wg21 url = https://github.com/mpark/wg21.git -[submodule "extern/googletest"] - path = extern/googletest - url = https://github.com/google/googletest.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 564e9d76..b2647469 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,18 +3,30 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception # cmake-format: on -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.27) project( beman_optional26 VERSION 0.0.0 LANGUAGES CXX) -enable_testing() +cmake_policy(VERSION 3.27) set(TARGETS_EXPORT_NAME ${CMAKE_PROJECT_NAME}Targets) -add_subdirectory(extern) +if("${CMAKE_BUILD_TESTS}") + enable_testing() + + # Fetch GoogleTest + include(FetchContent) + FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG f8d7d77c06936315286eb55f8de22cd23c188571 # release-1.14.0 + ) + FetchContent_MakeAvailable(googletest) +endif() + add_subdirectory(src) add_subdirectory(examples) diff --git a/CMakePresets.json b/CMakePresets.json index 40cb22a2..51b846d8 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -14,7 +14,8 @@ "binaryDir": "${sourceDir}/.build/${presetName}", "installDir": "${sourceDir}/.install/${presetName}", "cacheVariables": { - "CMAKE_CONFIGURATION_TYPES": "RelWithDebInfo;Debug;Tsan;Asan" + "CMAKE_CONFIGURATION_TYPES": "RelWithDebInfo;Debug;Tsan;Asan", + "CMAKE_BUILD_TESTS": true } }, { @@ -95,6 +96,7 @@ { "name": "common", "hidden": true, + "configuration": "Asan", "output": { "outputOnFailure": true }, diff --git a/extern/CMakeLists.txt b/extern/CMakeLists.txt deleted file mode 100644 index 31f2a6fc..00000000 --- a/extern/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -# cmake-format: off -# extern/CMakeLists.txt -*-makefile-*- -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# cmake-format: on - -add_subdirectory(googletest EXCLUDE_FROM_ALL) diff --git a/extern/googletest b/extern/googletest deleted file mode 160000 index 305e5a23..00000000 --- a/extern/googletest +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 305e5a238b3c8d11266fbafd85520fb6b3184851 diff --git a/src/Beman/Optional26/CMakeLists.txt b/src/Beman/Optional26/CMakeLists.txt index 59e00a89..28393cbe 100644 --- a/src/Beman/Optional26/CMakeLists.txt +++ b/src/Beman/Optional26/CMakeLists.txt @@ -35,17 +35,6 @@ install( target_link_libraries("${TARGET_LIBRARY}") # Tests -add_executable(optional_test "") - -target_sources( - optional_test - PRIVATE tests/optional.t.cpp tests/optional_ref.t.cpp - tests/optional_monadic.t.cpp tests/optional_range_support.t.cpp - tests/optional_ref_monadic.t.cpp tests/detail/iterator.t.cpp) - -target_link_libraries(optional_test "${TARGET_LIBRARY}") -target_link_libraries(optional_test gtest) -target_link_libraries(optional_test gtest_main) - -include(GoogleTest) -gtest_discover_tests(optional_test) +if("${CMAKE_BUILD_TESTS}") + add_subdirectory(tests) +endif() diff --git a/src/Beman/Optional26/tests/CMakeLists.txt b/src/Beman/Optional26/tests/CMakeLists.txt new file mode 100644 index 00000000..5fe363f8 --- /dev/null +++ b/src/Beman/Optional26/tests/CMakeLists.txt @@ -0,0 +1,19 @@ +# cmake-format: off +# src/Beman/Optional26/tests/CMakeLists.txt -*-makefile-*- +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# cmake-format: on + + +# Tests +add_executable(optional_test "") + +target_sources( + optional_test + PRIVATE optional.t.cpp optional_ref.t.cpp + optional_monadic.t.cpp optional_range_support.t.cpp + optional_ref_monadic.t.cpp detail/iterator.t.cpp) + +target_link_libraries(optional_test "${TARGET_LIBRARY}" GTest::gtest GTest::gtest_main) + +include(GoogleTest) +gtest_add_tests(optional_test "" AUTO)