From f458c053c8f4a4a09a00d10d2ce0597d2b2cacdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Sat, 21 Dec 2024 04:42:16 +0900 Subject: [PATCH] build: use WinSQLite3 when possible --- CMakeLists.txt | 16 ++++++++++++++-- CMakePresets.json | 5 ++++- cmake/FindWinSQLite3.cmake | 14 ++++++++++++++ src/common/sqlite3_wrapper.h | 7 +++++++ src/infra/infra.cpp | 3 ++- src/main.cpp | 3 ++- 6 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 cmake/FindWinSQLite3.cmake create mode 100644 src/common/sqlite3_wrapper.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f82e934..67e0141 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,9 +2,15 @@ cmake_minimum_required(VERSION 3.10) project(kgg-dec VERSION 0.6.0 LANGUAGES CXX) +option(USE_WIN_SQLITE3 "Use Windows SQLite3 (MSVC Only)" ${MSVC}) + add_subdirectory(third-party/aes) add_subdirectory(third-party/md5) -add_subdirectory(third-party/sqlite3) +include(cmake/FindWinSQLite3.cmake) +if (NOT WinSQLite3_Found) + message("including sqlite3 to the build") + add_subdirectory(third-party/sqlite3) +endif () set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) @@ -27,6 +33,12 @@ target_include_directories(kgg-dec src/tc_tea ) -target_link_libraries(kgg-dec PRIVATE shell32 ole32 libaes libmd5 sqlite3) +target_link_libraries(kgg-dec PRIVATE shell32 ole32 libaes libmd5) +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}") diff --git a/CMakePresets.json b/CMakePresets.json index 0853876..7ab03a5 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -35,7 +35,10 @@ "description": "Configure for Visual Studio", "generator": "Visual Studio 17 2022", "binaryDir": "${sourceDir}/build/vs2022", - "architecture": "x64" + "architecture": "x64,version=10.0", + "toolset": { + "value": "v143" + } } ], "buildPresets": [ diff --git a/cmake/FindWinSQLite3.cmake b/cmake/FindWinSQLite3.cmake new file mode 100644 index 0000000..65a2c0f --- /dev/null +++ b/cmake/FindWinSQLite3.cmake @@ -0,0 +1,14 @@ +set(WinSQLite3_Found FALSE) + +if (MSVC AND USE_WIN_SQLITE3) + set(ProgramFiles_x86 "$ENV{ProgramFiles\(x86\)}") + file(GLOB WindowsKitLibs "${ProgramFiles_x86}/Windows Kits/10/Lib/10.0.*/um/${CMAKE_VS_PLATFORM_NAME}") + find_library(LibWinSQLite3 WinSQLite3 PATHS ${WindowsKitLibs}) + if (LibWinSQLite3) + set(WinSQLite3_Found TRUE) + get_filename_component(WindowsKitVersion "${LibWinSQLite3}/../../.." ABSOLUTE) + get_filename_component(WindowsKitVersion ${WindowsKitVersion} NAME) + set(WindowsKitInclude "${ProgramFiles_x86}/Windows Kits/10/Include/${WindowsKitVersion}/um") + message("Using WinSQLite3 from Windows SDK (${WindowsKitVersion}).") + endif () +endif () diff --git a/src/common/sqlite3_wrapper.h b/src/common/sqlite3_wrapper.h new file mode 100644 index 0000000..04b52b6 --- /dev/null +++ b/src/common/sqlite3_wrapper.h @@ -0,0 +1,7 @@ +#pragma once + +#if __has_include() +#include +#else +#include +#endif diff --git a/src/infra/infra.cpp b/src/infra/infra.cpp index 30d3aba..e6d0b4b 100644 --- a/src/infra/infra.cpp +++ b/src/infra/infra.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include @@ -11,6 +11,7 @@ #include namespace Infra { +using std::size_t; constexpr size_t kPageSize = 0x400; diff --git a/src/main.cpp b/src/main.cpp index c4a3ae4..c6d5d34 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,4 +1,5 @@ -#include +#include + #include "infra/infra.h" #include "jobs.hpp" #include "utils/cli.h"