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