cmake, refactor: Use helper function instead of interface library

This change aims to simplify the following commit.
This commit is contained in:
Hennadii Stepanov 2023-07-14 08:41:26 +01:00
parent 907a67212e
commit cef373997c
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F

View File

@ -1,24 +1,23 @@
add_library(example INTERFACE) function(add_example name)
target_include_directories(example INTERFACE set(target_name ${name}_example)
${PROJECT_SOURCE_DIR}/include add_executable(${target_name} ${name}.c)
) target_include_directories(${target_name} PRIVATE
target_link_libraries(example INTERFACE ${PROJECT_SOURCE_DIR}/include
secp256k1 )
$<$<PLATFORM_ID:Windows>:bcrypt> target_link_libraries(${target_name}
) secp256k1
$<$<PLATFORM_ID:Windows>:bcrypt>
)
set(test_name ${name}_example)
add_test(NAME ${test_name} COMMAND ${target_name})
endfunction()
add_executable(ecdsa_example ecdsa.c) add_example(ecdsa)
target_link_libraries(ecdsa_example example)
add_test(NAME ecdsa_example COMMAND ecdsa_example)
if(SECP256K1_ENABLE_MODULE_ECDH) if(SECP256K1_ENABLE_MODULE_ECDH)
add_executable(ecdh_example ecdh.c) add_example(ecdh)
target_link_libraries(ecdh_example example)
add_test(NAME ecdh_example COMMAND ecdh_example)
endif() endif()
if(SECP256K1_ENABLE_MODULE_SCHNORRSIG) if(SECP256K1_ENABLE_MODULE_SCHNORRSIG)
add_executable(schnorr_example schnorr.c) add_example(schnorr)
target_link_libraries(schnorr_example example)
add_test(NAME schnorr_example COMMAND schnorr_example)
endif() endif()