Skip to content

Commit

Permalink
Try using fancy environment modification features.
Browse files Browse the repository at this point in the history
  • Loading branch information
dabrahams committed Mar 4, 2024
1 parent 37efaa0 commit 0e54d89
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions cmake/modules/FindSwiftXCTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ function(add_swift_xctest test_target testee)
# If the executable target depends on DLLs their directories need to be injected into the PATH
# or they won't be found and the target will fail to run, so invoke it through cmake. Because
COMMAND
${CMAKE_COMMAND} -E env
"PATH=$<JOIN:$<TARGET_RUNTIME_DLL_DIRS:GenerateXCTestMain>;$ENV{PATH},;>"
${CMAKE_COMMAND} -E env --modify
"$<LIST:TRANSFORM,$<TARGET_RUNTIME_DLL_DIRS:GenerateXCTestMain>,PREPEND,PATH=>"
--
$<TARGET_FILE:GenerateXCTestMain> -o ${test_main} ${sources}
DEPENDS ${sources} GenerateXCTestMain
Expand All @@ -145,12 +145,9 @@ function(add_swift_xctest test_target testee)
# (e.g. "C:\path\to\foo\;C:\another\path\...") will end up causing semicolons to be escaped.
string(REPLACE "\\" "/" path "$ENV{PATH}")

# Escape the semicolons when forming the environment setting. As explained in
# https://stackoverflow.com/a/59866840/125349, “this is not the last place the list will be used
# (and interpreted by CMake). [It] is then used to populate CTestTestfile.cmake, which is later
# read by CTest to setup your test environment.”
set_tests_properties(${test_target}
PROPERTIES ENVIRONMENT "PATH=$<JOIN:$<TARGET_RUNTIME_DLL_DIRS:${test_target}>;${path},\\;>")
PROPERTIES ENVIRONMENT_MODIFICATION
"$<LIST:TRANSFORM,$<TARGET_RUNTIME_DLL_DIRS:${test_target}>,PREPEND,PATH=>")

endif()

Expand Down

0 comments on commit 0e54d89

Please sign in to comment.