Skip to content

Commit d4420fb

Browse files
committed
Inject DLL paths on TestFoundation
1 parent 2ab55d9 commit d4420fb

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

Tests/Foundation/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,14 @@ add_custom_command(TARGET TestFoundation POST_BUILD
179179
COMMAND
180180
${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:FoundationXML> ${CMAKE_BINARY_DIR}/TestFoundation.app)
181181

182+
cmake_path(GET CMAKE_Swift_COMPILER PARENT_PATH Swift_LIBRARY_PATH)
183+
# NOTE(stevapple): Path separator ; is passed as ? because it conflicts with CMake's list separator
182184
xctest_discover_tests(TestFoundation
183185
COMMAND
184186
${CMAKE_BINARY_DIR}/TestFoundation.app/TestFoundation${CMAKE_EXECUTABLE_SUFFIX}
185187
WORKING_DIRECTORY
186188
${CMAKE_BINARY_DIR}/TestFoundation.app
187189
PROPERTIES
188190
ENVIRONMENT
189-
LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/TestFoundation.app:$<TARGET_LINKER_FILE_DIR:XCTest>:$<TARGET_LINKER_FILE_DIR:dispatch>:$<TARGET_LINKER_FILE_DIR:swiftDispatch>:$<TARGET_LINKER_FILE_DIR:BlocksRuntime>)
191+
LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/TestFoundation.app:$<TARGET_LINKER_FILE_DIR:XCTest>:$<TARGET_LINKER_FILE_DIR:dispatch>:$<TARGET_LINKER_FILE_DIR:swiftDispatch>:$<TARGET_LINKER_FILE_DIR:BlocksRuntime>
192+
DLL_LIBRARY_PATH=${Swift_LIBRARY_PATH}?${CMAKE_BINARY_DIR}/bin?$<TARGET_FILE_DIR:XCTest>?$<TARGET_FILE_DIR:dispatch>)

cmake/modules/XCTestAddTests.cmake

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
set(properties ${TEST_PROPERTIES})
1+
set(properties "${TEST_PROPERTIES}")
22
set(script)
33
set(tests)
44

@@ -21,7 +21,7 @@ if(NOT EXISTS "${TEST_EXECUTABLE}")
2121
)
2222
endif()
2323
# We need to figure out if some environment is needed to run the test listing.
24-
cmake_parse_arguments("_properties" "" "ENVIRONMENT" "" ${properties})
24+
cmake_parse_arguments("_properties" "" "" "ENVIRONMENT" ${properties})
2525
if(_properties_ENVIRONMENT)
2626
foreach(_env ${_properties_ENVIRONMENT})
2727
string(REGEX REPLACE "([a-zA-Z0-9_]+)=(.*)" "\\1" _key "${_env}")
@@ -31,6 +31,13 @@ if(_properties_ENVIRONMENT)
3131
endif()
3232
endforeach()
3333
endif()
34+
# Set Path to avoid DLL missing
35+
if (CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
36+
string(REPLACE "?" ";" DLL_LIBRARY_PATH "$ENV{DLL_LIBRARY_PATH}")
37+
set(ENV{Path} "${DLL_LIBRARY_PATH};$ENV{Path}")
38+
string(REPLACE ";" "\\\\;" DLL_LIBRARY_PATH "${DLL_LIBRARY_PATH}")
39+
endif()
40+
3441
execute_process(
3542
COMMAND "${TEST_EXECUTABLE}" --list-tests
3643
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
@@ -75,6 +82,13 @@ foreach(line ${output})
7582
WORKING_DIRECTORY "${TEST_WORKING_DIR}"
7683
${properties}
7784
)
85+
if (CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
86+
add_command(set_tests_properties
87+
"${pretty_target}"
88+
PROPERTIES
89+
ENVIRONMENT "Path=${DLL_LIBRARY_PATH}"
90+
)
91+
endif()
7892
list(APPEND tests "${pretty_target}")
7993
else()
8094
message(FATAL_ERROR

0 commit comments

Comments
 (0)