From c4a61c8813f1eac7a3d8a64c2a55127d2648d24c Mon Sep 17 00:00:00 2001 From: Freddie Wu Date: Mon, 21 Aug 2023 21:21:49 +0800 Subject: [PATCH] fixed #15 support for zlib Debug build --- kdb/CMakeLists.txt | 44 ++++++++++++++++++++++++---------------- kdb/CMake_mingw+vcpkg.md | 7 +++++++ 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/kdb/CMakeLists.txt b/kdb/CMakeLists.txt index 9a13a6c6..2fe2b33c 100644 --- a/kdb/CMakeLists.txt +++ b/kdb/CMakeLists.txt @@ -30,37 +30,45 @@ target_sources(PluginKDB PUBLIC ${PluginKDB_HEADER} PRIVATE ${PluginKDB_SOURCE}) target_compile_options(PluginKDB PRIVATE -Wall) #=== Build Types +if ("${CMAKE_BUILD_TYPE}" MATCHES Debug) + set(optimize_opts -g -O0) + set(dep_debug_tag "d") +elseif("${CMAKE_BUILD_TYPE}" MATCHES Release) + set(optimize_opts -O3 ) + set(dep_debug_tag "") +elseif("${CMAKE_BUILD_TYPE}" MATCHES RelWithDebInfo) + set(optimize_opts -g -O2) + set(dep_debug_tag "") +else() + message(FATAL_ERROR "Unknown build type: ${CMAKE_BUILD_TYPE}") +endif() + +target_compile_options(PluginKDB PRIVATE ${optimize_opts}) if(WIN32) set(platform_macro WINDOWS) set(install_type win) set(kdb_lib "${PROJECT_SOURCE_DIR}/lib/w64/c.lib") - set(extra_bin - "${PROJECT_SOURCE_DIR}/lib/w64/c.dll" + configure_file( + "${PROJECT_SOURCE_DIR}/PluginKDB_WIN32.txt" + "${PROJECT_BINARY_DIR}/PluginKDB.txt" COPYONLY) + #FIXME: CMake 3.21 offers better way to do this: install(IMPORTED_RUNTIME_ARTIFACTS ...) + configure_file( "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/bin/zlib1.dll" - ) #FIXME: CMake 3.21 offers better way to do this! - configure_file("${PROJECT_SOURCE_DIR}/PluginKDB_WIN32.txt" "${PROJECT_BINARY_DIR}/PluginKDB.txt" COPYONLY) + "${PROJECT_BINARY_DIR}/zlib${dep_debug_tag}1.dll" COPYONLY) + set(extra_bin "${PROJECT_BINARY_DIR}/zlib${dep_debug_tag}1.dll") elseif(UNIX) set(platform_macro LINUX) set(install_type linux) set(kdb_lib "${PROJECT_SOURCE_DIR}/lib/c.o") + configure_file( + "${PROJECT_SOURCE_DIR}/PluginKDB.txt" + "${PROJECT_BINARY_DIR}/PluginKDB.txt" COPYONLY) set(extra_bin ) - configure_file("${PROJECT_SOURCE_DIR}/PluginKDB.txt" "${PROJECT_BINARY_DIR}/PluginKDB.txt" COPYONLY) else() message(FATAL_ERROR "FIXME: Add build support for this platform!") endif() target_compile_definitions(PluginKDB PUBLIC ${platform_macro}) -if ("${CMAKE_BUILD_TYPE}" MATCHES Debug) - set(optimize_opts -g -O0) -elseif("${CMAKE_BUILD_TYPE}" MATCHES Release) - set(optimize_opts -O3 ) -elseif("${CMAKE_BUILD_TYPE}" MATCHES RelWithDebInfo) - set(optimize_opts -g -O2) -else() - message(FATAL_ERROR "Unknown build type: ${CMAKE_BUILD_TYPE}") -endif() -target_compile_options(PluginKDB PRIVATE ${optimize_opts}) - #=== ASAN or not? if (${DDB_USE_ASAN}) target_compile_options(PluginKDB PRIVATE @@ -88,7 +96,7 @@ target_link_libraries (PluginKDB PRIVATE DolphinDB) #== zlib find_package(ZLIB REQUIRED) -target_link_libraries (PluginKDB PRIVATE ZLIB::ZLIB) +target_link_libraries(PluginKDB PRIVATE ZLIB::ZLIB) #== kdb+ target_compile_definitions(PluginKDB PUBLIC KXVER=3) @@ -102,4 +110,4 @@ install(TARGETS PluginKDB install(FILES "${PROJECT_BINARY_DIR}/PluginKDB.txt" ${extra_bin} DESTINATION "${PROJECT_SOURCE_DIR}/bin/${install_type}" -) +) \ No newline at end of file diff --git a/kdb/CMake_mingw+vcpkg.md b/kdb/CMake_mingw+vcpkg.md index a2485007..a0acdf10 100644 --- a/kdb/CMake_mingw+vcpkg.md +++ b/kdb/CMake_mingw+vcpkg.md @@ -49,7 +49,14 @@ SET DOLPHINDB_ROOT= ```batch del /S /Q build + +:: Release mode cmake -S . -B build -G Ninja +:: Debug mode +cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Debug +:: RelWithDebInfo mode +cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=RelWithDebInfo + cmake --build build cmake --install build ```