From 5ee2b2cb251b909f32228d07965f633c7997902e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Sun, 22 Dec 2024 00:38:37 +0900 Subject: [PATCH] build: use system sqlite3 if available --- CMakeLists.txt | 37 +++++++++++++++++++++++-------------- cmake/FindWinSQLite3.cmake | 7 +++++++ 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 636b911..97af605 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,16 @@ -cmake_minimum_required(VERSION 3.10) +cmake_minimum_required(VERSION 3.14) project(kgg-dec VERSION 0.6.0 LANGUAGES CXX) option(USE_WIN_SQLITE3 "Use Windows SQLite3 (MSVC Only)" ${MSVC}) option(USE_WIN_CRYPTO "Use Windows Crypto API" ${WIN32}) +option(USE_SYSTEM_SQLITE3 "Use system SQLite3 (if not using WinSQLite3)" ON) add_subdirectory(third-party/aes) add_subdirectory(third-party/md5) include(cmake/FindWinSQLite3.cmake) -if (NOT WinSQLite3_Found) +if (NOT WinSQLite3_Found AND NOT USE_WIN_SQLITE3) message("including sqlite3 to the build") add_subdirectory(third-party/sqlite3) endif () @@ -35,19 +36,27 @@ target_include_directories(kgg-dec src/tc_tea ) +# Base crypto implementations target_link_libraries(kgg-dec PRIVATE libaes libmd5) -if (WIN32) - target_link_libraries(kgg-dec PRIVATE shell32 ole32) -endif () -if (WinSQLite3_Found) - target_link_libraries(kgg-dec PRIVATE WinSQLite3) - target_include_directories(kgg-dec PRIVATE ${WindowsKitInclude}) -else () - target_link_libraries(kgg-dec PRIVATE sqlite3) -endif () -target_compile_definitions(kgg-dec PRIVATE NOMINMAX) -target_compile_definitions(kgg-dec PRIVATE KGGDEC_PROJECT_VERSION="${PROJECT_VERSION}") - if (USE_WIN_CRYPTO) target_compile_definitions(kgg-dec PRIVATE USE_WIN_CRYPTO=1) endif () + +# Win32 specific +if (WIN32) + target_link_libraries(kgg-dec PRIVATE shell32 ole32) + target_compile_definitions(kgg-dec PRIVATE NOMINMAX) +endif () + +# SQLite3 +if (WinSQLite3_Found) + target_link_libraries(kgg-dec PRIVATE WinSQLite3) + target_include_directories(kgg-dec PRIVATE ${WindowsKitInclude}) +elseif(SQLite3_FOUND) + target_link_libraries(kgg-dec PRIVATE SQLite::SQLite3) +else () + target_link_libraries(kgg-dec PRIVATE sqlite3) +endif () + +# Extra definitions +target_compile_definitions(kgg-dec PRIVATE KGGDEC_PROJECT_VERSION="${PROJECT_VERSION}") diff --git a/cmake/FindWinSQLite3.cmake b/cmake/FindWinSQLite3.cmake index 65a2c0f..9ee2d9e 100644 --- a/cmake/FindWinSQLite3.cmake +++ b/cmake/FindWinSQLite3.cmake @@ -12,3 +12,10 @@ if (MSVC AND USE_WIN_SQLITE3) message("Using WinSQLite3 from Windows SDK (${WindowsKitVersion}).") endif () endif () + +if (NOT WinSQLite3_Found AND USE_SYSTEM_SQLITE3) + find_package(SQLite3) + if (SQLite3_FOUND) + message("Using existing SQLite3.") + endif() +endif()