diff --git a/CMake/ctkMacroSimpleTest.cmake b/CMake/ctkMacroSimpleTest.cmake index 67dcf6b2dd..5817f75966 100644 --- a/CMake/ctkMacroSimpleTest.cmake +++ b/CMake/ctkMacroSimpleTest.cmake @@ -31,7 +31,7 @@ macro(SIMPLE_TEST testname) add_test(NAME ${testname} COMMAND $ ${testname} ${ARGN}) set_property(TEST ${testname} PROPERTY LABELS ${KIT}) - set_property(TEST ${testname} PROPERTY ENVIRONMENT "${CTK_TEST_LAUNCH_BUILD_ENVIRONMENT}") + set_property(TEST ${testname} PROPERTY ENVIRONMENT_MODIFICATION "${CTK_TEST_LAUNCH_BUILD_ENVIRONMENT_MODIFICATION}") endmacro() diff --git a/CMake/ctkMacroSimpleTestWithData.cmake b/CMake/ctkMacroSimpleTestWithData.cmake index 373656760e..4c8734e7e9 100644 --- a/CMake/ctkMacroSimpleTestWithData.cmake +++ b/CMake/ctkMacroSimpleTestWithData.cmake @@ -61,6 +61,6 @@ macro(SIMPLE_TEST_WITH_DATA testname baseline_relative_location) ) set_property(TEST ${testname} PROPERTY LABELS ${KIT}) - set_property(TEST ${testname} PROPERTY ENVIRONMENT "${CTK_TEST_LAUNCH_BUILD_ENVIRONMENT}") + set_property(TEST ${testname} PROPERTY ENVIRONMENT_MODIFICATION "${CTK_TEST_LAUNCH_BUILD_ENVIRONMENT_MODIFICATION}") endmacro() diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c48fb717b..8b067f12e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1065,11 +1065,13 @@ set(CTK_PATHS_LAUNCHER_BUILD ) set(CTK_LIBRARY_PATHS_LAUNCHER_BUILD ) set(CTK_TEST_LAUNCH_BUILD_ENVIRONMENT ) -if(${CMAKE_VERSION} VERSION_EQUAL "3.9" OR ${CMAKE_VERSION} VERSION_GREATER "3.9") +if(${CMAKE_VERSION} VERSION_EQUAL "3.22" OR ${CMAKE_VERSION} VERSION_GREATER "3.22") # CMake 3.9 introduces support for "$" generator expression # and GENERATOR_IS_MULTI_CONFIG property. + # CMake 3.22 introduces support for ENVIRONMENT_MODIFICATION test property. + # Generate expression evaluating to the current build configuration or "." # for single configuration generator get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) @@ -1106,32 +1108,36 @@ if(${CMAKE_VERSION} VERSION_EQUAL "3.9" OR ${CMAKE_VERSION} VERSION_GREATER "3.9 list(APPEND CTK_PATHS_LAUNCHER_BUILD ${value}) endforeach() - # Set test launch environment specific to the build tree - if(WIN32) - # On Windows, create semicolon-separated strings for paths and library paths - set(separator "$") - ctk_list_to_string(${separator} "${CTK_PATHS_LAUNCHER_BUILD};${CTK_LIBRARY_PATHS_LAUNCHER_BUILD}" env_paths) + # Set test launch "environment modification" specific to the build tree + set(CTK_TEST_LAUNCH_BUILD_ENVIRONMENT_MODIFICATION) - string(REPLACE ";" "${separator}" sanitized_current_path "$ENV{PATH}") + if(WIN32) + # Paths and Library paths + foreach(value IN LISTS CTK_PATHS_LAUNCHER_BUILD CTK_LIBRARY_PATHS_LAUNCHER_BUILD) + list(APPEND CTK_TEST_LAUNCH_BUILD_ENVIRONMENT_MODIFICATION + "PATH=path_list_prepend:${value}" + ) + endforeach() - set(CTK_TEST_LAUNCH_BUILD_ENVIRONMENT - "PATH=${env_paths}${separator}${sanitized_current_path}" - ) else() - # On UNIX-like systems, create colon-separated strings for paths and library paths - set(separator ":") - ctk_list_to_string(${separator} "${CTK_PATHS_LAUNCHER_BUILD}" env_paths) - ctk_list_to_string(${separator} "${CTK_LIBRARY_PATHS_LAUNCHER_BUILD}" env_library_paths) + # Path + foreach(value IN LISTS CTK_PATHS_LAUNCHER_BUILD) + list(APPEND CTK_TEST_LAUNCH_BUILD_ENVIRONMENT_MODIFICATION + "PATH=path_list_prepend:${value}" + ) + endforeach() + # Library paths set(variable_name "LD_LIBRARY_PATH") if(APPLE) set(variable_name "DYLD_LIBRARY_PATH") endif() - set(CTK_TEST_LAUNCH_BUILD_ENVIRONMENT - "PATH=${env_paths}${separator}$ENV{PATH}" - "${variable_name}=${env_library_paths}${separator}$ENV{${variable_name}}" - ) + foreach(value IN LISTS CTK_LIBRARY_PATHS_LAUNCHER_BUILD) + list(APPEND CTK_TEST_LAUNCH_BUILD_ENVIRONMENT_MODIFICATION + "${variable_name}=path_list_prepend:${value}" + ) + endforeach() endif() endif() diff --git a/Libs/DICOM/Widgets/Testing/Cpp/CMakeLists.txt b/Libs/DICOM/Widgets/Testing/Cpp/CMakeLists.txt index 15da9b683d..8434d43437 100644 --- a/Libs/DICOM/Widgets/Testing/Cpp/CMakeLists.txt +++ b/Libs/DICOM/Widgets/Testing/Cpp/CMakeLists.txt @@ -67,7 +67,7 @@ SIMPLE_TEST(ctkDICOMThumbnailListWidgetTest1 if(EXISTS "${CTKData_DIR}") SIMPLE_TEST(ctkDICOMAppWidgetTest1 ${CTKData_DIR}/Data/DICOM/MRHEAD) SIMPLE_TEST(ctkDICOMBrowserTest) - set_property(TEST ctkDICOMBrowserTest PROPERTY ENVIRONMENT "CTKData_DIR=${CTKData_DIR}" APPEND) + set_property(TEST ctkDICOMBrowserTest PROPERTY ENVIRONMENT "CTKData_DIR=${CTKData_DIR}") SIMPLE_TEST(ctkDICOMBrowserTest1 ${CTKData_DIR}/Data/DICOM/MRHEAD) SIMPLE_TEST(ctkDICOMItemViewTest1 ${CTKData_DIR}/Data/DICOM/MRHEAD/000055.IMA) SIMPLE_TEST(ctkDICOMImageTest1 ${CTKData_DIR}/Data/DICOM/MRHEAD/000055.IMA)