Skip to content

Commit

Permalink
Conditionally check for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EduMenges committed Jun 5, 2024
1 parent aa9b812 commit 0d01207
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ set(HUNTER_TLS_VERIFY ON)

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

set(IS_MAIN_FILE CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
option(BUILD_TESTING "Enable build of tests" IS_MAIN_FILE)

include("cmake/HunterGate.cmake")
include("cmake/Catch.cmake")

Expand All @@ -20,34 +23,36 @@ HunterGate(

project(SqliteModernCpp)

hunter_add_package(Catch)
hunter_add_package(sqlite3)

find_package(Catch2 CONFIG REQUIRED)
find_package(sqlite3 CONFIG REQUIRED)

set(TEST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests)
file(GLOB TEST_SOURCES ${TEST_SOURCE_DIR}/*.cc)

if(BUILD_TESTING)
hunter_add_package(Catch)
find_package(Catch2 CONFIG REQUIRED)

set(TEST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests)
file(GLOB TEST_SOURCES ${TEST_SOURCE_DIR}/*.cc)

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

enable_testing()

add_library (sqlite_modern_cpp INTERFACE)
target_include_directories(sqlite_modern_cpp INTERFACE hdr/)

add_executable(tests_runner ${TEST_SOURCES})
target_include_directories(tests_runner INTERFACE ${SQLITE3_INCLUDE_DIRS})

if(ENABLE_SQLCIPHER_TESTS)
target_link_libraries(tests_runner Catch2::Catch2 sqlite_modern_cpp sqlite3::sqlite3 -lsqlcipher)
else()
target_link_libraries(tests_runner Catch2::Catch2 sqlite_modern_cpp sqlite3::sqlite3)
endif()

catch_discover_tests(tests_runner)
target_compile_options(tests_runner PUBLIC $<$<CXX_COMPILER_ID:MSVC>:/Zc:__cplusplus> )

target_compile_options(tests_runner PUBLIC $<$<CXX_COMPILER_ID:MSVC>:/Zc:__cplusplus>)
endif()

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

0 comments on commit 0d01207

Please sign in to comment.