Skip to content

Commit 374e2b5

Browse files
Merge #1290: cmake: Set ENVIRONMENT property for examples on Windows
175db31 ci: Drop no longer needed `PATH` variable update on Windows (Hennadii Stepanov) 116d2ab cmake: Set `ENVIRONMENT` property for examples on Windows (Hennadii Stepanov) cef3739 cmake, refactor: Use helper function instead of interface library (Hennadii Stepanov) Pull request description: This PR simplifies running examples on Windows, because the DLL must reside either in the same folder where the executable is or somewhere in PATH. It is an alternative to #1233. ACKs for top commit: real-or-random: utACK 175db31 Tree-SHA512: 8188018589a5bcf0179647a039cdafcce661dc103a70a5bb9e6b6f680b899332ba30b1e9ef5dad2a8c22c315d7794747e49d8cf2e391eebea21e3d8505ee334b
2 parents 1b13415 + 175db31 commit 374e2b5

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

.cirrus.yml

-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ task:
386386
cpu: 4
387387
memory: 3840MB
388388
env:
389-
PATH: '%CIRRUS_WORKING_DIR%\build\src\RelWithDebInfo;%PATH%'
390389
x64_NATIVE_TOOLS: '"C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat"'
391390
# Ignore MSBuild warning MSB8029.
392391
# See: https://learn.microsoft.com/en-us/visualstudio/msbuild/errors/msb8029?view=vs-2022

examples/CMakeLists.txt

+23-17
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,30 @@
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()
921

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)
1323

1424
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)
1826
endif()
1927

2028
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)
2430
endif()

0 commit comments

Comments
 (0)