|
1 | 1 | # Must be included before CMAKE_INSTALL_INCLUDEDIR is used.
|
2 | 2 | include(GNUInstallDirs)
|
3 |
| -set(${PROJECT_NAME}_installables "") |
4 | 3 |
|
5 | 4 | if(SECP256K1_ASM STREQUAL "arm")
|
6 |
| - add_library(common OBJECT |
| 5 | + target_sources(secp_common_objs PRIVATE |
7 | 6 | asm/field_10x26_arm.s
|
8 | 7 | )
|
9 |
| - set(common_obj "$<TARGET_OBJECTS:common>") |
10 |
| -else() |
11 |
| - set(common_obj "") |
12 | 8 | endif()
|
13 | 9 |
|
14 |
| -add_library(precomputed OBJECT |
| 10 | +add_library(secp_precomputed_objs OBJECT EXCLUDE_FROM_ALL |
15 | 11 | precomputed_ecmult.c
|
16 | 12 | precomputed_ecmult_gen.c
|
17 | 13 | )
|
18 |
| -set(internal_obj "$<TARGET_OBJECTS:precomputed>" "${common_obj}") |
19 | 14 |
|
20 |
| -add_library(secp256k1 SHARED EXCLUDE_FROM_ALL |
21 |
| - secp256k1.c |
22 |
| - ${internal_obj} |
| 15 | +add_library(secp_common_objs OBJECT EXCLUDE_FROM_ALL secp256k1.c) |
| 16 | + |
| 17 | +add_library(secp_interface INTERFACE) |
| 18 | +target_link_libraries(secp_common_objs PRIVATE secp_interface) |
| 19 | +target_link_libraries(secp_precomputed_objs PRIVATE secp_interface) |
| 20 | + |
| 21 | +# Add objects explicitly rather than linking to the object libs to keep them |
| 22 | +# from being exported. |
| 23 | +add_library(secp256k1 $<TARGET_OBJECTS:secp_precomputed_objs> $<TARGET_OBJECTS:secp_common_objs>) |
| 24 | + |
| 25 | +target_compile_definitions(secp_interface INTERFACE |
| 26 | + $<$<C_COMPILER_ID:MSVC>:_CRT_SECURE_NO_WARNINGS> |
23 | 27 | )
|
24 |
| -target_include_directories(secp256k1 INTERFACE |
| 28 | + |
| 29 | +if (BUILD_SHARED_LIBS) |
| 30 | + target_compile_definitions(secp_interface INTERFACE |
| 31 | + $<$<PLATFORM_ID:Windows>:DLL_EXPORT> |
| 32 | + ) |
| 33 | +endif() |
| 34 | + |
| 35 | +# The object libs don't know if they're being built for a shared or static lib. |
| 36 | +# Grab the PIC property from secp256k1 which knows. |
| 37 | +get_target_property(use_pic secp256k1 POSITION_INDEPENDENT_CODE) |
| 38 | +set_target_properties(secp_precomputed_objs PROPERTIES POSITION_INDEPENDENT_CODE ${use_pic}) |
| 39 | +set_target_properties(secp_common_objs PROPERTIES POSITION_INDEPENDENT_CODE ${use_pic}) |
| 40 | + |
| 41 | +target_include_directories(secp256k1 PUBLIC |
25 | 42 | $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
26 | 43 | )
|
27 |
| -target_compile_definitions(secp256k1 PRIVATE |
28 |
| - $<$<PLATFORM_ID:Windows>:DLL_EXPORT> |
29 |
| -) |
30 | 44 | set_target_properties(secp256k1 PROPERTIES
|
31 | 45 | VERSION "${${PROJECT_NAME}_LIB_VERSION_CURRENT}.${${PROJECT_NAME}_LIB_VERSION_AGE}.${${PROJECT_NAME}_LIB_VERSION_REVISION}"
|
32 | 46 | SOVERSION "${${PROJECT_NAME}_LIB_VERSION_CURRENT}"
|
33 | 47 | )
|
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 | 48 |
|
70 | 49 | if(SECP256K1_BUILD_BENCHMARK)
|
71 | 50 | 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) |
| 51 | + target_link_libraries(bench secp_common_objs secp_precomputed_objs) |
| 52 | + add_executable(bench_internal bench_internal.c) |
| 53 | + target_link_libraries(bench_internal secp_precomputed_objs) |
| 54 | + add_executable(bench_ecmult bench_ecmult.c) |
| 55 | + target_link_libraries(bench_ecmult secp_precomputed_objs) |
77 | 56 | endif()
|
78 | 57 |
|
79 | 58 | if(SECP256K1_BUILD_TESTS)
|
80 |
| - add_executable(noverify_tests tests.c ${internal_obj}) |
81 |
| - target_link_libraries(noverify_tests binary_interface) |
| 59 | + add_executable(noverify_tests tests.c) |
| 60 | + target_link_libraries(noverify_tests secp_precomputed_objs) |
82 | 61 | add_test(noverify_tests noverify_tests)
|
83 | 62 | if(NOT CMAKE_BUILD_TYPE STREQUAL "Coverage")
|
84 |
| - add_executable(tests tests.c ${internal_obj}) |
| 63 | + add_executable(tests tests.c) |
85 | 64 | target_compile_definitions(tests PRIVATE VERIFY)
|
86 |
| - target_link_libraries(tests binary_interface) |
| 65 | + target_link_libraries(tests secp_precomputed_objs) |
87 | 66 | add_test(tests tests)
|
88 | 67 | endif()
|
89 | 68 | endif()
|
90 | 69 |
|
91 | 70 | 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}) |
| 71 | + # Note: do not include secp_precomputed_objs in exhaustive_tests (it uses runtime-generated tables). |
| 72 | + add_executable(exhaustive_tests tests_exhaustive.c) |
94 | 73 | target_compile_definitions(exhaustive_tests PRIVATE $<$<NOT:$<CONFIG:Coverage>>:VERIFY>)
|
95 |
| - target_link_libraries(exhaustive_tests binary_interface) |
96 | 74 | add_test(exhaustive_tests exhaustive_tests)
|
97 | 75 | endif()
|
98 | 76 |
|
99 | 77 | if(SECP256K1_BUILD_CTIME_TESTS)
|
100 | 78 | add_executable(ctime_tests ctime_tests.c)
|
101 |
| - target_link_libraries(ctime_tests binary_interface link_library) |
| 79 | + target_link_libraries(ctime_tests secp_common_objs secp_precomputed_objs) |
102 | 80 | endif()
|
103 | 81 |
|
104 |
| -install(TARGETS ${${PROJECT_NAME}_installables} |
| 82 | +install(TARGETS secp256k1 |
105 | 83 | EXPORT ${PROJECT_NAME}-targets
|
106 | 84 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
107 | 85 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
0 commit comments