@@ -28,6 +28,17 @@ elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
28
28
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.3)
29
29
message (FATAL_ERROR "Clang version must be at least 3.3!" )
30
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 ()
31
42
endif ()
32
43
33
44
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /CMakeModules" )
@@ -38,53 +49,71 @@ include(Utils)
38
49
# function to help with cUrl
39
50
macro (FIND_CURL)
40
51
if (NOT WIN32 AND NOT APPLE AND CURL_STATICLIB)
52
+ find_package (OpenSSL REQUIRED)
41
53
set (OLD_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES} )
42
54
set (CMAKE_FIND_LIBRARY_SUFFIXES .a)
43
55
find_package (CURL REQUIRED)
44
- list (APPEND CURL_LIBRARIES ssl crypto )
56
+ list (APPEND CURL_LIBRARIES ${OPENSSL_LIBRARIES} ${BOOST_THREAD_LIBRARY} ${CMAKE_DL_LIBS} )
45
57
set (CMAKE_FIND_LIBRARY_SUFFIXES ${OLD_SUFFIXES} )
46
58
else (NOT WIN32 AND NOT APPLE AND CURL_STATICLIB)
47
59
find_package (CURL REQUIRED)
48
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 )
49
75
endmacro ()
50
76
77
+ # Save the old value of CMAKE_REQUIRED_FLAGS
78
+ set ( TEMP_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} )
79
+
51
80
# Fortify source
52
81
if (CMAKE_COMPILER_IS_GNUCXX)
53
82
if ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "Clang" )
54
- message ("-- Setting optimizations for clang++" )
83
+ message (STATUS " Setting optimizations for clang++" )
55
84
set (CMAKE_CXX_FLAGS_RELEASE "-D_FORTIFY_SOURCE=2 -O3 -DNDEBUG=1" )
56
85
set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-D_FORTIFY_SOURCE=2 -O3 -DNDEBUG=1 -g" )
57
86
58
87
# check and add data execution prevention
59
- message ("-- Enabling data execution prevention" )
88
+ message (STATUS " Enabling data execution prevention" )
60
89
add_linker_flag("-fsanitize=safe-stack" )
61
90
62
91
# check and add Stack-based buffer overrun detection
63
92
set (CMAKE_REQUIRED_FLAGS "-fstack-protector" )
64
93
check_c_compiler_flag("" HAVE_STACKPROTECTOR)
65
94
if (HAVE_STACKPROTECTOR)
66
- message ("-- Enabling stack-based buffer overrun detection" )
95
+ message (STATUS " Enabling stack-based buffer overrun detection" )
67
96
add_flag_append(CMAKE_C_FLAGS "-fstack-protector" )
68
97
add_flag_append(CMAKE_CXX_FLAGS "-fstack-protector" )
69
98
endif ()
70
99
else ()
71
- message ("-- Setting optimizations for g++" )
100
+ message (STATUS " Setting optimizations for g++" )
72
101
set (CMAKE_CXX_FLAGS_RELEASE "-D_FORTIFY_SOURCE=2 -O3 -DNDEBUG=1" )
73
102
set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-D_FORTIFY_SOURCE=2 -O3 -DNDEBUG=1 -g" )
74
103
75
104
# check and add data execution prevention
76
105
set (CMAKE_REQUIRED_FLAGS "-Wl,-znoexecstack" )
77
106
check_c_compiler_flag("" HAVE_NOEXECSTACK)
78
107
if (HAVE_NOEXECSTACK)
79
- message ("-- Enabling data execution prevention" )
108
+ message (STATUS " Enabling data execution prevention" )
80
109
add_linker_flag("-znoexecstack" )
81
110
endif ()
82
111
83
112
# check and add Stack-based buffer overrun detection
84
113
set (CMAKE_REQUIRED_FLAGS "-fstack-protector-strong" )
85
114
check_c_compiler_flag("" HAVE_STACKPROTECTOR)
86
115
if (HAVE_STACKPROTECTOR)
87
- message ("-- Enabling stack-based buffer overrun detection" )
116
+ message (STATUS " Enabling stack-based buffer overrun detection" )
88
117
add_flag_append(CMAKE_C_FLAGS "-fstack-protector-strong" )
89
118
add_flag_append(CMAKE_CXX_FLAGS "-fstack-protector-strong" )
90
119
endif ()
@@ -96,22 +125,26 @@ endif ()
96
125
set (CMAKE_REQUIRED_FLAGS "-Wl,-zrelro,-znow" )
97
126
check_c_compiler_flag("" HAVE_RELROFULL)
98
127
if (HAVE_RELROFULL)
99
- message ("-- Enabling full data relocation and protection" )
128
+ message (STATUS " Enabling full data relocation and protection" )
100
129
add_linker_flag("-zrelro" )
101
130
add_linker_flag("-znow" )
102
131
else ()
103
132
#if full relro is not available, try partial relro
104
133
set (CMAKE_REQUIRED_FLAGS "-Wl,-zrelro" )
105
134
check_c_compiler_flag("" HAVE_RELROPARTIAL)
106
135
if (HAVE_RELROPARTIAL)
107
- message ("-- Enabling partial data relocation and protection" )
136
+ message (STATUS " Enabling partial data relocation and protection" )
108
137
add_linker_flag("-zrelro" )
109
138
endif ()
110
139
endif ()
111
140
141
+ set (CMAKE_REQUIRED_FLAGS ${TEMP_REQUIRED_FLAGS} )
142
+
112
143
# position independent executetable (PIE)
113
144
# position independent code (PIC)
114
- add_definitions (-fPIC)
145
+ if (NOT MSVC )
146
+ add_definitions (-fPIC)
147
+ endif (NOT MSVC )
115
148
116
149
set (CMAKE_EXPORT_COMPILE_COMMANDS "ON" )
117
150
set ( GRAPHENE_EGENESIS_JSON "${CMAKE_CURRENT_SOURCE_DIR} /libraries/egenesis/genesis.json"
@@ -123,9 +156,9 @@ endif(USE_PCH)
123
156
124
157
option (USE_PROFILER "Build with GPROF support(Linux)." OFF )
125
158
126
- IF ( NOT WIN32 )
127
- list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /libraries/fc/CMakeModules" )
128
- ENDIF ( NOT WIN32 )
159
+ # Use Boost config file from fc
160
+ set (Boost_DIR "${CMAKE_CURRENT_SOURCE_DIR} /libraries/fc/CMakeModules/Boost" )
161
+
129
162
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /libraries/fc/GitVersionGen" )
130
163
include ( GetGitRevisionDescription )
131
164
get_git_head_revision( GIT_REFSPEC GIT_SHA2 )
@@ -139,14 +172,20 @@ LIST(APPEND BOOST_COMPONENTS thread
139
172
program_options
140
173
chrono
141
174
unit_test_framework
142
- context)
175
+ context
176
+ coroutine
177
+ regex )
143
178
# boost::endian is also required, but FindBoost can't handle header-only libs
144
179
SET ( Boost_USE_STATIC_LIBS ON CACHE STRING "ON or OFF" )
145
180
146
- IF ( WIN32 )
147
- 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} )
148
185
set (Boost_USE_MULTITHREADED ON )
149
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 )
150
189
ELSE ( WIN32 )
151
190
IF ( APPLE )
152
191
set ( CMAKE_THREAD_LIBS_INIT "-lpthread" )
@@ -157,28 +196,36 @@ ELSE( WIN32 )
157
196
ENDIF ( APPLE )
158
197
ENDIF (WIN32 )
159
198
160
- FIND_PACKAGE (Boost 1.57 REQUIRED COMPONENTS ${BOOST_COMPONENTS} )
161
- # 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
162
- IF (NOT "${Boost_VERSION} " MATCHES "1.53(.*)" )
163
- SET (BOOST_LIBRARIES_TEMP ${Boost_LIBRARIES} )
164
- FIND_PACKAGE (Boost 1.54 REQUIRED COMPONENTS coroutine)
165
- LIST (APPEND BOOST_COMPONENTS coroutine)
166
- SET (Boost_LIBRARIES ${BOOST_LIBRARIES_TEMP} ${Boost_LIBRARIES} )
167
- 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" )
168
213
169
214
if ( WIN32 )
170
215
171
216
message ( STATUS "Configuring BitShares on WIN32" )
172
- set ( DB_VERSION 60 )
173
- set ( BDB_STATIC_LIBS 1 )
174
217
175
- set ( ZLIB_LIBRARIES "" )
176
- 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 )
177
224
178
- set (CRYPTO_LIB )
225
+ SET ( DEFAULT_EXECUTABLE_INSTALL_DIR bin/ )
179
226
180
227
if ( MSVC )
181
- add_definitions (-DWIN32_LEAN_AND_MEAN)
228
+ add_definitions (-DWIN32_LEAN_AND_MEAN)
182
229
#looks like this flag can have different default on some machines.
183
230
SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO" )
184
231
SET (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO" )
@@ -187,44 +234,32 @@ if( WIN32 )
187
234
set (CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /DEBUG" )
188
235
endif ( MSVC )
189
236
190
- # On windows tcl should be installed to the directory pointed by setenv.bat script
191
- SET (TCL_INCLUDE_PATH $ENV{TCL_ROOT} /include )
192
- MESSAGE (STATUS "tcl INCLUDE PATH: ${TCL_INCLUDE_PATH} " )
193
-
194
- FIND_PACKAGE (TCL)
195
- MESSAGE (STATUS "tcl_library: ${TCL_LIBRARY} " )
196
-
197
- SET (TCL_LIBS "optimized;${TCL_LIBRARY} ;debug;" )
198
- get_filename_component (TCL_LIB_PATH "${TCL_LIBRARY} " PATH )
199
- get_filename_component (TCL_LIB_NAME "${TCL_LIBRARY} " NAME_WE )
200
- get_filename_component (TCL_LIB_EXT "${TCL_LIBRARY} " EXT )
201
-
202
- SET (TCL_LIBS "${TCL_LIBS}${TCL_LIB_PATH} /${TCL_LIB_NAME} g${TCL_LIB_EXT} " )
203
- SET (TCL_LIBRARY ${TCL_LIBS} )
204
-
205
237
else ( WIN32 ) # Apple AND Linux
206
238
207
239
if ( APPLE )
208
240
# Apple Specific Options Here
209
241
message ( STATUS "Configuring BitShares on OS X" )
210
242
set ( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -stdlib=libc++ -Wall" )
211
243
else ( APPLE )
212
- # Linux Specific Options Here
213
- 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
214
253
set ( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -Wall" )
215
254
if (USE_PROFILER)
216
255
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pg" )
217
256
endif ( USE_PROFILER )
218
- set ( rt_library rt )
219
257
set ( pthread_library pthread)
220
258
if ( NOT DEFINED crypto_library )
221
259
# I'm not sure why this is here, I guess someone has openssl and can't detect it with find_package()?
222
260
# if you have a normal install, you can define crypto_library to the empty string to avoid a build error
223
261
set ( crypto_library crypto)
224
262
endif ()
225
- if ( FULL_STATIC_BUILD )
226
- set ( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc" )
227
- endif ( FULL_STATIC_BUILD )
228
263
endif ( APPLE )
229
264
230
265
if ( "${CMAKE_CXX_COMPILER_ID} " STREQUAL "GNU" )
@@ -247,6 +282,10 @@ else( WIN32 ) # Apple AND Linux
247
282
248
283
endif ( WIN32 )
249
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
+
250
289
set (ENABLE_COVERAGE_TESTING FALSE CACHE BOOL "Build BitShares for code coverage analysis" )
251
290
252
291
if (ENABLE_COVERAGE_TESTING)
0 commit comments