Skip to content

Commit

Permalink
Set custom cmake compile options for tests target only
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunday111 committed Aug 12, 2024
1 parent 4dab929 commit 59e092c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 13 additions & 6 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
File renamed without changes.

0 comments on commit 59e092c

Please sign in to comment.