diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b458638..6d1351f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -162,9 +162,6 @@ include_directories("${PROJECT_SOURCE_DIR}/include") # add sources of the wrapper as a "SQLiteCpp" static library add_library(SQLiteCpp ${SQLITECPP_SRC} ${SQLITECPP_INC} ${SQLITECPP_DOC} ${SQLITECPP_SCRIPT}) -# make the sqlite3 library part of the interface of the SQLiteCpp wrapper itself (the client app does not need to link to sqlite3) -# PR https://github.com/SRombauts/SQLiteCpp/pull/111 "linked SQLiteCpp to sqlite3" commented out since it breaks install step from PR #118 -#target_link_libraries(SQLiteCpp PUBLIC sqlite3) # Options relative to SQLite and SQLiteC++ functions @@ -206,12 +203,6 @@ install(EXPORT ${PROJECT_NAME}Config DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/$ ## Build provided copy of SQLite3 C library ## -# TODO -#find_package(sqlite3) -#if(sqlite3_VERSION VERSION_LESS "3.19") -# set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-DSQLITECPP_HAS_MEM_STRUCT") -#endif() - option(SQLITECPP_USE_ASAN "Use Address Sanitizer." OFF) if (SQLITECPP_USE_ASAN) if ((CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 6) OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")) @@ -230,8 +221,24 @@ if (SQLITECPP_INTERNAL_SQLITE) add_subdirectory(sqlite3) target_include_directories(sqlite3 PUBLIC "${PROJECT_SOURCE_DIR}/sqlite3") target_include_directories(SQLiteCpp PRIVATE "${PROJECT_SOURCE_DIR}/sqlite3") + target_link_libraries(SQLiteCpp PUBLIC sqlite3) +else (SQLITECPP_INTERNAL_SQLITE) + find_package(SQLite3 REQUIRED) + if(SQLite3_VERSION VERSION_LESS "3.19") + set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-DSQLITECPP_HAS_MEM_STRUCT") + endif() + # make the sqlite3 library part of the interface of the SQLiteCpp wrapper itself (the client app does not need to link to sqlite3) + # PR https://github.com/SRombauts/SQLiteCpp/pull/111 "linked SQLiteCpp to sqlite3" commented out since it breaks install step from PR #118 + target_link_libraries(SQLiteCpp PUBLIC SQLite::SQLite3) endif (SQLITECPP_INTERNAL_SQLITE) +# Link target with pthread and dl for Unix +if (UNIX) + set(THREADS_PREFER_PTHREAD_FLAG ON) + find_package(Threads REQUIRED) + target_link_libraries(SQLiteCpp PUBLIC Threads::Threads ${CMAKE_DL_LIBS}) +endif (UNIX) + # Optional additional targets: option(SQLITECPP_RUN_CPPLINT "Run cpplint.py tool for Google C++ StyleGuide." ON) @@ -285,16 +292,10 @@ option(SQLITECPP_BUILD_EXAMPLES "Build examples." OFF) if (SQLITECPP_BUILD_EXAMPLES) # add the basic example executable add_executable(SQLiteCpp_example1 ${SQLITECPP_EXAMPLES}) - target_link_libraries(SQLiteCpp_example1 SQLiteCpp sqlite3) - # Link target with pthread and dl for linux - if (UNIX) - target_link_libraries(SQLiteCpp_example1 pthread) - if (NOT APPLE) - target_link_libraries(SQLiteCpp_example1 dl) - endif () - elseif (MSYS OR MINGW) + target_link_libraries(SQLiteCpp_example1 SQLiteCpp) + if (MSYS OR MINGW) target_link_libraries(SQLiteCpp_example1 ssp) - endif () + endif (MSYS OR MINGW) else (SQLITECPP_BUILD_EXAMPLES) message(STATUS "SQLITECPP_BUILD_EXAMPLES OFF") endif (SQLITECPP_BUILD_EXAMPLES) @@ -306,7 +307,7 @@ if (SQLITECPP_BUILD_TESTS) find_package(GTest) if (GTEST_FOUND) - target_link_libraries(SQLiteCpp_tests GTest::GTest GTest::Main SQLiteCpp sqlite3) + target_link_libraries(SQLiteCpp_tests GTest::GTest GTest::Main SQLiteCpp) else (GTEST_FOUND) # deactivate some warnings for compiling the gtest library if (NOT MSVC) @@ -330,14 +331,9 @@ if (SQLITECPP_BUILD_TESTS) endif (MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS_EQUAL 1919) endif (MSVC) - target_link_libraries(SQLiteCpp_tests gtest_main SQLiteCpp sqlite3) + target_link_libraries(SQLiteCpp_tests gtest_main SQLiteCpp) endif (GTEST_FOUND) - # Link target with dl for linux - if (UNIX AND NOT APPLE) - target_link_libraries(SQLiteCpp_tests dl) - endif () - # add a "test" target: enable_testing()