|
1 |
| -add_library(example INTERFACE) |
2 |
| -target_include_directories(example INTERFACE |
3 |
| - ${PROJECT_SOURCE_DIR}/include |
4 |
| -) |
5 |
| -target_link_libraries(example INTERFACE |
6 |
| - secp256k1 |
7 |
| - $<$<PLATFORM_ID:Windows>:bcrypt> |
8 |
| -) |
9 |
| -if(NOT BUILD_SHARED_LIBS AND MSVC) |
10 |
| - target_link_options(example INTERFACE /IGNORE:4217) |
11 |
| -endif() |
| 1 | +function(add_example name) |
| 2 | + set(target_name ${name}_example) |
| 3 | + add_executable(${target_name} ${name}.c) |
| 4 | + target_include_directories(${target_name} PRIVATE |
| 5 | + ${PROJECT_SOURCE_DIR}/include |
| 6 | + ) |
| 7 | + target_link_libraries(${target_name} |
| 8 | + secp256k1 |
| 9 | + $<$<PLATFORM_ID:Windows>:bcrypt> |
| 10 | + ) |
| 11 | + if(NOT BUILD_SHARED_LIBS AND MSVC) |
| 12 | + # We pass /IGNORE:4217 to the MSVC linker to suppress warning 4217 when |
| 13 | + # importing variables from a statically linked secp256k1. |
| 14 | + # (See the Libtool manual, section "Windows DLLs" for background.) |
| 15 | + target_link_options(${target_name} INTERFACE /IGNORE:4217) |
| 16 | + endif() |
| 17 | + |
| 18 | + set(test_name ${name}_example) |
| 19 | + add_test(NAME ${test_name} COMMAND ${target_name}) |
| 20 | +endfunction() |
12 | 21 |
|
13 |
| -add_executable(ecdsa_example ecdsa.c) |
14 |
| -target_link_libraries(ecdsa_example example) |
15 |
| -add_test(NAME ecdsa_example COMMAND ecdsa_example) |
| 22 | +add_example(ecdsa) |
16 | 23 |
|
17 | 24 | if(SECP256K1_ENABLE_MODULE_ECDH)
|
18 |
| - add_executable(ecdh_example ecdh.c) |
19 |
| - target_link_libraries(ecdh_example example) |
20 |
| - add_test(NAME ecdh_example COMMAND ecdh_example) |
| 25 | + add_example(ecdh) |
21 | 26 | endif()
|
22 | 27 |
|
23 | 28 | if(SECP256K1_ENABLE_MODULE_SCHNORRSIG)
|
24 |
| - add_executable(schnorr_example schnorr.c) |
25 |
| - target_link_libraries(schnorr_example example) |
26 |
| - add_test(NAME schnorr_example COMMAND schnorr_example) |
| 29 | + add_example(schnorr) |
27 | 30 | endif()
|
0 commit comments