1
1
# Defines BitShares library target.
2
- project ( BitShares )
3
- cmake_minimum_required ( VERSION 3.1 )
2
+ cmake_minimum_required ( VERSION 3.2 FATAL_ERROR )
3
+ project ( BitShares LANGUAGES CXX C )
4
4
5
5
set ( BLOCKCHAIN_NAME "BitShares" )
6
6
@@ -11,7 +11,13 @@ set( INSTALLER_APP_ID "68ad7005-8eee-49c9-95ce-9eed97e5b347" )
11
11
12
12
set ( CMAKE_CXX_STANDARD 14 )
13
13
set ( CMAKE_CXX_STANDARD_REQUIRED ON )
14
- set ( CMAKE_CXX_EXTENSIONS OFF )
14
+
15
+ if ( "${CMAKE_CXX_COMPILER_ID} " STREQUAL "GNU" OR
16
+ "${CMAKE_CXX_COMPILER_ID} " STREQUAL "Clang" )
17
+ set ( CMAKE_CXX_EXTENSIONS ON ) # for __int128 support
18
+ else ()
19
+ set ( CMAKE_CXX_EXTENSIONS OFF )
20
+ endif ()
15
21
16
22
# http://stackoverflow.com/a/18369825
17
23
if ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "GNU" )
@@ -22,25 +28,137 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
22
28
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.3)
23
29
message (FATAL_ERROR "Clang version must be at least 3.3!" )
24
30
endif ()
31
+ elseif ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "MSVC" )
32
+ if ("${CMAKE_CXX_COMPILER_VERSION} " VERSION_LESS "19.0" )
33
+ message (FATAL_ERROR "MSVC version must be at least 19.0 (Visual Studio 2015 Update 1)!" )
34
+ endif ()
35
+
36
+ # allow MSVC VS2015 with Update 1, other 2015 versions are not supported
37
+ if ("${CMAKE_CXX_COMPILER_VERSION} " VERSION_EQUAL "19.0" )
38
+ if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL "19.0.23506.0" )
39
+ message (FATAL_ERROR "Your version ${CMAKE_CXX_COMPILER_VERSION} of MSVC is not supported, use version 19.0.23506.0 (Visual Studio 2015 Update 1)!" )
40
+ endif ()
41
+ endif ()
25
42
endif ()
26
43
27
44
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /CMakeModules" )
28
45
29
- set (CMAKE_EXPORT_COMPILE_COMMANDS "ON" )
30
- set (GRAPHENE_EGENESIS_JSON "${CMAKE_CURRENT_SOURCE_DIR} /libraries/egenesis/genesis.json" )
46
+ include (CheckCCompilerFlag)
47
+ include (Utils)
48
+
49
+ # function to help with cUrl
50
+ macro (FIND_CURL)
51
+ if (NOT WIN32 AND NOT APPLE AND CURL_STATICLIB)
52
+ find_package (OpenSSL REQUIRED)
53
+ set (OLD_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} )
54
+ set (CMAKE_FIND_LIBRARY_SUFFIXES .a)
55
+ find_package (CURL REQUIRED)
56
+ list (APPEND CURL_LIBRARIES ${OPENSSL_LIBRARIES} ${BOOST_THREAD_LIBRARY} ${CMAKE_DL_LIBS} )
57
+ set (CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_SUFFIXES} )
58
+ else (NOT WIN32 AND NOT APPLE AND CURL_STATICLIB)
59
+ find_package (CURL REQUIRED)
60
+ endif (NOT WIN32 AND NOT APPLE AND CURL_STATICLIB)
61
+
62
+ if ( WIN32 )
63
+ if ( MSVC )
64
+ list ( APPEND CURL_LIBRARIES Wldap32 )
65
+ endif ( MSVC )
66
+
67
+ if ( MINGW )
68
+ # MinGW requires a specific order of included libraries ( CURL before ZLib )
69
+ find_package ( ZLIB REQUIRED )
70
+ list ( APPEND CURL_LIBRARIES ${ZLIB_LIBRARY} pthread )
71
+ endif ( MINGW )
72
+
73
+ list ( APPEND CURL_LIBRARIES ${PLATFORM_SPECIFIC_LIBS} )
74
+ endif ( WIN32 )
75
+ endmacro ()
76
+
77
+ # Save the old value of CMAKE_REQUIRED_FLAGS
78
+ set ( TEMP_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} )
79
+
80
+ # Fortify source
81
+ if (CMAKE_COMPILER_IS_GNUCXX)
82
+ if ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "Clang" )
83
+ message (STATUS "Setting optimizations for clang++" )
84
+ set (CMAKE_CXX_FLAGS_RELEASE "-D_FORTIFY_SOURCE=2 -O3 -DNDEBUG=1" )
85
+ set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-D_FORTIFY_SOURCE=2 -O3 -DNDEBUG=1 -g" )
86
+
87
+ # check and add data execution prevention
88
+ message (STATUS "Enabling data execution prevention" )
89
+ add_linker_flag("-fsanitize=safe-stack" )
90
+
91
+ # check and add Stack-based buffer overrun detection
92
+ set (CMAKE_REQUIRED_FLAGS "-fstack-protector" )
93
+ check_c_compiler_flag("" HAVE_STACKPROTECTOR)
94
+ if (HAVE_STACKPROTECTOR)
95
+ message (STATUS "Enabling stack-based buffer overrun detection" )
96
+ add_flag_append(CMAKE_C_FLAGS "-fstack-protector" )
97
+ add_flag_append(CMAKE_CXX_FLAGS "-fstack-protector" )
98
+ endif ()
99
+ else ()
100
+ message (STATUS "Setting optimizations for g++" )
101
+ set (CMAKE_CXX_FLAGS_RELEASE "-D_FORTIFY_SOURCE=2 -O3 -DNDEBUG=1" )
102
+ set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-D_FORTIFY_SOURCE=2 -O3 -DNDEBUG=1 -g" )
103
+
104
+ # check and add data execution prevention
105
+ set (CMAKE_REQUIRED_FLAGS "-Wl,-znoexecstack" )
106
+ check_c_compiler_flag("" HAVE_NOEXECSTACK)
107
+ if (HAVE_NOEXECSTACK)
108
+ message (STATUS "Enabling data execution prevention" )
109
+ add_linker_flag("-znoexecstack" )
110
+ endif ()
111
+
112
+ # check and add Stack-based buffer overrun detection
113
+ set (CMAKE_REQUIRED_FLAGS "-fstack-protector-strong" )
114
+ check_c_compiler_flag("" HAVE_STACKPROTECTOR)
115
+ if (HAVE_STACKPROTECTOR)
116
+ message (STATUS "Enabling stack-based buffer overrun detection" )
117
+ add_flag_append(CMAKE_C_FLAGS "-fstack-protector-strong" )
118
+ add_flag_append(CMAKE_CXX_FLAGS "-fstack-protector-strong" )
119
+ endif ()
120
+
121
+ endif ()
122
+ endif ()
123
+
124
+ # check for Data relocation and Protection (RELRO)
125
+ set (CMAKE_REQUIRED_FLAGS "-Wl,-zrelro,-znow" )
126
+ check_c_compiler_flag("" HAVE_RELROFULL)
127
+ if (HAVE_RELROFULL)
128
+ message (STATUS "Enabling full data relocation and protection" )
129
+ add_linker_flag("-zrelro" )
130
+ add_linker_flag("-znow" )
131
+ else ()
132
+ #if full relro is not available, try partial relro
133
+ set (CMAKE_REQUIRED_FLAGS "-Wl,-zrelro" )
134
+ check_c_compiler_flag("" HAVE_RELROPARTIAL)
135
+ if (HAVE_RELROPARTIAL)
136
+ message (STATUS "Enabling partial data relocation and protection" )
137
+ add_linker_flag("-zrelro" )
138
+ endif ()
139
+ endif ()
140
+
141
+ set (CMAKE_REQUIRED_FLAGS ${TEMP_REQUIRED_FLAGS} )
142
+
143
+ # position independent executetable (PIE)
144
+ # position independent code (PIC)
145
+ if (NOT MSVC )
146
+ add_definitions (-fPIC)
147
+ endif (NOT MSVC )
31
148
32
- #set (ENABLE_INSTALLER 1)
33
- #set (USE_PCH 1)
149
+ set (CMAKE_EXPORT_COMPILE_COMMANDS "ON" )
150
+ set ( GRAPHENE_EGENESIS_JSON "${CMAKE_CURRENT_SOURCE_DIR} /libraries/egenesis/genesis.json"
151
+ CACHE STRING "Path to embedded genesis file" )
34
152
35
153
if (USE_PCH)
36
154
include (cotire)
37
155
endif (USE_PCH)
38
156
39
157
option (USE_PROFILER "Build with GPROF support(Linux)." OFF )
40
158
41
- IF ( NOT WIN32 )
42
- list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /libraries/fc/CMakeModules" )
43
- ENDIF ( NOT WIN32 )
159
+ # Use Boost config file from fc
160
+ set (Boost_DIR "${CMAKE_CURRENT_SOURCE_DIR} /libraries/fc/CMakeModules/Boost" )
161
+
44
162
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /libraries/fc/GitVersionGen" )
45
163
include ( GetGitRevisionDescription )
46
164
get_git_head_revision( GIT_REFSPEC GIT_SHA2 )
@@ -54,38 +172,60 @@ LIST(APPEND BOOST_COMPONENTS thread
54
172
program_options
55
173
chrono
56
174
unit_test_framework
57
- context)
175
+ context
176
+ coroutine
177
+ regex )
58
178
# boost::endian is also required, but FindBoost can't handle header-only libs
59
179
SET ( Boost_USE_STATIC_LIBS ON CACHE STRING "ON or OFF" )
60
180
61
- IF ( WIN32 )
62
- SET (BOOST_ROOT $ENV{BOOST_ROOT} )
181
+ IF (WIN32 )
182
+ if ($ENV{BOOST_ROOT} )
183
+ SET (BOOST_ROOT $ENV{BOOST_ROOT} )
184
+ endif ($ENV{BOOST_ROOT} )
63
185
set (Boost_USE_MULTITHREADED ON )
64
186
set (BOOST_ALL_DYN_LINK OFF ) # force dynamic linking for all libraries
187
+ add_definitions ("-DCURL_STATICLIB" )
188
+ list (APPEND PLATFORM_SPECIFIC_LIBS ws2_32 crypt32 mswsock userenv )
189
+ ELSE ( WIN32 )
190
+ IF ( APPLE )
191
+ set ( CMAKE_THREAD_LIBS_INIT "-lpthread" )
192
+ set ( CMAKE_HAVE_THREADS_LIBRARY 1 )
193
+ set ( CMAKE_USE_WIN32_THREADS_INIT 0 )
194
+ set ( CMAKE_USE_PTHREADS_INIT 1 )
195
+ set ( THREADS_PREFER_PTHREAD_FLAG ON )
196
+ ENDIF ( APPLE )
65
197
ENDIF (WIN32 )
66
198
67
- FIND_PACKAGE (Boost 1.57 REQUIRED COMPONENTS ${BOOST_COMPONENTS} )
68
- # For Boost 1.53 on windows, coroutine was not in BOOST_LIBRARYDIR and do not need it to build, but if boost versin >= 1.54, find coroutine otherwise will cause link errors
69
- IF (NOT "${Boost_VERSION} " MATCHES "1.53(.*)" )
70
- SET (BOOST_LIBRARIES_TEMP ${Boost_LIBRARIES} )
71
- FIND_PACKAGE (Boost 1.54 REQUIRED COMPONENTS coroutine)
72
- LIST (APPEND BOOST_COMPONENTS coroutine)
73
- SET (Boost_LIBRARIES ${BOOST_LIBRARIES_TEMP} ${Boost_LIBRARIES} )
74
- ENDIF ()
199
+ FIND_PACKAGE (Boost CONFIG REQUIRED COMPONENTS ${BOOST_COMPONENTS} )
200
+
201
+ # enforce more strict compiler warnings and errors
202
+ add_compiler_flag_if_available("-Wall" )
203
+ add_compiler_flag_if_available("-Wclobbered" )
204
+ add_compiler_flag_if_available("-Wempty-body" )
205
+ add_compiler_flag_if_available("-Wformat-security" )
206
+ add_compiler_flag_if_available("-Wignored-qualifiers" )
207
+ add_compiler_flag_if_available("-Wimplicit-fallthrough=5" )
208
+ add_compiler_flag_if_available("-Wmissing-field-initializers" )
209
+ add_compiler_flag_if_available("-Wpointer-arith" )
210
+ add_compiler_flag_if_available("-Wshift-negative-value" )
211
+ add_compiler_flag_if_available("-Wtype-limits" )
212
+ add_compiler_flag_if_available("-Wunused-but-set-parameter" )
75
213
76
214
if ( WIN32 )
77
215
78
216
message ( STATUS "Configuring BitShares on WIN32" )
79
- set ( DB_VERSION 60 )
80
- set ( BDB_STATIC_LIBS 1 )
81
217
82
- set ( ZLIB_LIBRARIES "" )
83
- SET ( DEFAULT_EXECUTABLE_INSTALL_DIR bin/ )
218
+ if ( MINGW )
219
+ message ( STATUS "Windows build using MinGW" )
220
+ set ( FULL_STATIC_BUILD TRUE )
221
+ else ( MINGW )
222
+ set ( ZLIB_LIBRARIES "" )
223
+ endif ( MINGW )
84
224
85
- set (CRYPTO_LIB )
225
+ SET ( DEFAULT_EXECUTABLE_INSTALL_DIR bin/ )
86
226
87
227
if ( MSVC )
88
- add_definitions (-DWIN32_LEAN_AND_MEAN)
228
+ add_definitions (-DWIN32_LEAN_AND_MEAN)
89
229
#looks like this flag can have different default on some machines.
90
230
SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO" )
91
231
SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO" )
@@ -94,44 +234,32 @@ if( WIN32 )
94
234
set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /DEBUG" )
95
235
endif ( MSVC )
96
236
97
- # On windows tcl should be installed to the directory pointed by setenv.bat script
98
- SET (TCL_INCLUDE_PATH $ENV{TCL_ROOT} /include )
99
- MESSAGE (STATUS "tcl INCLUDE PATH: ${TCL_INCLUDE_PATH} " )
100
-
101
- FIND_PACKAGE (TCL)
102
- MESSAGE (STATUS "tcl_library: ${TCL_LIBRARY} " )
103
-
104
- SET (TCL_LIBS "optimized;${TCL_LIBRARY} ;debug;" )
105
- get_filename_component (TCL_LIB_PATH "${TCL_LIBRARY} " PATH )
106
- get_filename_component (TCL_LIB_NAME "${TCL_LIBRARY} " NAME_WE )
107
- get_filename_component (TCL_LIB_EXT "${TCL_LIBRARY} " EXT )
108
-
109
- SET (TCL_LIBS "${TCL_LIBS}${TCL_LIB_PATH} /${TCL_LIB_NAME} g${TCL_LIB_EXT} " )
110
- SET (TCL_LIBRARY ${TCL_LIBS} )
111
-
112
237
else ( WIN32 ) # Apple AND Linux
113
238
114
239
if ( APPLE )
115
240
# Apple Specific Options Here
116
241
message ( STATUS "Configuring BitShares on OS X" )
117
242
set ( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -stdlib=libc++ -Wall" )
118
243
else ( APPLE )
119
- # Linux Specific Options Here
120
- message ( STATUS "Configuring BitShares on Linux" )
244
+ if ( "${CMAKE_SYSTEM_NAME} " STREQUAL "OpenBSD" )
245
+ # OpenBSD Specific Options
246
+ message ( STATUS "Configuring BitShares on OpenBSD" )
247
+ else ()
248
+ # Linux Specific Options Here
249
+ message ( STATUS "Configuring BitShares on Linux" )
250
+ set ( rt_library rt )
251
+ endif ()
252
+ # Common Linux & OpenBSD Options
121
253
set ( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -Wall" )
122
254
if (USE_PROFILER)
123
255
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg" )
124
256
endif ( USE_PROFILER )
125
- set ( rt_library rt )
126
257
set ( pthread_library pthread)
127
258
if ( NOT DEFINED crypto_library )
128
259
# I'm not sure why this is here, I guess someone has openssl and can't detect it with find_package()?
129
260
# if you have a normal install, you can define crypto_library to the empty string to avoid a build error
130
261
set ( crypto_library crypto)
131
262
endif ()
132
- if ( FULL_STATIC_BUILD )
133
- set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc" )
134
- endif ( FULL_STATIC_BUILD )
135
263
endif ( APPLE )
136
264
137
265
if ( "${CMAKE_CXX_COMPILER_ID} " STREQUAL "GNU" )
@@ -154,6 +282,10 @@ else( WIN32 ) # Apple AND Linux
154
282
155
283
endif ( WIN32 )
156
284
285
+ if ( NOT MSVC AND FULL_STATIC_BUILD )
286
+ set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static -static-libstdc++ -static-libgcc" )
287
+ endif ( NOT MSVC AND FULL_STATIC_BUILD )
288
+
157
289
set (ENABLE_COVERAGE_TESTING FALSE CACHE BOOL "Build BitShares for code coverage analysis" )
158
290
159
291
if (ENABLE_COVERAGE_TESTING)
0 commit comments