diff --git a/CMakeLists.txt b/CMakeLists.txt index 997166b..f1b8ca3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,7 @@ OPTION(SQLITE_ENABLE_REGEXP "Enable extension 'regexp'" ON) OPTION(SQLITE_ENABLE_SERIES "Enable extension 'series'" ON) OPTION(SQLITE_ENABLE_SHA3 "Enable extension 'sha3'" ON) -# Options for shell only (compatibility with official SQLite shell +# Options for shell only (compatibility with official SQLite shell) OPTION(SQLITE_ENABLE_EXPLAIN_COMMENTS "Insert comment text into the output of EXPLAIN (shell only)" ON) OPTION(SQLITE_ENABLE_DBPAGE_VTAB "Enable the SQLITE_DBPAGE virtual table (shell only)" ON) OPTION(SQLITE_ENABLE_DBSTAT_VTAB "Enable the dbstat virtual table (shell only)" ON) @@ -209,6 +209,14 @@ endif() # Only generate Debug and Release configuration types. set(CMAKE_CONFIGURATION_TYPES Debug Release) +set(SQLITE3MC_PUBLIC_HEADERS + src/sqlite3.h + src/sqlite3ext.h + src/sqlite3mc.h + src/sqlite3mc_vfs.h + src/sqlite3userauth.h +) + set(SQLITE3MC_BASE_SRCS src/sqlite3mc.c src/cipher_common.h @@ -218,15 +226,10 @@ set(SQLITE3MC_BASE_SRCS src/rijndael.h src/sha1.h src/sha2.h - src/sqlite3.h - src/sqlite3ext.h - src/sqlite3mc.h - src/sqlite3mc_vfs.h - src/sqlite3userauth.h src/test_windirent.h + ${SQLITE3MC_PUBLIC_HEADERS} ) set(SQLITE3MC_DLLRES_SRCS - src/sqlite3mc.def src/sqlite3mc.rc ) set(SQLITE3MC_SHELL_SRCS @@ -260,11 +263,16 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Linux" dl m ) + if(CMAKE_SYSTEM_NAME STREQUAL "Darwin") + list(APPEND SQLITE3MC_LINK_LIBRARIES "-framework Security") + endif() + set(SHARED_LIB_EXPORT_DEFINITION "__attribute__((visibility(\"default\")))") else() if (CMAKE_C_COMPILER_ID STREQUAL "GNU") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse4.2 -maes") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2 -maes") endif() + set(SHARED_LIB_EXPORT_DEFINITION "__declspec(dllexport)") endif() set(_LIB_DIFINITIONS @@ -280,14 +288,15 @@ set(_DEFAULT_DEFINITIONS UNICODE ) -set(SQLITE3MC_TARGET "sqlite3mc") set(SQLITE3MC_SHELL_TARGET "sqlite3mc_shell") -set(SQLITE3MC_LINK "SHARED") - if(SQLITE3MC_STATIC) set(SQLITE3MC_LINK "STATIC") set(SQLITE3MC_TARGET "sqlite3mc_static") +else() + set(SQLITE3MC_LINK "SHARED") + set(SQLITE3MC_TARGET "sqlite3mc") + list(APPEND SQLITE3MC_BASE_SRCS ${SQLITE3MC_DLLRES_SRCS}) endif() # Lib Project @@ -308,6 +317,12 @@ target_link_libraries(${SQLITE3MC_TARGET} PRIVATE ${SQLITE3MC_LINK_LIBRARIES} ) +if(NOT SQLITE3MC_STATIC) + target_compile_definitions(${SQLITE3MC_TARGET} PRIVATE + SQLITE_API=${SHARED_LIB_EXPORT_DEFINITION} + ) +endif() + if(ZLIB_FOUND) target_include_directories(${SQLITE3MC_TARGET} PRIVATE ${ZLIB_INCLUDE_DIRS} @@ -337,6 +352,14 @@ if(SQLITE3MC_STATIC_RUNTIME_LINK) endif() message("Will build ${SQLITE3MC_TARGET} as ${SQLITE3MC_LINK}") +set_target_properties(${SQLITE3MC_TARGET} PROPERTIES PUBLIC_HEADER "${SQLITE3MC_PUBLIC_HEADERS}") +INSTALL(TARGETS ${SQLITE3MC_TARGET} + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + PUBLIC_HEADER DESTINATION include/${CMAKE_PROJECT_NAME} + RUNTIME DESTINATION bin +) + # Shell Executable project if(SQLITE3MC_BUILD_SHELL) add_executable(${SQLITE3MC_SHELL_TARGET} @@ -381,4 +404,11 @@ if(SQLITE3MC_BUILD_SHELL) _Enable_MT(${SQLIT3MC_SHELL_TARGET}) endif() message("Will build ${SQLITE3MC_SHELL_TARGET}") + + INSTALL(TARGETS ${SQLITE3MC_SHELL_TARGET} + ARCHIVE DESTINATION lib + LIBRARY DESTINATION lib + PUBLIC_HEADER DESTINATION include/${CMAKE_PROJECT_NAME} + RUNTIME DESTINATION bin + ) endif()