cmake_minimum_required(VERSION 3.23.1) option(ENABLE_SQLCIPHER_TESTS "enable sqlchipher test") include(GNUInstallDirs) # Creates the file compile_commands.json in the build directory. set(CMAKE_EXPORT_COMPILE_COMMANDS ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") include("cmake/Catch.cmake") project(SqliteModernCpp) find_package(Catch2 CONFIG REQUIRED) include(FindSQLite3) find_package(SQLite3 REQUIRED) set(TEST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests) file(GLOB TEST_SOURCES ${TEST_SOURCE_DIR}/*.cc) file(GLOB_RECURSE HEADER_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/hdr/ *.h) 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 $ ) target_sources(sqlite_modern_cpp INTERFACE FILE_SET HEADERS BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/hdr/ FILES ${HEADER_SOURCES} ) install(TARGETS sqlite_modern_cpp FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) 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::Catch2WithMain sqlite_modern_cpp SQLite::SQLite3 -lsqlcipher) else() target_link_libraries(tests_runner Catch2::Catch2WithMain sqlite_modern_cpp SQLite::SQLite3) endif() catch_discover_tests(tests_runner) target_compile_options(tests_runner PUBLIC $<$:/Zc:__cplusplus> ) # 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 IF(EXISTS "${CMAKE_BINARY_DIR}/compile_commands.json") EXECUTE_PROCESS( COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/compile_commands.json ${CMAKE_SOURCE_DIR}/compile_commands.json ) ENDIF()