Skip to content

Commit

Permalink
ENH: Streamline test execution setting launch environment (#1168)
Browse files Browse the repository at this point in the history
Update "simple_test" and "simple_test_with_data" macros by setting the
`ENVIRONMENT_MODIFICATION` test property using the `CTK_TEST_LAUNCH_BUILD_ENVIRONMENT_MODIFICATION`
variable.

The `CTK_TEST_LAUNCH_BUILD_ENVIRONMENT_MODIFICATION` variable now contains a list
of environment modifications for each of the variables: `PATH`, `LD_LIBRARY_PATH`,
and/or `DYLD_LIBRARY_PATH`. These modifications are based on the specified paths
and library paths associated with dependencies, including Qt and any enabled
external projects.

To simplify the collection of external project-specific "library paths" and "paths,"
these are individually defined within each external project and linked to a label
associated with the corresponding `mark_as_superbuild()` call.
  • Loading branch information
jcfr authored Jan 13, 2024
1 parent bfe6d92 commit c1d55a1
Show file tree
Hide file tree
Showing 11 changed files with 233 additions and 0 deletions.
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_MODIFICATION "${CTK_TEST_LAUNCH_BUILD_ENVIRONMENT_MODIFICATION}")

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_MODIFICATION "${CTK_TEST_LAUNCH_BUILD_ENVIRONMENT_MODIFICATION}")
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
83 changes: 83 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,89 @@ 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.22" OR ${CMAKE_VERSION} VERSION_GREATER "3.22")

# CMake 3.9 introduces support for "$<IF:...>" 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)
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.

# Location of the Qt shared libraries
if(WIN32)
get_target_property(_qt_moc_executable Qt${CTK_QT_VERSION}::moc LOCATION)
get_filename_component(_qt_installed_library_dir ${_qt_moc_executable} PATH)
else()
get_target_property(_qt_core_lib Qt${CTK_QT_VERSION}::Core LOCATION)
get_filename_component(_qt_installed_library_dir ${_qt_core_lib} PATH)
endif()

# 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 modification" specific to the build tree
set(CTK_TEST_LAUNCH_BUILD_ENVIRONMENT_MODIFICATION)

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

else()
# 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()

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

#-----------------------------------------------------------------------------
# Configure files with settings
#
Expand Down

0 comments on commit c1d55a1

Please sign in to comment.