1
+ # Must be included before CMAKE_INSTALL_INCLUDEDIR is used.
2
+ include (GNUInstallDirs)
3
+
4
+ add_library (secp256k1_precomputed OBJECT EXCLUDE_FROM_ALL
5
+ precomputed_ecmult.c
6
+ precomputed_ecmult_gen.c
7
+ )
8
+
9
+ # Add objects explicitly rather than linking to the object libs to keep them
10
+ # from being exported.
11
+ add_library (secp256k1 secp256k1.c $<TARGET_OBJECTS:secp256k1_precomputed>)
12
+
13
+ add_library (secp256k1_asm INTERFACE )
14
+ if (SECP256K1_ASM STREQUAL "arm32" )
15
+ add_library (secp256k1_asm_arm OBJECT EXCLUDE_FROM_ALL )
16
+ target_sources (secp256k1_asm_arm PUBLIC
17
+ asm/field_10x26_arm.s
18
+ )
19
+ target_sources (secp256k1 PRIVATE $<TARGET_OBJECTS:secp256k1_asm_arm>)
20
+ target_link_libraries (secp256k1_asm INTERFACE secp256k1_asm_arm)
21
+ endif ()
22
+
23
+ if (WIN32 )
24
+ # Define our export symbol only for shared libs.
25
+ set_target_properties (secp256k1 PROPERTIES DEFINE_SYMBOL SECP256K1_DLL_EXPORT)
26
+ target_compile_definitions (secp256k1 INTERFACE $<$<NOT :$<BOOL :${BUILD_SHARED_LIBS} >>:SECP256K1_STATIC>)
27
+ endif ()
28
+
29
+ # Object libs don't know if they're being built for a shared or static lib.
30
+ # Grab the PIC property from secp256k1 which knows.
31
+ get_target_property (use_pic secp256k1 POSITION_INDEPENDENT_CODE )
32
+ set_target_properties (secp256k1_precomputed PROPERTIES POSITION_INDEPENDENT_CODE ${use_pic} )
33
+
34
+ target_include_directories (secp256k1 INTERFACE
35
+ # Add the include path for parent projects so that they don't have to manually add it.
36
+ $<BUILD_INTERFACE:$<$<NOT :$<BOOL :${PROJECT_IS_TOP_LEVEL} >>:${PROJECT_SOURCE_DIR} /include >>
37
+ $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >
38
+ )
39
+
40
+ # This emulates Libtool to make sure Libtool and CMake agree on the ABI version,
41
+ # see below "Calculate the version variables" in build-aux/ltmain.sh.
42
+ math (EXPR ${PROJECT_NAME} _soversion "${${PROJECT_NAME} _LIB_VERSION_CURRENT} - ${${PROJECT_NAME} _LIB_VERSION_AGE}" )
43
+ set_target_properties (secp256k1 PROPERTIES
44
+ SOVERSION ${${PROJECT_NAME} _soversion}
45
+ )
46
+ if (CMAKE_SYSTEM_NAME STREQUAL "Linux" )
47
+ set_target_properties (secp256k1 PROPERTIES
48
+ VERSION ${${PROJECT_NAME} _soversion}.${${PROJECT_NAME} _LIB_VERSION_AGE}.${${PROJECT_NAME} _LIB_VERSION_REVISION}
49
+ )
50
+ elseif (APPLE )
51
+ if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.17)
52
+ math (EXPR ${PROJECT_NAME} _compatibility_version "${${PROJECT_NAME} _LIB_VERSION_CURRENT} + 1" )
53
+ set_target_properties (secp256k1 PROPERTIES
54
+ MACHO_COMPATIBILITY_VERSION ${${PROJECT_NAME} _compatibility_version}
55
+ MACHO_CURRENT_VERSION ${${PROJECT_NAME} _compatibility_version}.${${PROJECT_NAME} _LIB_VERSION_REVISION}
56
+ )
57
+ unset (${PROJECT_NAME} _compatibility_version)
58
+ elseif (BUILD_SHARED_LIBS )
59
+ message (WARNING
60
+ "The 'compatibility version' and 'current version' values of the DYLIB "
61
+ "will diverge from the values set by the GNU Libtool. To ensure "
62
+ "compatibility, it is recommended to upgrade CMake to at least version 3.17."
63
+ )
64
+ endif ()
65
+ elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows" )
66
+ set (${PROJECT_NAME} _windows "secp256k1" )
67
+ if (MSVC )
68
+ set (${PROJECT_NAME} _windows "${PROJECT_NAME} " )
69
+ endif ()
70
+ set_target_properties (secp256k1 PROPERTIES
71
+ ARCHIVE_OUTPUT_NAME "${${PROJECT_NAME} _windows}"
72
+ RUNTIME_OUTPUT_NAME "${${PROJECT_NAME} _windows}-${${PROJECT_NAME} _soversion}"
73
+ )
74
+ unset (${PROJECT_NAME} _windows)
75
+ endif ()
76
+ unset (${PROJECT_NAME} _soversion)
77
+
78
+ if (SECP256K1_BUILD_BENCHMARK)
79
+ add_executable (bench bench.c)
80
+ target_link_libraries (bench secp256k1)
81
+ add_executable (bench_internal bench_internal.c)
82
+ target_link_libraries (bench_internal secp256k1_precomputed secp256k1_asm)
83
+ add_executable (bench_ecmult bench_ecmult.c)
84
+ target_link_libraries (bench_ecmult secp256k1_precomputed secp256k1_asm)
85
+ endif ()
86
+
87
+ if (SECP256K1_BUILD_TESTS)
88
+ add_executable (noverify_tests tests.c)
89
+ target_link_libraries (noverify_tests secp256k1_precomputed secp256k1_asm)
90
+ add_test (NAME secp256k1_noverify_tests COMMAND noverify_tests)
91
+ if (NOT CMAKE_BUILD_TYPE STREQUAL "Coverage" )
92
+ add_executable (tests tests.c)
93
+ target_compile_definitions (tests PRIVATE VERIFY)
94
+ target_link_libraries (tests secp256k1_precomputed secp256k1_asm)
95
+ add_test (NAME secp256k1_tests COMMAND tests)
96
+ endif ()
97
+ endif ()
98
+
99
+ if (SECP256K1_BUILD_EXHAUSTIVE_TESTS)
100
+ # Note: do not include secp256k1_precomputed in exhaustive_tests (it uses runtime-generated tables).
101
+ add_executable (exhaustive_tests tests_exhaustive.c)
102
+ target_link_libraries (exhaustive_tests secp256k1_asm)
103
+ target_compile_definitions (exhaustive_tests PRIVATE $<$<NOT :$<CONFIG:Coverage>>:VERIFY>)
104
+ add_test (NAME secp256k1_exhaustive_tests COMMAND exhaustive_tests)
105
+ endif ()
106
+
107
+ if (SECP256K1_BUILD_CTIME_TESTS)
108
+ add_executable (ctime_tests ctime_tests.c)
109
+ target_link_libraries (ctime_tests secp256k1)
110
+ endif ()
111
+
112
+ if (SECP256K1_INSTALL)
113
+ install (TARGETS secp256k1
114
+ EXPORT ${PROJECT_NAME} -targets
115
+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
116
+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
117
+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
118
+ )
119
+ set (${PROJECT_NAME} _headers
120
+ "${PROJECT_SOURCE_DIR} /include/secp256k1.h"
121
+ "${PROJECT_SOURCE_DIR} /include/secp256k1_preallocated.h"
122
+ )
123
+ if (SECP256K1_ENABLE_MODULE_ECDH)
124
+ list (APPEND ${PROJECT_NAME} _headers "${PROJECT_SOURCE_DIR} /include/secp256k1_ecdh.h" )
125
+ endif ()
126
+ if (SECP256K1_ENABLE_MODULE_RECOVERY)
127
+ list (APPEND ${PROJECT_NAME} _headers "${PROJECT_SOURCE_DIR} /include/secp256k1_recovery.h" )
128
+ endif ()
129
+ if (SECP256K1_ENABLE_MODULE_EXTRAKEYS)
130
+ list (APPEND ${PROJECT_NAME} _headers "${PROJECT_SOURCE_DIR} /include/secp256k1_extrakeys.h" )
131
+ endif ()
132
+ if (SECP256K1_ENABLE_MODULE_SCHNORRSIG)
133
+ list (APPEND ${PROJECT_NAME} _headers "${PROJECT_SOURCE_DIR} /include/secp256k1_schnorrsig.h" )
134
+ endif ()
135
+ if (SECP256K1_ENABLE_MODULE_MUSIG)
136
+ list (APPEND ${PROJECT_NAME} _headers "${PROJECT_SOURCE_DIR} /include/secp256k1_musig.h" )
137
+ endif ()
138
+ if (SECP256K1_ENABLE_MODULE_ELLSWIFT)
139
+ list (APPEND ${PROJECT_NAME} _headers "${PROJECT_SOURCE_DIR} /include/secp256k1_ellswift.h" )
140
+ endif ()
141
+ install (FILES ${${PROJECT_NAME} _headers}
142
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
143
+ )
144
+
145
+ install (EXPORT ${PROJECT_NAME} -targets
146
+ FILE ${PROJECT_NAME} -targets.cmake
147
+ NAMESPACE ${PROJECT_NAME} ::
148
+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/${PROJECT_NAME}
149
+ )
150
+
151
+ include (CMakePackageConfigHelpers)
152
+ configure_package_config_file(
153
+ ${PROJECT_SOURCE_DIR} /cmake/config.cmake.in
154
+ ${PROJECT_NAME} -config.cmake
155
+ INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/${PROJECT_NAME}
156
+ NO_SET_AND_CHECK_MACRO
157
+ )
158
+ write_basic_package_version_file(${PROJECT_NAME} -config-version .cmake
159
+ COMPATIBILITY SameMinorVersion
160
+ )
161
+
162
+ install (
163
+ FILES
164
+ ${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAME} -config.cmake
165
+ ${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAME} -config-version .cmake
166
+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/${PROJECT_NAME}
167
+ )
168
+
169
+ include (GeneratePkgConfigFile)
170
+ generate_pkg_config_file(${PROJECT_SOURCE_DIR} /libsecp256k1.pc.in)
171
+ install (
172
+ FILES
173
+ ${CMAKE_CURRENT_BINARY_DIR} /${PROJECT_NAME} .pc
174
+ DESTINATION ${CMAKE_INSTALL_LIBDIR} /pkgconfig
175
+ )
176
+ endif ()
0 commit comments