From 59e092c4fbe788b4658e733f42110f576d7d44ba Mon Sep 17 00:00:00 2001 From: Kostiantyn Lazukin Date: Mon, 12 Aug 2024 22:02:55 +0100 Subject: [PATCH] Set custom cmake compile options for tests target only --- CMakeLists.txt | 5 ----- tests/CMakeLists.txt | 19 +++++++++++++------ .../cmake}/generic_compile_options.cmake | 0 3 files changed, 13 insertions(+), 11 deletions(-) rename {cmake => tests/cmake}/generic_compile_options.cmake (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 01f2f66..bede31b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,18 +2,13 @@ cmake_minimum_required(VERSION 3.16) project(ASS) -set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_CURRENT_SOURCE_DIR}/cmake") # Library target - file(GLOB_RECURSE target_sources ${CMAKE_CURRENT_SOURCE_DIR}/include/*.hpp) - set(target_name ass) add_library(${target_name} INTERFACE ${target_sources}) target_include_directories(${target_name} INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include) -include(generic_compile_options) -set_generic_compile_options(${target_name} INTERFACE) option(ASS_ENABLE_TESTING "Build with tests" OFF) if (ASS_ENABLE_TESTING) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f2c2071..dafebbb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,21 +1,28 @@ cmake_minimum_required(VERSION 3.16) +include("${CMAKE_CURRENT_SOURCE_DIR}/cmake/generic_compile_options.cmake") + include(FetchContent) file(GLOB_RECURSE target_headers ${CMAKE_CURRENT_SOURCE_DIR}/*.hpp) file(GLOB_RECURSE target_sources ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp) -FetchContent_Declare( - googletest - GIT_REPOSITORY https://github.com/google/googletest - GIT_TAG "release-1.12.1" -) +option(ASS_FETCH_GOOGLE_TESTS "Disable it if you already have google tests in your project" ON) -FetchContent_MakeAvailable(googletest) +if (CPP_REFLECTION_SHARED) + FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest + GIT_TAG "release-1.12.1" + ) + + FetchContent_MakeAvailable(googletest) +endif() set(target_name ass_tests) add_executable(${target_name} ${target_headers} ${target_sources}) target_link_libraries(${target_name} PUBLIC gtest_main ass) +set_generic_compile_options(${target_name} INTERFACE) enable_testing() include(GoogleTest) diff --git a/cmake/generic_compile_options.cmake b/tests/cmake/generic_compile_options.cmake similarity index 100% rename from cmake/generic_compile_options.cmake rename to tests/cmake/generic_compile_options.cmake