From b3586a7f9b50c69a9d9f0370c309a720edf3eb1a Mon Sep 17 00:00:00 2001 From: Dave Abrahams Date: Mon, 4 Mar 2024 17:26:25 -0800 Subject: [PATCH] Try using fancy environment modification features. (#3) Clearly a win for the second case. Not so much for the first. Switched to SHELL_PATH for clarity. https://discourse.cmake.org/t/variables-for-cross-platform-code/10115/8 --- cmake/modules/FindSwiftXCTest.cmake | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/cmake/modules/FindSwiftXCTest.cmake b/cmake/modules/FindSwiftXCTest.cmake index 664e628..9ae98a2 100644 --- a/cmake/modules/FindSwiftXCTest.cmake +++ b/cmake/modules/FindSwiftXCTest.cmake @@ -127,7 +127,7 @@ function(add_swift_xctest test_target testee) # 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=$;$ENV{PATH},;>" + "PATH=$;$ENV{PATH}>" -- $ -o ${test_main} ${sources} DEPENDS ${sources} GenerateXCTestMain @@ -141,16 +141,10 @@ function(add_swift_xctest test_target testee) add_test(NAME ${test_target} COMMAND ${test_target}) - # When $ENV{PATH} is interpreted as a list on Windows, trailing backslashes in elements - # (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=$;${path},\\;>") + PROPERTIES ENVIRONMENT_MODIFICATION + # For each DLL dependency X, make the PATH=path_list_prepend:X environment modification. + "$,PREPEND,PATH=path_list_prepend:>") endif()