@@ -12,6 +12,7 @@ option(HUNTER_ENABLED "Enable Hunter package manager support" ON)
1212
1313set (IS_MAIN_FILE CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
1414option (BUILD_TESTING "Enable build of tests" IS_MAIN_FILE)
15+ option (ENABLE_INSTALL "Enable the installation of the library" "NOT IS_MAIN_FILE" )
1516
1617include ("cmake/HunterGate.cmake" )
1718include ("cmake/Catch.cmake" )
@@ -26,6 +27,32 @@ project(SQLiteModernCpp LANGUAGES CXX)
2627hunter_add_package(sqlite3)
2728find_package (sqlite3 CONFIG REQUIRED)
2829
30+ add_library (SQLiteModernCpp INTERFACE )
31+
32+ target_include_directories (SQLiteModernCpp INTERFACE
33+ $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR} /hdr>
34+ )
35+
36+ include (GNUInstallDirs)
37+
38+ if (ENABLE_INSTALL)
39+ install (
40+ TARGETS SQLiteModernCpp
41+ EXPORT SQLiteModernCppConfig
42+ INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
43+ )
44+
45+ install (
46+ EXPORT SQLiteModernCppConfig
47+ DESTINATION "${CMAKE_INSTALL_LIBDIR} /cmake/SQLiteModernCpp"
48+ NAMESPACE SQLiteModernCpp::
49+ )
50+
51+ install (
52+ DIRECTORY ${CMAKE_CURRENT_LIST_DIR} /hdr/
53+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
54+ )
55+ endif ()
2956
3057if (BUILD_TESTING)
3158 hunter_add_package(Catch)
@@ -34,22 +61,22 @@ if(BUILD_TESTING)
3461 set (TEST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR} /tests)
3562 file (GLOB TEST_SOURCES ${TEST_SOURCE_DIR} /*.cc)
3663
37- IF (NOT ENABLE_SQLCIPHER_TESTS)
38- list (REMOVE_ITEM TEST_SOURCES ${TEST_SOURCE_DIR} /sqlcipher.cc)
39- ENDIF (NOT ENABLE_SQLCIPHER_TESTS)
64+ IF (NOT ENABLE_SQLCIPHER_TESTS)
65+ list (REMOVE_ITEM TEST_SOURCES ${TEST_SOURCE_DIR} /sqlcipher.cc)
66+ ENDIF (NOT ENABLE_SQLCIPHER_TESTS)
4067
41- enable_testing ()
68+ enable_testing ()
4269
43- add_executable (tests_runner ${TEST_SOURCES} )
44- target_include_directories (tests_runner INTERFACE ${SQLITE3_INCLUDE_DIRS} )
70+ add_executable (tests_runner ${TEST_SOURCES} )
71+ target_include_directories (tests_runner INTERFACE ${SQLITE3_INCLUDE_DIRS} )
4572
46- if (ENABLE_SQLCIPHER_TESTS)
47- target_link_libraries (tests_runner Catch2::Catch2 sqlite_modern_cpp sqlite3::sqlite3 -lsqlcipher)
48- else ()
49- target_link_libraries (tests_runner Catch2::Catch2 sqlite_modern_cpp sqlite3::sqlite3)
50- endif ()
73+ if (ENABLE_SQLCIPHER_TESTS)
74+ target_link_libraries (tests_runner Catch2::Catch2 sqlite_modern_cpp sqlite3::sqlite3 -lsqlcipher)
75+ else ()
76+ target_link_libraries (tests_runner Catch2::Catch2 sqlite_modern_cpp sqlite3::sqlite3)
77+ endif ()
5178
52- catch_discover_tests(tests_runner)
79+ catch_discover_tests(tests_runner)
5380
5481 target_compile_options (tests_runner PUBLIC $<$<CXX_COMPILER_ID:MSVC >:/Zc:__cplusplus>)
5582endif ()
@@ -58,7 +85,7 @@ endif()
5885# YCM is the code-completion engine for (neo)vim https://github.com/Valloric/YouCompleteMe
5986IF (EXISTS "${CMAKE_BINARY_DIR} /compile_commands.json" )
6087 EXECUTE_PROCESS (COMMAND ${CMAKE_COMMAND} -E copy_if_different
61- ${CMAKE_BINARY_DIR} /compile_commands.json
62- ${CMAKE_SOURCE_DIR} /compile_commands.json
63- )
88+ ${CMAKE_BINARY_DIR} /compile_commands.json
89+ ${CMAKE_SOURCE_DIR} /compile_commands.json
90+ )
6491ENDIF ()
0 commit comments