Skip to content

Commit 4b84f4b

Browse files
Merge #1239: cmake: Bugfix and other improvements after bumping CMake up to 3.13
a273d74 cmake: Improve version comparison (Hennadii Stepanov) 6a58b48 cmake: Use `if(... IN_LIST ...)` command (Hennadii Stepanov) 2445808 cmake: Use dedicated `GENERATOR_IS_MULTI_CONFIG` property (Hennadii Stepanov) 9f8703e cmake: Use dedicated `CMAKE_HOST_APPLE` variable (Hennadii Stepanov) 8c20170 cmake: Use recommended `add_compile_definitions` command (Hennadii Stepanov) 04d4cc0 cmake: Add `DESCRIPTION` and `HOMEPAGE_URL` options to `project` command (Hennadii Stepanov) 8a8b653 cmake: Use `SameMinorVersion` compatibility mode (Hennadii Stepanov) Pull request description: This PR: - resolves two items from #1235, including a bugfix with package version compatibility - includes other improvements which have become available for CMake 3.13+. To test the `GENERATOR_IS_MULTI_CONFIG` property on Linux, one can use the "[Ninja Multi-Config](https://cmake.org/cmake/help/latest/generator/Ninja%20Multi-Config.html)" generator: ```sh cmake -S . -B build -G "Ninja Multi-Config" ``` ACKs for top commit: real-or-random: ACK a273d74 theuni: ACK a273d74 Tree-SHA512: f31c4f0f30bf368303e70ab8952cde5cc8c70a5e79a04f879abcbee3d0a8d8c598379fb38f5142cb1f8ff5f9dcfc8b8eb4c13c975a1d05fdcc92d9c805a59d9a
2 parents 596b336 + a273d74 commit 4b84f4b

File tree

4 files changed

+44
-38
lines changed

4 files changed

+44
-38
lines changed

CMakeLists.txt

+39-31
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
cmake_minimum_required(VERSION 3.13)
22

3-
if(CMAKE_VERSION VERSION_GREATER 3.14)
3+
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.15)
44
# MSVC runtime library flags are selected by the CMAKE_MSVC_RUNTIME_LIBRARY abstraction.
55
cmake_policy(SET CMP0091 NEW)
66
# MSVC warning flags are not in CMAKE_<LANG>_FLAGS by default.
77
cmake_policy(SET CMP0092 NEW)
88
endif()
99

10-
# The package (a.k.a. release) version is based on semantic versioning 2.0.0 of
11-
# the API. All changes in experimental modules are treated as
12-
# backwards-compatible and therefore at most increase the minor version.
13-
project(libsecp256k1 VERSION 0.3.2 LANGUAGES C)
10+
project(libsecp256k1
11+
# The package (a.k.a. release) version is based on semantic versioning 2.0.0 of
12+
# the API. All changes in experimental modules are treated as
13+
# backwards-compatible and therefore at most increase the minor version.
14+
VERSION 0.3.2
15+
DESCRIPTION "Optimized C library for ECDSA signatures and secret/public key operations on curve secp256k1."
16+
HOMEPAGE_URL "https://github.com/bitcoin-core/secp256k1"
17+
LANGUAGES C
18+
)
1419

1520
# The library version is based on libtool versioning of the ABI. The set of
1621
# rules for updating the version can be found here:
@@ -36,27 +41,27 @@ option(SECP256K1_INSTALL "Enable installation" ON)
3641

3742
option(SECP256K1_ENABLE_MODULE_ECDH "Enable ECDH module." ON)
3843
if(SECP256K1_ENABLE_MODULE_ECDH)
39-
add_definitions(-DENABLE_MODULE_ECDH=1)
44+
add_compile_definitions(ENABLE_MODULE_ECDH=1)
4045
endif()
4146

4247
option(SECP256K1_ENABLE_MODULE_RECOVERY "Enable ECDSA pubkey recovery module." OFF)
4348
if(SECP256K1_ENABLE_MODULE_RECOVERY)
44-
add_definitions(-DENABLE_MODULE_RECOVERY=1)
49+
add_compile_definitions(ENABLE_MODULE_RECOVERY=1)
4550
endif()
4651

4752
option(SECP256K1_ENABLE_MODULE_EXTRAKEYS "Enable extrakeys module." ON)
4853
option(SECP256K1_ENABLE_MODULE_SCHNORRSIG "Enable schnorrsig module." ON)
4954
if(SECP256K1_ENABLE_MODULE_SCHNORRSIG)
5055
set(SECP256K1_ENABLE_MODULE_EXTRAKEYS ON)
51-
add_definitions(-DENABLE_MODULE_SCHNORRSIG=1)
56+
add_compile_definitions(ENABLE_MODULE_SCHNORRSIG=1)
5257
endif()
5358
if(SECP256K1_ENABLE_MODULE_EXTRAKEYS)
54-
add_definitions(-DENABLE_MODULE_EXTRAKEYS=1)
59+
add_compile_definitions(ENABLE_MODULE_EXTRAKEYS=1)
5560
endif()
5661

5762
option(SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS "Enable external default callback functions." OFF)
5863
if(SECP256K1_USE_EXTERNAL_DEFAULT_CALLBACKS)
59-
add_definitions(-DUSE_EXTERNAL_DEFAULT_CALLBACKS=1)
64+
add_compile_definitions(USE_EXTERNAL_DEFAULT_CALLBACKS=1)
6065
endif()
6166

6267
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]")
@@ -66,22 +71,22 @@ check_string_option_value(SECP256K1_ECMULT_WINDOW_SIZE)
6671
if(SECP256K1_ECMULT_WINDOW_SIZE STREQUAL "AUTO")
6772
set(SECP256K1_ECMULT_WINDOW_SIZE 15)
6873
endif()
69-
add_definitions(-DECMULT_WINDOW_SIZE=${SECP256K1_ECMULT_WINDOW_SIZE})
74+
add_compile_definitions(ECMULT_WINDOW_SIZE=${SECP256K1_ECMULT_WINDOW_SIZE})
7075

7176
set(SECP256K1_ECMULT_GEN_PREC_BITS "AUTO" CACHE STRING "Precision bits to tune the precomputed table size for signing, specified as integer 2, 4 or 8. \"AUTO\" is a reasonable setting for desktop machines (currently 4). [default=AUTO]")
7277
set_property(CACHE SECP256K1_ECMULT_GEN_PREC_BITS PROPERTY STRINGS "AUTO" 2 4 8)
7378
check_string_option_value(SECP256K1_ECMULT_GEN_PREC_BITS)
7479
if(SECP256K1_ECMULT_GEN_PREC_BITS STREQUAL "AUTO")
7580
set(SECP256K1_ECMULT_GEN_PREC_BITS 4)
7681
endif()
77-
add_definitions(-DECMULT_GEN_PREC_BITS=${SECP256K1_ECMULT_GEN_PREC_BITS})
82+
add_compile_definitions(ECMULT_GEN_PREC_BITS=${SECP256K1_ECMULT_GEN_PREC_BITS})
7883

7984
set(SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY "OFF" CACHE STRING "Test-only override of the (autodetected by the C code) \"widemul\" setting. Legal values are: \"OFF\", \"int128_struct\", \"int128\" or \"int64\". [default=OFF]")
8085
set_property(CACHE SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY PROPERTY STRINGS "OFF" "int128_struct" "int128" "int64")
8186
check_string_option_value(SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY)
8287
if(SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY)
8388
string(TOUPPER "${SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY}" widemul_upper_value)
84-
add_definitions(-DUSE_FORCE_WIDEMUL_${widemul_upper_value}=1)
89+
add_compile_definitions(USE_FORCE_WIDEMUL_${widemul_upper_value}=1)
8590
endif()
8691
mark_as_advanced(FORCE SECP256K1_TEST_OVERRIDE_WIDE_MULTIPLY)
8792

@@ -90,13 +95,13 @@ set_property(CACHE SECP256K1_ASM PROPERTY STRINGS "AUTO" "OFF" "x86_64" "arm")
9095
check_string_option_value(SECP256K1_ASM)
9196
if(SECP256K1_ASM STREQUAL "arm")
9297
enable_language(ASM)
93-
add_definitions(-DUSE_EXTERNAL_ASM=1)
98+
add_compile_definitions(USE_EXTERNAL_ASM=1)
9499
elseif(SECP256K1_ASM)
95100
include(Check64bitAssembly)
96101
check_64bit_assembly()
97102
if(HAS_64BIT_ASM)
98103
set(SECP256K1_ASM "x86_64")
99-
add_definitions(-DUSE_ASM_X86_64=1)
104+
add_compile_definitions(USE_ASM_X86_64=1)
100105
elseif(SECP256K1_ASM STREQUAL "AUTO")
101106
set(SECP256K1_ASM "OFF")
102107
else()
@@ -119,7 +124,7 @@ if(SECP256K1_VALGRIND)
119124
if(Valgrind_FOUND)
120125
set(SECP256K1_VALGRIND ON)
121126
include_directories(${Valgrind_INCLUDE_DIR})
122-
add_definitions(-DVALGRIND)
127+
add_compile_definitions(VALGRIND)
123128
elseif(SECP256K1_VALGRIND STREQUAL "AUTO")
124129
set(SECP256K1_VALGRIND OFF)
125130
else()
@@ -166,21 +171,24 @@ mark_as_advanced(
166171
CMAKE_SHARED_LINKER_FLAGS_COVERAGE
167172
)
168173

169-
if(CMAKE_CONFIGURATION_TYPES)
170-
set(CMAKE_CONFIGURATION_TYPES "RelWithDebInfo" "Release" "Debug" "MinSizeRel" "Coverage")
171-
endif()
172-
173-
get_property(cached_cmake_build_type CACHE CMAKE_BUILD_TYPE PROPERTY TYPE)
174-
if(cached_cmake_build_type)
174+
get_property(is_multi_config GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
175+
set(default_build_type "RelWithDebInfo")
176+
if(is_multi_config)
177+
set(CMAKE_CONFIGURATION_TYPES "${default_build_type}" "Release" "Debug" "MinSizeRel" "Coverage" CACHE STRING
178+
"Supported configuration types."
179+
FORCE
180+
)
181+
else()
175182
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY
176-
STRINGS "RelWithDebInfo" "Release" "Debug" "MinSizeRel" "Coverage"
183+
STRINGS "${default_build_type}" "Release" "Debug" "MinSizeRel" "Coverage"
177184
)
178-
endif()
179-
180-
set(default_build_type "RelWithDebInfo")
181-
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
182-
message(STATUS "Setting build type to \"${default_build_type}\" as none was specified")
183-
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING "Choose the type of build." FORCE)
185+
if(NOT CMAKE_BUILD_TYPE)
186+
message(STATUS "Setting build type to \"${default_build_type}\" as none was specified")
187+
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE STRING
188+
"Choose the type of build."
189+
FORCE
190+
)
191+
endif()
184192
endif()
185193

186194
include(TryAddCompileOption)
@@ -274,15 +282,15 @@ message("CFLAGS ................................ ${CMAKE_C_FLAGS}")
274282
get_directory_property(compile_options COMPILE_OPTIONS)
275283
string(REPLACE ";" " " compile_options "${compile_options}")
276284
message("Compile options ....................... " ${compile_options})
277-
if(DEFINED CMAKE_BUILD_TYPE)
285+
if(NOT is_multi_config)
278286
message("Build type:")
279287
message(" - CMAKE_BUILD_TYPE ................... ${CMAKE_BUILD_TYPE}")
280288
string(TOUPPER "${CMAKE_BUILD_TYPE}" build_type)
281289
message(" - CFLAGS ............................. ${CMAKE_C_FLAGS_${build_type}}")
282290
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_${build_type}}")
283291
message(" - LDFLAGS for shared libraries ....... ${CMAKE_SHARED_LINKER_FLAGS_${build_type}}")
284292
else()
285-
message("Available configurations .............. ${CMAKE_CONFIGURATION_TYPES}")
293+
message("Supported configurations .............. ${CMAKE_CONFIGURATION_TYPES}")
286294
message("RelWithDebInfo configuration:")
287295
message(" - CFLAGS ............................. ${CMAKE_C_FLAGS_RELWITHDEBINFO}")
288296
message(" - LDFLAGS for executables ............ ${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}")

cmake/CheckStringOptionValue.cmake

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
function(check_string_option_value option)
22
get_property(expected_values CACHE ${option} PROPERTY STRINGS)
33
if(expected_values)
4-
foreach(value IN LISTS expected_values)
5-
if(value STREQUAL "${${option}}")
6-
return()
7-
endif()
8-
endforeach()
4+
if(${option} IN_LIST expected_values)
5+
return()
6+
endif()
97
message(FATAL_ERROR "${option} value is \"${${option}}\", but must be one of ${expected_values}.")
108
endif()
119
message(AUTHOR_WARNING "The STRINGS property must be set before invoking `check_string_option_value' function.")

cmake/FindValgrind.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")
1+
if(CMAKE_HOST_APPLE)
22
find_program(BREW_COMMAND brew)
33
execute_process(
44
COMMAND ${BREW_COMMAND} --prefix valgrind

src/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ if(SECP256K1_INSTALL)
114114
NO_SET_AND_CHECK_MACRO
115115
)
116116
write_basic_package_version_file(${PROJECT_NAME}-config-version.cmake
117-
COMPATIBILITY SameMajorVersion
117+
COMPATIBILITY SameMinorVersion
118118
)
119119

120120
install(

0 commit comments

Comments
 (0)