Skip to content

Commit 0d01207

Browse files
committed
Conditionally check for tests
1 parent aa9b812 commit 0d01207

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

CMakeLists.txt

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ set(HUNTER_TLS_VERIFY ON)
1010

1111
option(HUNTER_ENABLED "Enable Hunter package manager support" ON)
1212

13+
set(IS_MAIN_FILE CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
14+
option(BUILD_TESTING "Enable build of tests" IS_MAIN_FILE)
15+
1316
include("cmake/HunterGate.cmake")
1417
include("cmake/Catch.cmake")
1518

@@ -20,34 +23,36 @@ HunterGate(
2023

2124
project(SqliteModernCpp)
2225

23-
hunter_add_package(Catch)
2426
hunter_add_package(sqlite3)
25-
26-
find_package(Catch2 CONFIG REQUIRED)
2727
find_package(sqlite3 CONFIG REQUIRED)
2828

29-
set(TEST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests)
30-
file(GLOB TEST_SOURCES ${TEST_SOURCE_DIR}/*.cc)
29+
30+
if(BUILD_TESTING)
31+
hunter_add_package(Catch)
32+
find_package(Catch2 CONFIG REQUIRED)
33+
34+
set(TEST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests)
35+
file(GLOB TEST_SOURCES ${TEST_SOURCE_DIR}/*.cc)
3136

3237
IF(NOT ENABLE_SQLCIPHER_TESTS)
3338
list(REMOVE_ITEM TEST_SOURCES ${TEST_SOURCE_DIR}/sqlcipher.cc)
3439
ENDIF(NOT ENABLE_SQLCIPHER_TESTS)
3540

3641
enable_testing()
3742

38-
add_library (sqlite_modern_cpp INTERFACE)
39-
target_include_directories(sqlite_modern_cpp INTERFACE hdr/)
40-
4143
add_executable(tests_runner ${TEST_SOURCES})
4244
target_include_directories(tests_runner INTERFACE ${SQLITE3_INCLUDE_DIRS})
45+
4346
if(ENABLE_SQLCIPHER_TESTS)
4447
target_link_libraries(tests_runner Catch2::Catch2 sqlite_modern_cpp sqlite3::sqlite3 -lsqlcipher)
4548
else()
4649
target_link_libraries(tests_runner Catch2::Catch2 sqlite_modern_cpp sqlite3::sqlite3)
4750
endif()
4851

4952
catch_discover_tests(tests_runner)
50-
target_compile_options(tests_runner PUBLIC $<$<CXX_COMPILER_ID:MSVC>:/Zc:__cplusplus> )
53+
54+
target_compile_options(tests_runner PUBLIC $<$<CXX_COMPILER_ID:MSVC>:/Zc:__cplusplus>)
55+
endif()
5156

5257
# Place the file in the source directory, permitting us to place a single configuration file for YCM there.
5358
# YCM is the code-completion engine for (neo)vim https://github.com/Valloric/YouCompleteMe

0 commit comments

Comments
 (0)