Skip to content

Commit

Permalink
ENH: Streamline test execution setting launch environment
Browse files Browse the repository at this point in the history
Update "simple_test" and "simple_test_with_data" macros settings
the `ENVIRONMENT` test property using `CTK_TEST_LAUNCH_BUILD_ENVIRONMENT`
variable.

Set `CTK_TEST_LAUNCH_BUILD_ENVIRONMENT` variable defines the environment
variables `PATH`, `LD_LIBRARY_PATH` and/or `DYLD_LIBRARY_PATH` based on
the list of paths and library paths associated with dependencies. This
includes Qt and any enabled external projects.

To streamline the process of gathering external project-specific "library paths"
and "paths", these are now individually defined within each external project
and linked to a label associated with the corresponding `mark_as_superbuild()`
call.
  • Loading branch information
jcfr committed Jan 13, 2024
1 parent bfe6d92 commit 9c609db
Show file tree
Hide file tree
Showing 12 changed files with 218 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CMake/ctkMacroSimpleTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@ macro(SIMPLE_TEST testname)

add_test(NAME ${testname} COMMAND $<TARGET_FILE:${KIT}CppTests> ${testname} ${ARGN})
set_property(TEST ${testname} PROPERTY LABELS ${KIT})

set_property(TEST ${testname} PROPERTY ENVIRONMENT "${CTK_TEST_LAUNCH_BUILD_ENVIRONMENT}")

endmacro()

2 changes: 2 additions & 0 deletions CMake/ctkMacroSimpleTestWithData.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,7 @@ macro(SIMPLE_TEST_WITH_DATA testname baseline_relative_location)
${ARGN}
)
set_property(TEST ${testname} PROPERTY LABELS ${KIT})

set_property(TEST ${testname} PROPERTY ENVIRONMENT "${CTK_TEST_LAUNCH_BUILD_ENVIRONMENT}")
endmacro()

27 changes: 27 additions & 0 deletions CMakeExternals/DCMTK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,33 @@ if(NOT DEFINED DCMTK_DIR AND NOT ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
)
set(DCMTK_DIR ${CMAKE_CURRENT_BINARY_DIR}/${proj}-build)

#-----------------------------------------------------------------------------
# Launcher setting specific to build tree

set(_lib_subdir lib)
if(WIN32)
set(_lib_subdir bin)
endif()

# library paths
set(${proj}_LIBRARY_PATHS_LAUNCHER_BUILD ${DCMTK_DIR}/${_lib_subdir}/<CMAKE_CFG_INTDIR>)
mark_as_superbuild(
VARS ${proj}_LIBRARY_PATHS_LAUNCHER_BUILD
LABELS "LIBRARY_PATHS_LAUNCHER_BUILD"
)

# paths
set(${proj}_PATHS_LAUNCHER_BUILD ${DCMTK_DIR}/bin/<CMAKE_CFG_INTDIR>)
mark_as_superbuild(
VARS ${proj}_PATHS_LAUNCHER_BUILD
LABELS "PATHS_LAUNCHER_BUILD"
)

#-----------------------------------------------------------------------------
# Launcher setting specific to install tree

# NA

else()
ExternalProject_Add_Empty(${proj} DEPENDS ${${proj}_DEPENDENCIES})
endif()
Expand Down
20 changes: 20 additions & 0 deletions CMakeExternals/ITK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ if(NOT DEFINED ITK_DIR AND NOT ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
)
set(ITK_DIR ${CMAKE_BINARY_DIR}/${proj}-build)

#-----------------------------------------------------------------------------
# Launcher setting specific to build tree

set(_lib_subdir lib)
if(WIN32)
set(_lib_subdir bin)
endif()

# library paths
set(${proj}_LIBRARY_PATHS_LAUNCHER_BUILD ${ITK_DIR}/${_lib_subdir}/<CMAKE_CFG_INTDIR>)
mark_as_superbuild(
VARS ${proj}_LIBRARY_PATHS_LAUNCHER_BUILD
LABELS "LIBRARY_PATHS_LAUNCHER_BUILD"
)

#-----------------------------------------------------------------------------
# Launcher setting specific to install tree

# NA

else()
ExternalProject_Add_Empty(${proj} DEPENDS ${${proj}_DEPENDENCIES})
endif()
Expand Down
17 changes: 17 additions & 0 deletions CMakeExternals/Log4Qt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ if(NOT DEFINED Log4Qt_DIR)
set(Log4Qt_INSTALL_DIR ${ep_install_dir})
set(Log4Qt_DIR ${Log4Qt_INSTALL_DIR}/lib/cmake/Log4Qt/)

#-----------------------------------------------------------------------------
# Launcher setting specific to build tree

set(_lib_subdir bin)

# library paths
set(${proj}_LIBRARY_PATHS_LAUNCHER_BUILD ${CMAKE_BINARY_DIR}/${proj}-build/${_lib_subdir}/<CMAKE_CFG_INTDIR>)
mark_as_superbuild(
VARS ${proj}_LIBRARY_PATHS_LAUNCHER_BUILD
LABELS "LIBRARY_PATHS_LAUNCHER_BUILD"
)

#-----------------------------------------------------------------------------
# Launcher setting specific to install tree

# NA

else()
ExternalProject_Add_Empty(${proj} DEPENDS ${${proj}_DEPENDENCIES})
endif()
Expand Down
15 changes: 15 additions & 0 deletions CMakeExternals/PythonQt.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ if(NOT DEFINED PYTHONQT_INSTALL_DIR)
)
set(PYTHONQT_INSTALL_DIR ${ep_install_dir})

#-----------------------------------------------------------------------------
# Launcher setting specific to build tree

# library paths
set(${proj}_LIBRARY_PATHS_LAUNCHER_BUILD ${CMAKE_BINARY_DIR}/${proj}/<CMAKE_CFG_INTDIR>)
mark_as_superbuild(
VARS ${proj}_LIBRARY_PATHS_LAUNCHER_BUILD
LABELS "LIBRARY_PATHS_LAUNCHER_BUILD"
)

#-----------------------------------------------------------------------------
# Launcher setting specific to install tree

# NA

else()
ExternalProject_Add_Empty(${proj} DEPENDS ${${proj}_DEPENDENCIES})
endif()
Expand Down
17 changes: 17 additions & 0 deletions CMakeExternals/QtSOAP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ if(NOT DEFINED QtSOAP_DIR)
)
set(QtSOAP_DIR "${CMAKE_BINARY_DIR}/${proj}-build")

#-----------------------------------------------------------------------------
# Launcher setting specific to build tree

set(_lib_subdir bin)

# library paths
set(${proj}_LIBRARY_PATHS_LAUNCHER_BUILD ${QtSOAP_DIR}/${_lib_subdir}/<CMAKE_CFG_INTDIR>)
mark_as_superbuild(
VARS ${proj}_LIBRARY_PATHS_LAUNCHER_BUILD
LABELS "LIBRARY_PATHS_LAUNCHER_BUILD"
)

#-----------------------------------------------------------------------------
# Launcher setting specific to install tree

# NA

else()
ExternalProject_Add_Empty(${proj} DEPENDS ${${proj}_DEPENDENCIES})
endif()
Expand Down
15 changes: 15 additions & 0 deletions CMakeExternals/QtTesting.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ if(NOT DEFINED QtTesting_DIR)
set(QtTesting_INSTALL_DIR ${ep_install_dir})
set(QtTesting_DIR ${CMAKE_BINARY_DIR}/${proj}-build)

#-----------------------------------------------------------------------------
# Launcher setting specific to build tree

# library paths
set(${proj}_LIBRARY_PATHS_LAUNCHER_BUILD ${QtTesting_DIR}/<CMAKE_CFG_INTDIR>)
mark_as_superbuild(
VARS ${proj}_LIBRARY_PATHS_LAUNCHER_BUILD
LABELS "LIBRARY_PATHS_LAUNCHER_BUILD"
)

#-----------------------------------------------------------------------------
# Launcher setting specific to install tree

# NA

else()
ExternalProject_Add_Empty(${proj} DEPENDS ${${proj}_DEPENDENCIES})
endif()
Expand Down
19 changes: 19 additions & 0 deletions CMakeExternals/VTK.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,25 @@ if(NOT DEFINED VTK_DIR AND NOT ${CMAKE_PROJECT_NAME}_USE_SYSTEM_${proj})
)
set(VTK_DIR ${CMAKE_BINARY_DIR}/${proj}-build)

#-----------------------------------------------------------------------------
# Launcher setting specific to build tree

# library paths
set(_library_output_subdir bin)
if(UNIX)
set(_library_output_subdir lib)
endif()
set(${proj}_LIBRARY_PATHS_LAUNCHER_BUILD ${VTK_DIR}/${_library_output_subdir}/<CMAKE_CFG_INTDIR>)
mark_as_superbuild(
VARS ${proj}_LIBRARY_PATHS_LAUNCHER_BUILD
LABELS "LIBRARY_PATHS_LAUNCHER_BUILD"
)

#-----------------------------------------------------------------------------
# Launcher setting specific to install tree

# NA

else()
ExternalProject_Add_Empty(${proj} DEPENDS ${${proj}_DEPENDENCIES})
endif()
Expand Down
15 changes: 15 additions & 0 deletions CMakeExternals/qRestAPI.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ if(NOT DEFINED ${proj}_DIR)
)
set(qRestAPI_DIR ${CMAKE_CURRENT_BINARY_DIR}/${proj}-build)

#-----------------------------------------------------------------------------
# Launcher setting specific to build tree

# library paths
set(${proj}_LIBRARY_PATHS_LAUNCHER_BUILD ${qRestAPI_DIR}/<CMAKE_CFG_INTDIR>)
mark_as_superbuild(
VARS ${proj}_LIBRARY_PATHS_LAUNCHER_BUILD
LABELS "LIBRARY_PATHS_LAUNCHER_BUILD"
)

#-----------------------------------------------------------------------------
# Launcher setting specific to install tree

# NA

else()
ExternalProject_Add_Empty(${proj} DEPENDS ${${proj}_DEPENDENCIES})
endif()
Expand Down
67 changes: 67 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,73 @@ if(NOT DEFINED CTK_SUPERBUILD_BINARY_DIR)
set(CTK_SUPERBUILD_BINARY_DIR ${CTK_BINARY_DIR})
endif()

#-----------------------------------------------------------------------------
# Configure test launcher environment variables for the build tree

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")

# CMake 3.9 introduces support for "$<IF:...>" generator expression
# and GENERATOR_IS_MULTI_CONFIG property.

# Generate expression evaluating to the current build configuration or "."
# for single configuration generator
get_property(_isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
set(_cfg_intdir $<IF:${_isMultiConfig},$<CONFIG>,.>)

# Collect "library paths" and "paths" defined in external projects.
# Values for each are retrieved based on the label associated with the
# corresponding `mark_as_superbuild()` call used in each external project.

# Library paths
set(CTK_LIBRARY_PATHS_LAUNCHER_BUILD
${QT_INSTALLED_LIBRARY_DIR}
)
foreach(varname IN LISTS CTK_EP_LABEL_LIBRARY_PATHS_LAUNCHER_BUILD)
set(value ${${varname}})
list(TRANSFORM value REPLACE "<CMAKE_CFG_INTDIR>" "${_cfg_intdir}")
list(APPEND CTK_LIBRARY_PATHS_LAUNCHER_BUILD ${value})
endforeach()

# Paths
set(CTK_PATHS_LAUNCHER_BUILD)
foreach(varname IN LISTS CTK_EP_LABEL_PATHS_LAUNCHER_BUILD)
set(value ${${varname}})
list(TRANSFORM value REPLACE "<CMAKE_CFG_INTDIR>" "${_cfg_intdir}")
list(APPEND CTK_PATHS_LAUNCHER_BUILD ${value})
endforeach()

# Set test launch environment specific to the build tree
if(WIN32)
# On Windows, concatenate the build and library paths directly since a list in CMake
# is a ; separated group of strings.
set(separator ";")
set(env_paths "${CTK_PATHS_LAUNCHER_BUILD};${CTK_LIBRARY_PATHS_LAUNCHER_BUILD}")

set(CTK_TEST_LAUNCH_BUILD_ENVIRONMENT
"PATH=${env_paths}${separator}$ENV{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)

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}}"
)
endif()
endif()

#-----------------------------------------------------------------------------
# Configure files with settings
#
Expand Down
2 changes: 1 addition & 1 deletion Libs/DICOM/Widgets/Testing/Cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
set_property(TEST ctkDICOMBrowserTest PROPERTY ENVIRONMENT "CTKData_DIR=${CTKData_DIR}" APPEND)
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)
Expand Down

0 comments on commit 9c609db

Please sign in to comment.