From e7839bff602b30812e33bba622e536bc0f55c7f3 Mon Sep 17 00:00:00 2001 From: stevapple Date: Sun, 27 Feb 2022 16:23:07 +0800 Subject: [PATCH] Inject DLL paths on TestFoundation --- Tests/Foundation/CMakeLists.txt | 5 ++++- cmake/modules/XCTestAddTests.cmake | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Tests/Foundation/CMakeLists.txt b/Tests/Foundation/CMakeLists.txt index 8defc2106b..070d9fe0eb 100644 --- a/Tests/Foundation/CMakeLists.txt +++ b/Tests/Foundation/CMakeLists.txt @@ -179,6 +179,8 @@ add_custom_command(TARGET TestFoundation POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $ ${CMAKE_BINARY_DIR}/TestFoundation.app) +cmake_path(GET CMAKE_Swift_COMPILER PARENT_PATH Swift_LIBRARY_PATH) +# NOTE(stevapple): Path separator ; is passed as ? because it conflicts with CMake's list separator xctest_discover_tests(TestFoundation COMMAND ${CMAKE_BINARY_DIR}/TestFoundation.app/TestFoundation${CMAKE_EXECUTABLE_SUFFIX} @@ -186,4 +188,5 @@ xctest_discover_tests(TestFoundation ${CMAKE_BINARY_DIR}/TestFoundation.app PROPERTIES ENVIRONMENT - LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/TestFoundation.app:$:$:$:$) + LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/TestFoundation.app:$:$:$:$ + DLL_LIBRARY_PATH=${Swift_LIBRARY_PATH}?${CMAKE_BINARY_DIR}/bin?$?$?$?$) diff --git a/cmake/modules/XCTestAddTests.cmake b/cmake/modules/XCTestAddTests.cmake index b836c96554..d74edc1a8d 100644 --- a/cmake/modules/XCTestAddTests.cmake +++ b/cmake/modules/XCTestAddTests.cmake @@ -1,6 +1,7 @@ -set(properties ${TEST_PROPERTIES}) +set(properties "${TEST_PROPERTIES}") set(script) set(tests) +set(dll_library_path) function(add_command NAME) set(_args "") @@ -21,7 +22,7 @@ if(NOT EXISTS "${TEST_EXECUTABLE}") ) endif() # We need to figure out if some environment is needed to run the test listing. -cmake_parse_arguments("_properties" "" "ENVIRONMENT" "" ${properties}) +cmake_parse_arguments("_properties" "" "" "ENVIRONMENT" ${properties}) if(_properties_ENVIRONMENT) foreach(_env ${_properties_ENVIRONMENT}) string(REGEX REPLACE "([a-zA-Z0-9_]+)=(.*)" "\\1" _key "${_env}") @@ -31,6 +32,13 @@ if(_properties_ENVIRONMENT) endif() endforeach() endif() +# Set Path to avoid DLL missing +if (DEFINED ENV{DLL_LIBRARY_PATH} AND CMAKE_HOST_SYSTEM_NAME STREQUAL Windows) + string(REPLACE "?" ";" dll_library_path "$ENV{DLL_LIBRARY_PATH}") + set(ENV{Path} "${dll_library_path};$ENV{Path}") + string(REPLACE ";" "\\\\;" dll_library_path "${dll_library_path}") +endif() + execute_process( COMMAND "${TEST_EXECUTABLE}" --list-tests WORKING_DIRECTORY "${TEST_WORKING_DIR}" @@ -75,6 +83,13 @@ foreach(line ${output}) WORKING_DIRECTORY "${TEST_WORKING_DIR}" ${properties} ) + if (NOT "${dll_library_path}" STREQUAL "") + add_command(set_tests_properties + "${pretty_target}" + PROPERTIES + ENVIRONMENT "Path=${dll_library_path}" + ) + endif() list(APPEND tests "${pretty_target}") else() message(FATAL_ERROR