Skip to content

Commit

Permalink
CMake test_install: Path Handling
Browse files Browse the repository at this point in the history
Improve path handling of executed test binary inputs file & output.
  • Loading branch information
ax3l committed Mar 15, 2024
1 parent 8753a15 commit 1d4ddd7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion Tests/CMakeTestInstall/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,15 @@ foreach(D IN LISTS AMReX_SPACEDIM)
${_input_dir}/Prob.H
)

file(TO_NATIVE_PATH "${_input_dir}/inputs" inputs_path)

add_custom_command(
TARGET install_test_${D}d
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Running test project"
COMMAND $<TARGET_FILE:install_test_${D}d> ${_input_dir}/inputs max_step=1 > out_${D}d.txt
COMMAND ${CMAKE_COMMAND} -E echo "Command: $<TARGET_FILE:install_test_${D}d> ${inputs_path} max_step=1"
COMMAND $<TARGET_FILE:install_test_${D}d> ${inputs_path} max_step=1
# > out_${D}d.txt
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
endforeach()
12 changes: 11 additions & 1 deletion Tools/CMake/AMReXInstallHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,28 @@ endfunction ()
# _amrex_root is the amrex installation dir
#
macro( add_test_install_target _dir _amrex_root )
# Multi-Config generators such as Visual Studio or Ninja Multi-Config
# select the build type at build time. Others (GNUmake, Ninja, ...) select
# the build type at configure time.
get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
set(_select_config)
set(_select_bldtype)
if(isMultiConfig)
set(_select_config "--config $<CONFIG>")
else()
set(_select_bldtype "-DCMAKE_BUILD_TYPE=$<CONFIG>")
endif()

# Fortran compiler used?
get_filename_component( _dirname ${_dir} NAME )
set(_builddir ${CMAKE_CURRENT_BINARY_DIR}/${_dirname})
set(_enable_fortran)
if(AMReX_FORTRAN)
set(_enable_fortran -DCMAKE_Fortran_COMPILER=${CMAKE_Fortran_COMPILER})
endif()

# Configure and Build
# A registered POST_BUILD target in Tests/CMakeTestInstall will then also run the test.
add_custom_target(test_install
COMMAND ${CMAKE_COMMAND} -E echo ""
COMMAND ${CMAKE_COMMAND} -E echo "------------------------------------"
Expand All @@ -155,7 +165,7 @@ macro( add_test_install_target _dir _amrex_root )
COMMAND ${CMAKE_COMMAND} -E echo ""
COMMAND ${CMAKE_COMMAND} -E make_directory ${_builddir}
COMMAND ${CMAKE_COMMAND} -E echo "Configuring test project"
COMMAND ${CMAKE_COMMAND} -S ${_dir} -B ${_builddir} -DCMAKE_BUILD_TYPE=$<CONFIG> -DAMReX_ROOT=${_amrex_root} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} ${_enable_fortran}
COMMAND ${CMAKE_COMMAND} -S ${_dir} -B ${_builddir} ${_select_bldtype} -DAMReX_ROOT=${_amrex_root} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} ${_enable_fortran}
COMMAND ${CMAKE_COMMAND} -E echo "Building test project"
COMMAND ${CMAKE_COMMAND} --build ${_builddir} ${_select_config}
COMMAND ${CMAKE_COMMAND} -E echo ""
Expand Down

0 comments on commit 1d4ddd7

Please sign in to comment.