-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
162 lines (127 loc) · 5.86 KB
/
CMakeLists.txt
File metadata and controls
162 lines (127 loc) · 5.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
cmake_minimum_required(VERSION 3.10)
if(DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Choose the type of build, options are: Debug, Release, RelWithDebInfo")
else()
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: Debug, Release, RelWithDebInfo")
endif()
set(CMAKE_CONFIGURATION_TYPES Debug RelWithDebInfo Release CACHE STRING INTERNAL)
set(ARCH native CACHE STRING "CPU to build for: -march value or native")
message(STATUS "Building for target architecture: ${ARCH}")
set(LIB_MAJOR_VERSION "2")
set(LIB_MINOR_VERSION "0")
set(LIB_PATCH_VERSION "0")
set(LIB_VERSION_STRING "${LIB_MAJOR_VERSION}.${LIB_MINOR_VERSION}.${LIB_PATCH_VERSION}")
project(lmdbcpp VERSION "${LIB_VERSION_STRING}" LANGUAGES CXX)
if(NOT MSVC)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
message(STATUS "Found ccache package... Activating...")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif()
endif()
## This section describes our general CMake setup options
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_SKIP_INSTALL_RULES OFF FORCE)
set(CMAKE_SKIP_PACKAGE_ALL_DEPENDENCY ON FORCE)
set(CMAKE_SUPPRESS_REGENERATION ON)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
# Enable c++17
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
## We only build static binaries -- this is left here for our dependencies
set(STATIC ON CACHE BOOL FORCE "Link libraries statically? Forced to ON")
add_definitions(-DSTATICLIB)
option(STATIC_LIBC "Build with static libc" OFF)
if(DEFINED ENV{STATIC_LIBC})
set(STATIC_LIBC $ENV{STATIC_LIBC})
endif()
if(STATIC_LIBC)
message(STATUS "Forcing build with statically linked libc, binaries may not be portable")
endif()
option(BUILD_TESTS "Build included tests" OFF)
if(DEFINED ENV{BUILD_TESTS})
set(BUILD_TESTS $ENV{BUILD_TESTS})
endif()
if(BUILD_TESTS)
message(STATUS "Tests added to targets list")
endif()
if(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /D_CRT_SECURE_NO_WARNINGS")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std:c++17 /wd4267 /wd4804 /wd4996 /D_DLL /D_CRT_SECURE_NO_WARNINGS")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /O2")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2")
# Warning flags applied only to our targets (not externals)
set(LMDBCPP_COMPILE_OPTIONS /W4)
set(LMDBCPP_COMPILE_OPTIONS_RELEASE)
else()
if("${ARCH}" STREQUAL "default")
set(ARCH_FLAG "")
else()
set(ARCH_FLAG "-march=${ARCH}")
endif()
if (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "aarch64" OR "${LABEL}" STREQUAL "aarch64")
set(MAES_FLAG "")
set(CRYPTOPP_AARCH64 ON CACHE BOOL FORCE "Tell CryptoPP that we are building for aarch64")
elseif (${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" AND NOT "${LABEL}" STREQUAL "aarch64")
set(MAES_FLAG "-maes")
else ()
set(MAES_FLAG "")
endif ()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11 ${MAES_FLAG}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 ${MAES_FLAG}")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g3 -Og")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g3 -Og")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG -O3")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG -O3")
# Warning and hardening flags applied only to our targets (not externals)
set(LMDBCPP_COMPILE_OPTIONS -Wall -Wextra -Wpedantic -Wuninitialized)
set(LMDBCPP_COMPILE_OPTIONS_RELEASE -fstack-protector-strong -D_FORTIFY_SOURCE=2)
if(APPLE)
if(CMAKE_C_COMPILER_ID STREQUAL "GNU")
# Need to build against libc++ instead of libstc++ on apple
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdinc++ -I/usr/local/opt/llvm/include/c++/v1 -nodefaultlibs -lc++ -lc++abi -lm -lc -lgcc -lgcc_eh")
# Need these flags so gcc OSX works on the cryptopp ASM - https://groups.google.com/forum/#!topic/cryptopp-users/po8yO-vYaac
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCRYPTOPP_CLANG_INTEGRATED_ASSEMBLER=1")
elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
# Need to link against the llvm libc++ library, default is too old for std::filesystem
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -I/usr/local/opt/llvm/include/c++/v1")
endif()
endif()
if(MINGW OR STATIC_LIBC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static -static-libstdc++")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static")
endif()
if(NOT APPLE)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
endif()
endif()
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external)
set(INCLUDE_DIRECTORIES
${CMAKE_CURRENT_SOURCE_DIR}/include
)
include_directories(${INCLUDE_DIRECTORIES})
set(SOURCES
src/lmdb_errors.cpp
src/lmdb_cpp.cpp
)
add_library(lmdbcpp-static STATIC ${SOURCES})
target_link_libraries(lmdbcpp-static lmdbcpp-thirdparty)
target_include_directories(lmdbcpp-static PUBLIC ${INCLUDE_DIRECTORIES})
target_compile_options(lmdbcpp-static PRIVATE ${LMDBCPP_COMPILE_OPTIONS})
target_compile_options(lmdbcpp-static PRIVATE $<$<CONFIG:Release>:${LMDBCPP_COMPILE_OPTIONS_RELEASE}>)
if(WIN32)
target_link_libraries(lmdbcpp-static ws2_32 advapi32 crypt32 gdi32 user32)
endif()
if(BUILD_TESTS)
enable_testing()
set(TEST_SOURCES
tests/db_test.cpp
)
add_executable(lmdb-tests ${TEST_SOURCES})
target_link_libraries(lmdb-tests lmdbcpp-static)
target_compile_options(lmdb-tests PRIVATE ${LMDBCPP_COMPILE_OPTIONS})
target_compile_options(lmdb-tests PRIVATE $<$<CONFIG:Release>:${LMDBCPP_COMPILE_OPTIONS_RELEASE}>)
add_test(NAME lmdb-tests COMMAND lmdb-tests)
endif()