From d9133e05c6e1d92ee466877458d1f510d74280a9 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 8 Sep 2024 18:48:48 +0200 Subject: [PATCH] Change project structure: tests as subdirectory, not as a separate project Also: - Set `FETCHCONTENT_BASE_DIR` to default --- .github/workflows/cmake-multi-platform.yml | 2 +- CMakeLists.txt | 7 +++++++ tests/CMakeLists.txt | 14 -------------- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 313f526..7dfe648 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -61,7 +61,7 @@ jobs: -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} - -S ${{ github.workspace }}/tests + -S ${{ github.workspace }} - name: Build # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). diff --git a/CMakeLists.txt b/CMakeLists.txt index fcccb13..fa14c5e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,8 @@ project(tulz) set(CMAKE_CXX_STANDARD 20) +option(TULZ_ENABLE_TESTS "Turn it off in order to disable tests" ON) + set(TULZ_OBSERVER_SOURCES include/tulz/observer/Observer.h include/tulz/observer/Subject.h @@ -96,4 +98,9 @@ target_include_directories(tulz PUBLIC include) if (ANDROID) target_include_directories(tulz PUBLIC android/include) +endif() + +if (TULZ_ENABLE_TESTS) + enable_testing() + add_subdirectory(tests) endif() \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ea6a1b1..32c69d9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,23 +1,11 @@ cmake_minimum_required(VERSION 3.14) project(tulz-tests) -enable_testing() - set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) include(FetchContent) -if (UNIX) - set(DEPS_DIR "deps") -elseif (WIN32) - set(DEPS_DIR "deps-win") -else() - message(FATAL_ERROR "Unsupported OS") -endif() - -get_filename_component(FETCHCONTENT_BASE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/${DEPS_DIR}" REALPATH) - FetchContent_Declare(googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG v1.14.0) @@ -27,8 +15,6 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) FetchContent_MakeAvailable(googletest) -add_subdirectory(../ tulz) - include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR}) function(add_gtest name src)