-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from FlyingOE/release200
revamp kdb+ plugin's build with vcpkg on Windows
- Loading branch information
Showing
7 changed files
with
897 additions
and
580 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,116 @@ | ||
cmake_minimum_required(VERSION 3.0) | ||
project(PluginKDB) | ||
add_definitions(-DLOCKFREE_SYMBASE) | ||
cmake_minimum_required(VERSION 3.1) | ||
|
||
set(CMAKE_CXX_STANDARD 11) | ||
#======================================== | ||
if("${CMAKE_BUILD_TYPE}" MATCHES "") | ||
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "") | ||
endif () | ||
message(STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE}) | ||
|
||
if (WIN32) | ||
add_definitions("-DWINDOWS -D_WIN32_WINNT=0x0600 -DWINVER=0x0600") | ||
set(plugin_file "${CMAKE_CURRENT_LIST_DIR}/PluginKDB_WIN32.txt") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${platform_macro} -DKXVER=3 -Wall") | ||
file(COPY ${PROJECT_SOURCE_DIR}/lib/w64/c.dll DESTINATION ${CMAKE_BINARY_DIR}/) | ||
elseif(UNIX) | ||
set(platform_macro "-DLINUX") | ||
set(plugin_file "${CMAKE_CURRENT_LIST_DIR}/PluginKDB.txt") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${platform_macro} -DKXVER=3 -Wall -fPIC") | ||
#=== vcpkg | ||
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) | ||
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "") | ||
endif() | ||
|
||
if("${CMAKE_BUILD_TYPE}" STREQUAL "") | ||
set(CMAKE_BUILD_TYPE "RELEASE") | ||
endif () | ||
if(NOT DEFINED VCPKG_TARGET_TRIPLET) | ||
set(VCPKG_TARGET_TRIPLET x64-windows) # Use x64-windows by default | ||
endif() | ||
message(STATUS "VCPKG_TARGET_TRIPLET: " ${VCPKG_TARGET_TRIPLET}) | ||
|
||
string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE) | ||
message("CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE}) | ||
#======================================== | ||
project(PluginKDB LANGUAGES CXX) | ||
|
||
if("${CMAKE_BUILD_TYPE}" STREQUAL "DEBUG") | ||
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0") | ||
elseif("${CMAKE_BUILD_TYPE}" STREQUAL "RELEASE") | ||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3") | ||
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "RELWITHDEBINFO") # release with debug info | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O2") | ||
else () | ||
#=== Source Code | ||
file(GLOB PluginKDB_HEADER CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/src/*.h ) | ||
file(GLOB PluginKDB_SOURCE CONFIGURE_DEPENDS ${PROJECT_SOURCE_DIR}/src/*.cpp) | ||
|
||
#=== Build Target | ||
add_library(PluginKDB SHARED) | ||
set_property(TARGET PluginKDB PROPERTY CXX_STANDARD 11) | ||
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 () | ||
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") | ||
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" | ||
"${PROJECT_BINARY_DIR}/zlib${dep_debug_tag}1.dll" COPYONLY) | ||
set(extra_bin | ||
"${PROJECT_SOURCE_DIR}/lib/w64/c.dll" | ||
"${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 ) | ||
else() | ||
message(FATAL_ERROR "FIXME: Add build support for this platform!") | ||
endif() | ||
target_compile_definitions(PluginKDB PUBLIC ${platform_macro}) | ||
|
||
#=== ASAN or not? | ||
if (${DDB_USE_ASAN}) | ||
add_compile_options( | ||
"-fsanitize=address" # Enable ASAN. | ||
"-fno-omit-frame-pointer" # Nicer stack traces in error messages. | ||
"-fno-optimize-sibling-calls" # Disable tail call elimination (perfect stack traces if inlining off). | ||
) | ||
set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} "-fsanitize=address") | ||
endif () | ||
target_compile_options(PluginKDB PRIVATE | ||
-fsanitize=address # Enable ASAN. | ||
-fno-omit-frame-pointer # Nicer stack traces in error messages. | ||
-fno-optimize-sibling-calls # Disable tail call elimination (perfect stack traces if inlining off). | ||
) | ||
target_link_options(PluginKDB PRIVATE | ||
-fsanitize=address | ||
) | ||
endif() | ||
|
||
include_directories(${CMAKE_SOURCE_DIR}/../include) | ||
link_directories("${CMAKE_BINARY_DIR}") | ||
#=== Dependencies | ||
if(NOT DEFINED DOLPHINDB_ROOT) | ||
if(NOT DEFINED ENV{DOLPHINDB_ROOT}) | ||
message(FATAL_ERROR "DOLPHINDB_ROOT should be defined to provide path to DolphinDB installation!") | ||
else() | ||
set(DOLPHINDB_ROOT "$ENV{DOLPHINDB_ROOT}") | ||
endif() | ||
endif() | ||
target_compile_definitions(PluginKDB PUBLIC LOCKFREE_SYMBASE) | ||
target_include_directories(PluginKDB PUBLIC "${PROJECT_SOURCE_DIR}/../include") | ||
target_link_directories (PluginKDB PRIVATE "${DOLPHINDB_ROOT}") | ||
target_link_libraries (PluginKDB PRIVATE DolphinDB) | ||
|
||
aux_source_directory(${PROJECT_SOURCE_DIR}/src DIR_SRCS) | ||
add_library(PluginKDB SHARED ${DIR_SRCS}) | ||
#== zlib | ||
find_package(ZLIB REQUIRED) | ||
target_link_libraries(PluginKDB PRIVATE ZLIB::ZLIB) | ||
|
||
if (WIN32) | ||
target_link_libraries(PluginKDB DolphinDB ${PROJECT_SOURCE_DIR}/lib/w64/c.lib ${PROJECT_SOURCE_DIR}/lib/w64/c.dll z) | ||
elseif(UNIX) | ||
target_link_libraries(PluginKDB DolphinDB ${PROJECT_SOURCE_DIR}/lib/c.o z) | ||
endif() | ||
#== kdb+ | ||
target_compile_definitions(PluginKDB PUBLIC KXVER=3) | ||
target_link_directories (PluginKDB PUBLIC "${CMAKE_BINARY_DIR}") | ||
target_link_libraries (PluginKDB PRIVATE ${kdb_lib}) | ||
|
||
configure_file(${plugin_file} ${CMAKE_BINARY_DIR}/PluginKDB.txt COPYONLY) | ||
#=== Post-build Actions | ||
install(TARGETS PluginKDB | ||
RUNTIME DESTINATION "${PROJECT_SOURCE_DIR}/bin/${install_type}" | ||
) | ||
install(FILES | ||
"${PROJECT_BINARY_DIR}/PluginKDB.txt" ${extra_bin} | ||
DESTINATION "${PROJECT_SOURCE_DIR}/bin/${install_type}" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# kdb+ Plugin for DolphinDB using CMake & MinGW | ||
|
||
## Requirements | ||
|
||
### 1. MinGW-w64 | ||
|
||
https://www.mingw-w64.org/downloads/#mingw-builds | ||
|
||
- In order to be consistent with DolphinDB, it is recommended to use the `x86_64`/`win32`/`seh` build of MinGW-w64. | ||
|
||
- The following version of MinGW-w64 was considered: | ||
|
||
- The original kdb+ plugin on Windows was built with `x86_64-5.3.0-win32-seh-rt_v4-rev0.zip` | ||
|
||
### 2. CMake | ||
|
||
https://cmake.org/download/ | ||
|
||
Alternatively, the build-in CMake within Visual Studio can also be used. | ||
|
||
### 3. vcpkg | ||
|
||
https://vcpkg.io/en/getting-started | ||
|
||
A short version of how to install vcpkg: | ||
|
||
```batch | ||
git clone https://github.com/Microsoft/vcpkg.git | ||
.\vcpkg\bootstrap-vcpkg.bat | ||
SET VCPKG_ROOT=%CD%\vcpkg | ||
%VCPKG_ROOT%\vcpkg integrate install | ||
``` | ||
|
||
## Build Steps | ||
|
||
The follow commands assume that you are under the `DolphinDBPlugin\kdb\` directory. | ||
|
||
### 1. Install dependencies | ||
|
||
```batch | ||
%VCPKG_ROOT%\vcpkg install zlib:x64-windows | ||
``` | ||
|
||
```batch | ||
SET DOLPHINDB_ROOT=<path_to_DolphinDB> | ||
``` | ||
|
||
### 2. Build using CMake | ||
|
||
```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 -j 4 | ||
cmake --install build | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.