@@ -18,15 +18,14 @@ project(libsecp256k1
18
18
)
19
19
20
20
if (CMAKE_VERSION VERSION_LESS 3.21)
21
- get_directory_property ( parent_directory PARENT_DIRECTORY )
22
- if (parent_directory )
23
- set (PROJECT_IS_TOP_LEVEL OFF CACHE INTERNAL "Emulates CMake 3.21+ behavior." )
24
- set (${PROJECT_NAME} _IS_TOP_LEVEL OFF CACHE INTERNAL "Emulates CMake 3.21+ behavior." )
21
+ # Emulates CMake 3.21+ behavior.
22
+ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR )
23
+ set (PROJECT_IS_TOP_LEVEL ON )
24
+ set (${PROJECT_NAME} _IS_TOP_LEVEL ON )
25
25
else ()
26
- set (PROJECT_IS_TOP_LEVEL ON CACHE INTERNAL "Emulates CMake 3.21+ behavior." )
27
- set (${PROJECT_NAME} _IS_TOP_LEVEL ON CACHE INTERNAL "Emulates CMake 3.21+ behavior." )
26
+ set (PROJECT_IS_TOP_LEVEL OFF )
27
+ set (${PROJECT_NAME} _IS_TOP_LEVEL OFF )
28
28
endif ()
29
- unset (parent_directory )
30
29
endif ()
31
30
32
31
# The library version is based on libtool versioning of the ABI. The set of
@@ -214,23 +213,25 @@ mark_as_advanced(
214
213
CMAKE_SHARED_LINKER_FLAGS_COVERAGE
215
214
)
216
215
217
- get_property (is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
218
- set (default_build_type "RelWithDebInfo" )
219
- if (is_multi_config)
220
- set (CMAKE_CONFIGURATION_TYPES "${default_build_type} " "Release" "Debug" "MinSizeRel" "Coverage" CACHE STRING
221
- "Supported configuration types."
222
- FORCE
223
- )
224
- else ()
225
- set_property (CACHE CMAKE_BUILD_TYPE PROPERTY
226
- STRINGS "${default_build_type} " "Release" "Debug" "MinSizeRel" "Coverage"
227
- )
228
- if (NOT CMAKE_BUILD_TYPE )
229
- message (STATUS "Setting build type to \" ${default_build_type} \" as none was specified" )
230
- set (CMAKE_BUILD_TYPE "${default_build_type} " CACHE STRING
231
- "Choose the type of build."
216
+ if (PROJECT_IS_TOP_LEVEL)
217
+ get_property (is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
218
+ set (default_build_type "RelWithDebInfo" )
219
+ if (is_multi_config)
220
+ set (CMAKE_CONFIGURATION_TYPES "${default_build_type} " "Release" "Debug" "MinSizeRel" "Coverage" CACHE STRING
221
+ "Supported configuration types."
232
222
FORCE
233
223
)
224
+ else ()
225
+ set_property (CACHE CMAKE_BUILD_TYPE PROPERTY
226
+ STRINGS "${default_build_type} " "Release" "Debug" "MinSizeRel" "Coverage"
227
+ )
228
+ if (NOT CMAKE_BUILD_TYPE )
229
+ message (STATUS "Setting build type to \" ${default_build_type} \" as none was specified" )
230
+ set (CMAKE_BUILD_TYPE "${default_build_type} " CACHE STRING
231
+ "Choose the type of build."
232
+ FORCE
233
+ )
234
+ endif ()
234
235
endif ()
235
236
endif ()
236
237
@@ -263,25 +264,34 @@ endif()
263
264
264
265
set (CMAKE_C_VISIBILITY_PRESET hidden)
265
266
266
- # Ask CTest to create a "check" target (e.g., make check) as alias for the "test" target.
267
- # CTEST_TEST_TARGET_ALIAS is not documented but supposed to be user-facing.
268
- # See: https://gitlab.kitware.com/cmake/cmake/-/commit/816c9d1aa1f2b42d40c81a991b68c96eb12b6d2
269
- set (CTEST_TEST_TARGET_ALIAS check)
267
+ set (print_msan_notice)
268
+ if (SECP256K1_BUILD_CTIME_TESTS)
269
+ include (CheckMemorySanitizer)
270
+ check_memory_sanitizer(msan_enabled)
271
+ if (msan_enabled)
272
+ try_append_c_flags(-fno-sanitize-memory-param-retval)
273
+ set (print_msan_notice YES )
274
+ endif ()
275
+ unset (msan_enabled)
276
+ endif ()
277
+
270
278
include (CTest)
271
279
# We do not use CTest's BUILD_TESTING because a single toggle for all tests is too coarse for our needs.
272
280
mark_as_advanced (BUILD_TESTING)
273
281
if (SECP256K1_BUILD_BENCHMARK OR SECP256K1_BUILD_TESTS OR SECP256K1_BUILD_EXHAUSTIVE_TESTS OR SECP256K1_BUILD_CTIME_TESTS OR SECP256K1_BUILD_EXAMPLES)
274
282
enable_testing ()
275
283
endif ()
276
284
277
- set (SECP256K1_LATE_CFLAGS "" CACHE STRING "Compiler flags that are added to the command line after all other flags added by the build system." )
278
- include (AllTargetsCompileOptions)
285
+ set (SECP256K1_APPEND_CFLAGS "" CACHE STRING "Compiler flags that are appended to the command line after all other flags added by the build system. This variable is intended for debugging and special builds." )
286
+ if (SECP256K1_APPEND_CFLAGS)
287
+ # Appending to this low-level rule variable is the only way to
288
+ # guarantee that the flags appear at the end of the command line.
289
+ string (APPEND CMAKE_C_COMPILE_OBJECT " ${SECP256K1_APPEND_CFLAGS} " )
290
+ endif ()
279
291
280
292
add_subdirectory (src)
281
- all_targets_compile_options(src "${SECP256K1_LATE_CFLAGS} " )
282
293
if (SECP256K1_BUILD_EXAMPLES)
283
294
add_subdirectory (examples)
284
- all_targets_compile_options(examples "${SECP256K1_LATE_CFLAGS} " )
285
295
endif ()
286
296
287
297
message ("\n " )
@@ -332,7 +342,7 @@ message("Valgrind .............................. ${SECP256K1_VALGRIND}")
332
342
get_directory_property (definitions COMPILE_DEFINITIONS )
333
343
string (REPLACE ";" " " definitions "${definitions} " )
334
344
message ("Preprocessor defined macros ........... ${definitions} " )
335
- message ("C compiler ............................ ${CMAKE_C_COMPILER} " )
345
+ message ("C compiler ............................ ${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION} , ${ CMAKE_C_COMPILER} " )
336
346
message ("CFLAGS ................................ ${CMAKE_C_FLAGS} " )
337
347
get_directory_property (compile_options COMPILE_OPTIONS)
338
348
string (REPLACE ";" " " compile_options "${compile_options} " )
@@ -355,10 +365,17 @@ else()
355
365
message (" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_DEBUG} " )
356
366
message (" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_DEBUG} " )
357
367
endif ()
358
- if (SECP256K1_LATE_CFLAGS)
359
- message ("SECP256K1_LATE_CFLAGS ................. ${SECP256K1_LATE_CFLAGS} " )
368
+ if (SECP256K1_APPEND_CFLAGS)
369
+ message ("SECP256K1_APPEND_CFLAGS ............... ${SECP256K1_APPEND_CFLAGS} " )
370
+ endif ()
371
+ message ("" )
372
+ if (print_msan_notice)
373
+ message (
374
+ "Note:\n "
375
+ " MemorySanitizer detected, tried to add -fno-sanitize-memory-param-retval to compile options\n "
376
+ " to avoid false positives in ctime_tests. Pass -DSECP256K1_BUILD_CTIME_TESTS=OFF to avoid this.\n "
377
+ )
360
378
endif ()
361
- message ("\n " )
362
379
if (SECP256K1_EXPERIMENTAL)
363
380
message (
364
381
" ******\n "
0 commit comments