Skip to content

Commit

Permalink
Added support for external sqlite3
Browse files Browse the repository at this point in the history
  • Loading branch information
emmenlau committed Dec 14, 2019
1 parent 8329e7a commit 07a0c0a
Showing 1 changed file with 21 additions and 25 deletions.
46 changes: 21 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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"))
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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()

Expand Down

0 comments on commit 07a0c0a

Please sign in to comment.