|
1 | 1 | # Must be included before CMAKE_INSTALL_INCLUDEDIR is used.
|
2 | 2 | include(GNUInstallDirs)
|
3 |
| -set(${PROJECT_NAME}_installables "") |
4 | 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) |
5 | 14 | if(SECP256K1_ASM STREQUAL "arm")
|
6 |
| - add_library(common OBJECT |
| 15 | + add_library(secp256k1_asm_arm OBJECT EXCLUDE_FROM_ALL) |
| 16 | + target_sources(secp256k1_asm_arm PUBLIC |
7 | 17 | asm/field_10x26_arm.s
|
8 | 18 | )
|
9 |
| - set(common_obj "$<TARGET_OBJECTS:common>") |
10 |
| -else() |
11 |
| - set(common_obj "") |
| 19 | + target_sources(secp256k1 PRIVATE $<TARGET_OBJECTS:secp256k1_asm_arm>) |
| 20 | + target_link_libraries(secp256k1_asm INTERFACE secp256k1_asm_arm) |
12 | 21 | endif()
|
13 | 22 |
|
14 |
| -add_library(precomputed OBJECT |
15 |
| - precomputed_ecmult.c |
16 |
| - precomputed_ecmult_gen.c |
17 |
| -) |
18 |
| -set(internal_obj "$<TARGET_OBJECTS:precomputed>" "${common_obj}") |
| 23 | +# Define our export symbol only for Win32 and only for shared libs. |
| 24 | +# This matches libtool's usage of DLL_EXPORT |
| 25 | +if(WIN32) |
| 26 | + set_target_properties(secp256k1 PROPERTIES DEFINE_SYMBOL "DLL_EXPORT") |
| 27 | +endif() |
19 | 28 |
|
20 |
| -add_library(secp256k1 SHARED EXCLUDE_FROM_ALL |
21 |
| - secp256k1.c |
22 |
| - ${internal_obj} |
23 |
| -) |
24 |
| -target_include_directories(secp256k1 INTERFACE |
| 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 PUBLIC |
25 | 35 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
26 | 36 | )
|
27 |
| -target_compile_definitions(secp256k1 PRIVATE |
28 |
| - $<$<PLATFORM_ID:Windows>:DLL_EXPORT> |
29 |
| -) |
30 | 37 | set_target_properties(secp256k1 PROPERTIES
|
31 | 38 | VERSION "${${PROJECT_NAME}_LIB_VERSION_CURRENT}.${${PROJECT_NAME}_LIB_VERSION_AGE}.${${PROJECT_NAME}_LIB_VERSION_REVISION}"
|
32 | 39 | SOVERSION "${${PROJECT_NAME}_LIB_VERSION_CURRENT}"
|
33 | 40 | )
|
34 |
| -if(SECP256K1_BUILD_SHARED) |
35 |
| - get_target_property(use_pic secp256k1 POSITION_INDEPENDENT_CODE) |
36 |
| - set_target_properties(precomputed PROPERTIES POSITION_INDEPENDENT_CODE ${use_pic}) |
37 |
| - set_target_properties(secp256k1 PROPERTIES EXCLUDE_FROM_ALL FALSE) |
38 |
| - list(APPEND ${PROJECT_NAME}_installables secp256k1) |
39 |
| -endif() |
40 |
| - |
41 |
| -add_library(secp256k1_static STATIC EXCLUDE_FROM_ALL |
42 |
| - secp256k1.c |
43 |
| - ${internal_obj} |
44 |
| -) |
45 |
| -target_include_directories(secp256k1_static INTERFACE |
46 |
| - $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> |
47 |
| -) |
48 |
| -if(NOT MSVC) |
49 |
| - set_target_properties(secp256k1_static PROPERTIES |
50 |
| - OUTPUT_NAME secp256k1 |
51 |
| - ) |
52 |
| -endif() |
53 |
| -if(SECP256K1_BUILD_STATIC) |
54 |
| - set_target_properties(secp256k1_static PROPERTIES EXCLUDE_FROM_ALL FALSE) |
55 |
| - list(APPEND ${PROJECT_NAME}_installables secp256k1_static) |
56 |
| -endif() |
57 |
| - |
58 |
| -add_library(binary_interface INTERFACE) |
59 |
| -target_compile_definitions(binary_interface INTERFACE |
60 |
| - $<$<C_COMPILER_ID:MSVC>:_CRT_SECURE_NO_WARNINGS> |
61 |
| -) |
62 |
| - |
63 |
| -add_library(link_library INTERFACE) |
64 |
| -if(SECP256K1_BUILD_SHARED) |
65 |
| - target_link_libraries(link_library INTERFACE secp256k1) |
66 |
| -elseif(SECP256K1_BUILD_STATIC) |
67 |
| - target_link_libraries(link_library INTERFACE secp256k1_static) |
68 |
| -endif() |
69 | 41 |
|
70 | 42 | if(SECP256K1_BUILD_BENCHMARK)
|
71 | 43 | add_executable(bench bench.c)
|
72 |
| - target_link_libraries(bench binary_interface link_library) |
73 |
| - add_executable(bench_internal bench_internal.c ${internal_obj}) |
74 |
| - target_link_libraries(bench_internal binary_interface) |
75 |
| - add_executable(bench_ecmult bench_ecmult.c ${internal_obj}) |
76 |
| - target_link_libraries(bench_ecmult binary_interface) |
| 44 | + target_link_libraries(bench secp256k1) |
| 45 | + add_executable(bench_internal bench_internal.c) |
| 46 | + target_link_libraries(bench_internal secp256k1_precomputed secp256k1_asm) |
| 47 | + add_executable(bench_ecmult bench_ecmult.c) |
| 48 | + target_link_libraries(bench_ecmult secp256k1_precomputed secp256k1_asm) |
77 | 49 | endif()
|
78 | 50 |
|
79 | 51 | if(SECP256K1_BUILD_TESTS)
|
80 |
| - add_executable(noverify_tests tests.c ${internal_obj}) |
81 |
| - target_link_libraries(noverify_tests binary_interface) |
| 52 | + add_executable(noverify_tests tests.c) |
| 53 | + target_link_libraries(noverify_tests secp256k1_precomputed secp256k1_asm) |
82 | 54 | add_test(noverify_tests noverify_tests)
|
83 | 55 | if(NOT CMAKE_BUILD_TYPE STREQUAL "Coverage")
|
84 |
| - add_executable(tests tests.c ${internal_obj}) |
| 56 | + add_executable(tests tests.c) |
85 | 57 | target_compile_definitions(tests PRIVATE VERIFY)
|
86 |
| - target_link_libraries(tests binary_interface) |
| 58 | + target_link_libraries(tests secp256k1_precomputed secp256k1_asm) |
87 | 59 | add_test(tests tests)
|
88 | 60 | endif()
|
89 | 61 | endif()
|
90 | 62 |
|
91 | 63 | if(SECP256K1_BUILD_EXHAUSTIVE_TESTS)
|
92 |
| - # Note: do not include $<TARGET_OBJECTS:precomputed> in exhaustive_tests (it uses runtime-generated tables). |
93 |
| - add_executable(exhaustive_tests tests_exhaustive.c ${common_obj}) |
| 64 | + # Note: do not include secp256k1_precomputed in exhaustive_tests (it uses runtime-generated tables). |
| 65 | + add_executable(exhaustive_tests tests_exhaustive.c) |
| 66 | + target_link_libraries(exhaustive_tests secp256k1_asm) |
94 | 67 | target_compile_definitions(exhaustive_tests PRIVATE $<$<NOT:$<CONFIG:Coverage>>:VERIFY>)
|
95 |
| - target_link_libraries(exhaustive_tests binary_interface) |
96 | 68 | add_test(exhaustive_tests exhaustive_tests)
|
97 | 69 | endif()
|
98 | 70 |
|
99 | 71 | if(SECP256K1_BUILD_CTIME_TESTS)
|
100 | 72 | add_executable(ctime_tests ctime_tests.c)
|
101 |
| - target_link_libraries(ctime_tests binary_interface link_library) |
| 73 | + target_link_libraries(ctime_tests secp256k1) |
102 | 74 | endif()
|
103 | 75 |
|
104 |
| -install(TARGETS ${${PROJECT_NAME}_installables} |
| 76 | +install(TARGETS secp256k1 |
105 | 77 | EXPORT ${PROJECT_NAME}-targets
|
106 | 78 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
107 | 79 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
0 commit comments