@@ -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
@@ -92,21 +91,15 @@ if(SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS)
92
91
add_compile_definitions (USE_EXTERNAL_DEFAULT_CALLBACKS=1 )
93
92
endif ()
94
93
95
- set (SECP256K1_ECMULT_WINDOW_SIZE "AUTO" CACHE STRING "Window size for ecmult precomputation for verification, specified as integer in range [2..24]. \" AUTO \" is a reasonable setting for desktop machines (currently 15). [default=AUTO ]" )
96
- set_property (CACHE SECP256K1_ECMULT_WINDOW_SIZE PROPERTY STRINGS "AUTO" 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 )
94
+ set (SECP256K1_ECMULT_WINDOW_SIZE 15 CACHE STRING "Window size for ecmult precomputation for verification, specified as integer in range [2..24]. The default value is a reasonable setting for desktop machines (currently 15). [default=15 ]" )
95
+ set_property (CACHE SECP256K1_ECMULT_WINDOW_SIZE PROPERTY STRINGS 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 )
97
96
include (CheckStringOptionValue )
98
97
check_string_option_value (SECP256K1_ECMULT_WINDOW_SIZE )
99
- if (SECP256K1_ECMULT_WINDOW_SIZE STREQUAL "AUTO" )
100
- set (SECP256K1_ECMULT_WINDOW_SIZE 15 )
101
- endif ()
102
98
add_compile_definitions (ECMULT_WINDOW_SIZE=${SECP256K1_ECMULT_WINDOW_SIZE} )
103
99
104
- set (SECP256K1_ECMULT_GEN_KB "AUTO" CACHE STRING "The size of the precomputed table for signing in multiples of 1024 bytes (on typical platforms). Larger values result in possibly better signing or key generation performance at the cost of a larger table. Valid choices are 2, 22, 86. \" AUTO \" is a reasonable setting for desktop machines (currently 22). [default=AUTO ]" )
105
- set_property (CACHE SECP256K1_ECMULT_GEN_KB PROPERTY STRINGS "AUTO" 2 22 86 )
100
+ set (SECP256K1_ECMULT_GEN_KB 22 CACHE STRING "The size of the precomputed table for signing in multiples of 1024 bytes (on typical platforms). Larger values result in possibly better signing or key generation performance at the cost of a larger table. Valid choices are 2, 22, 86. The default value is a reasonable setting for desktop machines (currently 22). [default=22 ]" )
101
+ set_property (CACHE SECP256K1_ECMULT_GEN_KB PROPERTY STRINGS 2 22 86 )
106
102
check_string_option_value (SECP256K1_ECMULT_GEN_KB )
107
- if (SECP256K1_ECMULT_GEN_KB STREQUAL "AUTO" )
108
- set (SECP256K1_ECMULT_GEN_KB 22 )
109
- endif ()
110
103
if (SECP256K1_ECMULT_GEN_KB EQUAL 2 )
111
104
add_compile_definitions (COMB_BLOCKS=2 )
112
105
add_compile_definitions (COMB_TEETH=5 )
@@ -214,23 +207,25 @@ mark_as_advanced(
214
207
CMAKE_SHARED_LINKER_FLAGS_COVERAGE
215
208
)
216
209
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."
210
+ if (PROJECT_IS_TOP_LEVEL )
211
+ get_property (is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG )
212
+ set (default_build_type "RelWithDebInfo" )
213
+ if (is_multi_config )
214
+ set (CMAKE_CONFIGURATION_TYPES "${default_build_type} " "Release" "Debug" "MinSizeRel" "Coverage" CACHE STRING
215
+ "Supported configuration types."
232
216
FORCE
233
217
)
218
+ else ()
219
+ set_property (CACHE CMAKE_BUILD_TYPE PROPERTY
220
+ STRINGS "${default_build_type} " "Release" "Debug" "MinSizeRel" "Coverage"
221
+ )
222
+ if (NOT CMAKE_BUILD_TYPE )
223
+ message (STATUS "Setting build type to \" ${default_build_type} \" as none was specified" )
224
+ set (CMAKE_BUILD_TYPE "${default_build_type} " CACHE STRING
225
+ "Choose the type of build."
226
+ FORCE
227
+ )
228
+ endif ()
234
229
endif ()
235
230
endif ()
236
231
@@ -263,25 +258,34 @@ endif()
263
258
264
259
set (CMAKE_C_VISIBILITY_PRESET hidden )
265
260
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 )
261
+ set (print_msan_notice )
262
+ if (SECP256K1_BUILD_CTIME_TESTS )
263
+ include (CheckMemorySanitizer )
264
+ check_memory_sanitizer (msan_enabled )
265
+ if (msan_enabled )
266
+ try_append_c_flags (-fno-sanitize-memory-param-retval )
267
+ set (print_msan_notice YES )
268
+ endif ()
269
+ unset (msan_enabled )
270
+ endif ()
271
+
270
272
include (CTest )
271
273
# We do not use CTest's BUILD_TESTING because a single toggle for all tests is too coarse for our needs.
272
274
mark_as_advanced (BUILD_TESTING )
273
275
if (SECP256K1_BUILD_BENCHMARK OR SECP256K1_BUILD_TESTS OR SECP256K1_BUILD_EXHAUSTIVE_TESTS OR SECP256K1_BUILD_CTIME_TESTS OR SECP256K1_BUILD_EXAMPLES )
274
276
enable_testing ()
275
277
endif ()
276
278
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 )
279
+ 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." )
280
+ if (SECP256K1_APPEND_CFLAGS )
281
+ # Appending to this low-level rule variable is the only way to
282
+ # guarantee that the flags appear at the end of the command line.
283
+ string (APPEND CMAKE_C_COMPILE_OBJECT " ${SECP256K1_APPEND_CFLAGS} " )
284
+ endif ()
279
285
280
286
add_subdirectory (src )
281
- all_targets_compile_options (src "${SECP256K1_LATE_CFLAGS} " )
282
287
if (SECP256K1_BUILD_EXAMPLES )
283
288
add_subdirectory (examples )
284
- all_targets_compile_options (examples "${SECP256K1_LATE_CFLAGS} " )
285
289
endif ()
286
290
287
291
message ("\n " )
@@ -332,7 +336,7 @@ message("Valgrind .............................. ${SECP256K1_VALGRIND}")
332
336
get_directory_property (definitions COMPILE_DEFINITIONS )
333
337
string (REPLACE ";" " " definitions "${definitions} " )
334
338
message ("Preprocessor defined macros ........... ${definitions} " )
335
- message ("C compiler ............................ ${CMAKE_C_COMPILER} " )
339
+ message ("C compiler ............................ ${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER_VERSION} , ${ CMAKE_C_COMPILER} " )
336
340
message ("CFLAGS ................................ ${CMAKE_C_FLAGS} " )
337
341
get_directory_property (compile_options COMPILE_OPTIONS )
338
342
string (REPLACE ";" " " compile_options "${compile_options} " )
@@ -355,10 +359,17 @@ else()
355
359
message (" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_DEBUG} " )
356
360
message (" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_DEBUG} " )
357
361
endif ()
358
- if (SECP256K1_LATE_CFLAGS )
359
- message ("SECP256K1_LATE_CFLAGS ................. ${SECP256K1_LATE_CFLAGS} " )
362
+ if (SECP256K1_APPEND_CFLAGS )
363
+ message ("SECP256K1_APPEND_CFLAGS ............... ${SECP256K1_APPEND_CFLAGS} " )
364
+ endif ()
365
+ message ("" )
366
+ if (print_msan_notice )
367
+ message (
368
+ "Note:\n "
369
+ " MemorySanitizer detected, tried to add -fno-sanitize-memory-param-retval to compile options\n "
370
+ " to avoid false positives in ctime_tests. Pass -DSECP256K1_BUILD_CTIME_TESTS=OFF to avoid this.\n "
371
+ )
360
372
endif ()
361
- message ("\n " )
362
373
if (SECP256K1_EXPERIMENTAL )
363
374
message (
364
375
" ******\n "
0 commit comments