From 2f2eddb4865b395efd4251209fa81c5693a3c023 Mon Sep 17 00:00:00 2001 From: Eduardo Menges Mattje Date: Wed, 5 Jun 2024 17:04:55 -0300 Subject: [PATCH 1/5] Moved HUNTER_ENABLED option to main file --- CMakeLists.txt | 3 +++ cmake/HunterGate.cmake | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f18d59b4..5674c1d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,9 @@ set(CMAKE_CXX_STANDARD 17) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") set(HUNTER_TLS_VERIFY ON) + +option(HUNTER_ENABLED "Enable Hunter package manager support" ON) + include("cmake/HunterGate.cmake") include("cmake/Catch.cmake") diff --git a/cmake/HunterGate.cmake b/cmake/HunterGate.cmake index 45438f11..03496fd7 100644 --- a/cmake/HunterGate.cmake +++ b/cmake/HunterGate.cmake @@ -42,7 +42,6 @@ # * https://github.com/hunter-packages/gate/ # * https://github.com/ruslo/hunter -option(HUNTER_ENABLED "Enable Hunter package manager support" ON) if(HUNTER_ENABLED) if(CMAKE_VERSION VERSION_LESS "3.0") message(FATAL_ERROR "At least CMake version 3.0 required for hunter dependency management." From aa9b8126d7f513d448d4e11e026577c66ec4b284 Mon Sep 17 00:00:00 2001 From: Eduardo Menges Mattje Date: Wed, 5 Jun 2024 17:05:07 -0300 Subject: [PATCH 2/5] Bumped CMake version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5674c1d3..0ac3e952 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.22) option(ENABLE_SQLCIPHER_TESTS "enable sqlchipher test") # Creates the file compile_commands.json in the build directory. From 0d01207b73205cd217ee3e5ecb5426ad8650a82f Mon Sep 17 00:00:00 2001 From: Eduardo Menges Mattje Date: Wed, 5 Jun 2024 17:06:12 -0300 Subject: [PATCH 3/5] Conditionally check for tests --- CMakeLists.txt | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0ac3e952..ecb24bdb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") @@ -20,14 +23,16 @@ 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) @@ -35,11 +40,9 @@ 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() @@ -47,7 +50,9 @@ else() endif() catch_discover_tests(tests_runner) -target_compile_options(tests_runner PUBLIC $<$:/Zc:__cplusplus> ) + + target_compile_options(tests_runner PUBLIC $<$:/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 From 1a98087ebdfaa30514946453af7ac4ef347df4ac Mon Sep 17 00:00:00 2001 From: Eduardo Menges Mattje Date: Wed, 5 Jun 2024 17:07:29 -0300 Subject: [PATCH 4/5] Added languages to project --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ecb24bdb..a282691b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ HunterGate( SHA1 "8010d63d5ae611c564889d5fe12d3cb7a45703ac" ) -project(SqliteModernCpp) +project(SQLiteModernCpp LANGUAGES CXX) hunter_add_package(sqlite3) find_package(sqlite3 CONFIG REQUIRED) @@ -57,8 +57,8 @@ 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 IF(EXISTS "${CMAKE_BINARY_DIR}/compile_commands.json") - EXECUTE_PROCESS( COMMAND ${CMAKE_COMMAND} -E copy_if_different + EXECUTE_PROCESS(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/compile_commands.json ${CMAKE_SOURCE_DIR}/compile_commands.json ) -ENDIF() +ENDIF() \ No newline at end of file From 5290028307270355d4a901a111b1fcb3820c6e7e Mon Sep 17 00:00:00 2001 From: Eduardo Menges Mattje Date: Thu, 6 Jun 2024 09:17:48 -0300 Subject: [PATCH 5/5] Added install procedure in CMake --- CMakeLists.txt | 57 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a282691b..d87107cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ 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) +option(ENABLE_INSTALL "Enable the installation of the library" "NOT IS_MAIN_FILE") include("cmake/HunterGate.cmake") include("cmake/Catch.cmake") @@ -26,6 +27,32 @@ project(SQLiteModernCpp LANGUAGES CXX) hunter_add_package(sqlite3) find_package(sqlite3 CONFIG REQUIRED) +add_library(SQLiteModernCpp INTERFACE) + +target_include_directories(SQLiteModernCpp INTERFACE + $ +) + +include(GNUInstallDirs) + +if(ENABLE_INSTALL) + install( + TARGETS SQLiteModernCpp + EXPORT SQLiteModernCppConfig + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + ) + + install( + EXPORT SQLiteModernCppConfig + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/SQLiteModernCpp" + NAMESPACE SQLiteModernCpp:: + ) + + install( + DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/hdr/ + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + ) +endif() if(BUILD_TESTING) hunter_add_package(Catch) @@ -34,22 +61,22 @@ if(BUILD_TESTING) 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) + IF(NOT ENABLE_SQLCIPHER_TESTS) + list(REMOVE_ITEM TEST_SOURCES ${TEST_SOURCE_DIR}/sqlcipher.cc) + ENDIF(NOT ENABLE_SQLCIPHER_TESTS) -enable_testing() + enable_testing() -add_executable(tests_runner ${TEST_SOURCES}) -target_include_directories(tests_runner INTERFACE ${SQLITE3_INCLUDE_DIRS}) + 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() + 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) + catch_discover_tests(tests_runner) target_compile_options(tests_runner PUBLIC $<$:/Zc:__cplusplus>) endif() @@ -58,7 +85,7 @@ endif() # 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 - ) + ${CMAKE_BINARY_DIR}/compile_commands.json + ${CMAKE_SOURCE_DIR}/compile_commands.json + ) ENDIF() \ No newline at end of file