1- cmake_minimum_required (VERSION 3.6 )
2- set (CMAKE_CXX_STANDARD 11)
1+ cmake_minimum_required (VERSION 3.13 )
2+
33project (DolphinDBAPI)
44
5- set (LINK_LIBS)
6- if (USE_OPENSSL)
7- add_definitions ("-DUSE_OPENSSL=1" )
8- if (OPENSSL_PATH)
9- set (ENV{OPENSSL_ROOT_DIR} ${OPENSSL_PATH} )
10- endif ()
5+ set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
6+ set (CMAKE_CXX_STANDARD 11)
7+ set (CMAKE_CXX_EXTENSIONS OFF )
8+
9+ option (USE_OPENSSL "Use OpenSSL for encrypted communication" ON )
10+ option (USE_AERON "Use Aeron for UDP connection" ON )
11+ option (USE_CXX11_ABI "Gcc Use C++11 ABI" ON )
12+
13+ add_library (${CMAKE_PROJECT_NAME} SHARED)
14+
15+ add_subdirectory (src)
16+
17+ if (USE_OPENSSL)
1118 find_package (OpenSSL REQUIRED)
12- list (APPEND LINK_LIBS ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY} )
13- include_directories (${OPENSSL_INCLUDE_DIR} )
14- message ("openssl include dir : ${OPENSSL_INCLUDE_DIR} " )
15- message ("openssl ssl lib dir : ${OPENSSL_SSL_LIBRARY} " )
16- message ("openssl crypto lib dir : ${OPENSSL_CRYPTO_LIBRARY} " )
19+ target_compile_definitions (${CMAKE_PROJECT_NAME} PRIVATE USE_OPENSSL)
1720endif ()
1821
19- if (UNIX )
20- add_definitions (-fPIC -DNDEBUG -DLINUX -O3 -Wall -fmessage-length =0 -std=gnu++11 -msse -msse2 -msse3 -funroll-loops)
21- if (ABI EQUAL 0)
22- message ("set _GLIBCXX_USE_CXX11_ABI to 0" )
23- add_definitions ("-D_GLIBCXX_USE_CXX11_ABI=0" )
24- elseif (ABI EQUAL 1)
25- message ("set _GLIBCXX_USE_CXX11_ABI to 1" )
26- add_definitions ("-D_GLIBCXX_USE_CXX11_ABI=1" )
27- endif ()
28- if (UUID_PATH)
29- include_directories (${UUID_PATH} /include )
30- link_directories (${UUID_PATH} /lib)
22+ if (USE_AERON)
23+ if (NOT DEFINED AERON_INSTALL_DIR)
24+ set (AERON_INSTALL_DIR "/usr/local" )
3125 endif ()
32- list (APPEND LINK_LIBS pthread uuid dl)
33- elseif (WIN32 )
34- if (MSVC )
35- message ("MSVC Compiling" )
36- add_definitions ("-DWINDOWS -DWIN32_LEAN_AND_MEAN -D_DDBAPIDLL -DNOMINMAX" )
37- set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MDd" )
38- set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd" )
39- elseif (MINGW)
40- message ("MINGW Compiling" )
41- add_definitions (-fPIC -DNDEBUG -O3 -Wall -fmessage-length =0 -std=gnu++11 -msse -msse2 -msse3 -funroll-loops)
42- add_definitions ("-DWINDOWS -D_WIN32_WINNT=0x0600" )
43- if (ABI EQUAL 0)
44- message ("set _GLIBCXX_USE_CXX11_ABI to 0" )
45- add_definitions ("-D_GLIBCXX_USE_CXX11_ABI=0" )
46- elseif (ABI EQUAL 1)
47- message ("set _GLIBCXX_USE_CXX11_ABI to 1" )
48- add_definitions ("-D_GLIBCXX_USE_CXX11_ABI=1" )
49- endif ()
50- endif ()
51- list (APPEND LINK_LIBS ws2_32)
26+ set (AERON_INCLUDE_DIR
27+ "${AERON_INSTALL_DIR} /include/wrapper"
28+ "${AERON_INSTALL_DIR} /include/aeron"
29+ "${AERON_INSTALL_DIR} /include"
30+ )
31+ target_link_directories (${CMAKE_PROJECT_NAME} PRIVATE ${AERON_INSTALL_DIR} /lib)
32+ set (AERON_LIBRARY
33+ aeron
34+ aeron_client_shared
35+ aeron_driver
36+ )
37+ target_compile_definitions (${CMAKE_PROJECT_NAME} PRIVATE USE_AERON)
5238endif ()
5339
54- AUX_SOURCE_DIRECTORY (src DIR_SRCS)
55- include_directories (include )
56- ADD_LIBRARY (DolphinDBAPI SHARED ${DIR_SRCS} )
57- target_link_libraries (
58- DolphinDBAPI
59- ${LINK_LIBS}
60- )
40+ if (NOT USE_CXX11_ABI)
41+ target_compile_definitions (${CMAKE_PROJECT_NAME} PRIVATE _GLIBCXX_USE_CXX11_ABI=0)
42+ endif ()
43+
44+ target_include_directories (${CMAKE_PROJECT_NAME}
45+ PRIVATE ${OPENSSL_INCLUDE_DIR}
46+ PRIVATE BEFORE ${AERON_INCLUDE_DIR} # make sure we include C warpper before deprecated C++ API
47+ )
48+ target_link_libraries (${CMAKE_PROJECT_NAME}
49+ PRIVATE ${OPENSSL_SSL_LIBRARY}
50+ PRIVATE ${OPENSSL_CRYPTO_LIBRARY}
51+ PRIVATE ${AERON_LIBRARY}
52+ )
53+
54+ if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
55+ target_compile_definitions (${CMAKE_PROJECT_NAME}
56+ PRIVATE WINDOWS NOMINMAX _DDBAPIDLL
57+ )
58+ # C4251: Class member of an exported class is not marked dllexport.
59+ # This is triggered by std::string but we cannot modify STL.
60+ # C4100: Parameter is unused. We should fix this later.
61+ target_compile_options (${CMAKE_PROJECT_NAME} PRIVATE /W3 /WX /MP /wd4251 /wd4100)
62+ target_link_libraries (${CMAKE_PROJECT_NAME} PRIVATE ws2_32)
63+ else ()
64+ target_compile_options (${CMAKE_PROJECT_NAME} PRIVATE -Wall -Werror)
65+ target_link_libraries (${CMAKE_PROJECT_NAME} PRIVATE pthread rt uuid)
66+ endif ()
67+
68+ if (USE_CXX11_ABI AND EXISTS "${PROJECT_SOURCE_DIR} /thirdparty/googletest/CMakeLists.txt" )
69+ add_executable (${CMAKE_PROJECT_NAME} _test)
70+ add_subdirectory (test )
71+
72+ if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
73+ target_compile_options (${CMAKE_PROJECT_NAME} _test PRIVATE /W0 /utf-8 /MP)
74+ target_compile_definitions (${CMAKE_PROJECT_NAME} _test PRIVATE WINDOWS NOMINMAX)
75+ else ()
76+ target_compile_options (${CMAKE_PROJECT_NAME} _test PRIVATE -w)
77+ endif ()
78+
79+ set (gtest_force_shared_crt ON CACHE BOOL "" FORCE)
80+ add_subdirectory ("${PROJECT_SOURCE_DIR} /thirdparty/googletest" )
81+
82+ enable_testing ()
83+
84+ target_link_libraries (${CMAKE_PROJECT_NAME} _test
85+ ${CMAKE_PROJECT_NAME}
86+ gtest_main
87+ gmock_main
88+ )
89+ else ()
90+ message ("skipping tests." )
91+ endif ()
0 commit comments