|
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 |
| -) |
| 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 | + set(test_name ${name}_example) |
| 12 | + add_test(NAME ${test_name} COMMAND ${target_name}) |
| 13 | + if(BUILD_SHARED_LIBS AND MSVC) |
| 14 | + # The DLL must reside either in the same folder where the executable is |
| 15 | + # or somewhere in PATH. Using the latter option. |
| 16 | + set_tests_properties(${test_name} PROPERTIES |
| 17 | + ENVIRONMENT "PATH=$<TARGET_FILE_DIR:secp256k1>;$ENV{PATH}" |
| 18 | + ) |
| 19 | + endif() |
| 20 | +endfunction() |
9 | 21 |
|
10 |
| -add_executable(ecdsa_example ecdsa.c) |
11 |
| -target_link_libraries(ecdsa_example example) |
12 |
| -add_test(NAME ecdsa_example COMMAND ecdsa_example) |
| 22 | +add_example(ecdsa) |
13 | 23 |
|
14 | 24 | if(SECP256K1_ENABLE_MODULE_ECDH)
|
15 |
| - add_executable(ecdh_example ecdh.c) |
16 |
| - target_link_libraries(ecdh_example example) |
17 |
| - add_test(NAME ecdh_example COMMAND ecdh_example) |
| 25 | + add_example(ecdh) |
18 | 26 | endif()
|
19 | 27 |
|
20 | 28 | if(SECP256K1_ENABLE_MODULE_SCHNORRSIG)
|
21 |
| - add_executable(schnorr_example schnorr.c) |
22 |
| - target_link_libraries(schnorr_example example) |
23 |
| - add_test(NAME schnorr_example COMMAND schnorr_example) |
| 29 | + add_example(schnorr) |
24 | 30 | endif()
|
0 commit comments