Skip to content

Commit 9f297b9

Browse files
authored
CMake: add test_install (AMReX-Codes#1894)
* CMake: add test_install * CMake: forgot to add test dir * CMake: specify compiler to use when running test_install * Update Doc
1 parent 146fc57 commit 9f297b9

File tree

5 files changed

+105
-1
lines changed

5 files changed

+105
-1
lines changed

.github/workflows/linux.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
-DCMAKE_CXX_STANDARD=17
2424
make -j 2
2525
make install
26+
make test_install
2627
2728
export PATH=/tmp/my-amrex/bin:$PATH
2829
which fcompare
@@ -54,6 +55,7 @@ jobs:
5455
-DCMAKE_Fortran_COMPILER=$(which gfortran)
5556
make -j 2
5657
make install
58+
make test_install
5759
5860
export PATH=/tmp/my-amrex/bin:$PATH
5961
which fcompare

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,13 @@ endif ()
136136
if(AMReX_INSTALL)
137137
include(AMReXInstallHelpers)
138138
install_amrex_targets(${_amrex_targets})
139-
endif()
140139

140+
# Add a test_install target to smoke-test
141+
# the installation
142+
add_test_install_target(
143+
${CMAKE_CURRENT_LIST_DIR}/Tests/CMakeTestInstall
144+
${CMAKE_INSTALL_PREFIX})
145+
endif()
141146

142147
#
143148
# Enable CTests

Docs/sphinx_documentation/source/BuildingAMReX.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ The CMake build process is summarized as follows:
369369
cd /path/to/builddir
370370
cmake [options] -DCMAKE_BUILD_TYPE=[Debug|Release|RelWithDebInfo|MinSizeRel] -DCMAKE_INSTALL_PREFIX=/path/to/installdir /path/to/amrex
371371
make install
372+
make test_install # optional step to test if the installation is working
372373

373374
In the above snippet, ``[options]`` indicates one or more options for the
374375
customization of the build, as described in the subsection on
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#
2+
# Test the amrex installation by
3+
# building and running the code
4+
# in Tests/Amr/Advection_AmrCore/
5+
#
6+
cmake_minimum_required(VERSION 3.14)
7+
8+
project(amrex-test-install)
9+
10+
get_filename_component(_base_dir ${CMAKE_CURRENT_LIST_DIR} DIRECTORY)
11+
12+
set(_base_dir ${_base_dir}/Amr/Advection_AmrCore)
13+
set(_src_dir ${_base_dir}/Source)
14+
set(_input_dir ${_base_dir}/Exec)
15+
16+
17+
find_package(AMReX REQUIRED)
18+
19+
if (AMReX_3D_FOUND)
20+
set(_dim 3)
21+
elseif (AMReX_2D_FOUND)
22+
set(_dim 2)
23+
else ()
24+
message(FATAL_ERROR "Cannot find a 2D or 3D version of AMReX")
25+
endif ()
26+
27+
28+
add_executable(install_test)
29+
30+
target_link_libraries(install_test PUBLIC AMReX::amrex)
31+
32+
target_include_directories(install_test
33+
PUBLIC
34+
${_src_dir}
35+
${_src_dir}/Src_K/
36+
${_input_dir}
37+
)
38+
39+
target_sources(install_test
40+
PRIVATE
41+
${_src_dir}/AdvancePhiAllLevels.cpp
42+
${_src_dir}/AdvancePhiAtLevel.cpp
43+
${_src_dir}/AmrCoreAdv.cpp
44+
${_src_dir}/AmrCoreAdv.H
45+
${_src_dir}/bc_fill.H
46+
${_src_dir}/DefineVelocity.cpp
47+
${_src_dir}/face_velocity.H
48+
${_src_dir}/Kernels.H
49+
${_src_dir}/main.cpp
50+
${_src_dir}/Tagging.H
51+
${_src_dir}/Src_K/Adv_K.H
52+
${_src_dir}/Src_K/compute_flux_2D_K.H
53+
${_src_dir}/Src_K/slope_K.H
54+
${_input_dir}/Prob.H
55+
)
56+
57+
add_custom_command(
58+
TARGET install_test
59+
POST_BUILD
60+
COMMAND ${CMAKE_COMMAND} -E echo "Running test project"
61+
COMMAND ${PROJECT_BINARY_DIR}/install_test ${_input_dir}/inputs max_step=1 > out.txt
62+
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
63+
)

Tools/CMake/AMReXInstallHelpers.cmake

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,36 @@ function (install_amrex_targets)
9797

9898

9999
endfunction ()
100+
101+
102+
#
103+
# Create a test_install target
104+
#
105+
# _dir is the project directory
106+
# _amrex_root is the amrex installation dir
107+
#
108+
macro( add_test_install_target _dir _amrex_root )
109+
110+
get_filename_component( _dirname ${_dir} NAME )
111+
set(_builddir ${CMAKE_CURRENT_BINARY_DIR}/${_dirname})
112+
add_custom_target(test_install
113+
COMMAND ${CMAKE_COMMAND} -E echo ""
114+
COMMAND ${CMAKE_COMMAND} -E echo "------------------------------------"
115+
COMMAND ${CMAKE_COMMAND} -E echo " Testing AMReX installation "
116+
COMMAND ${CMAKE_COMMAND} -E echo "------------------------------------"
117+
COMMAND ${CMAKE_COMMAND} -E echo ""
118+
COMMAND ${CMAKE_COMMAND} -E make_directory ${_builddir}
119+
COMMAND ${CMAKE_COMMAND} -E echo "Configuring test project"
120+
COMMAND ${CMAKE_COMMAND} -S ${_dir} -B ${_builddir} -DAMReX_ROOT=${_amrex_root} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
121+
COMMAND ${CMAKE_COMMAND} -E echo "Building test project"
122+
COMMAND ${CMAKE_COMMAND} --build ${_builddir}
123+
COMMAND ${CMAKE_COMMAND} -E echo ""
124+
COMMAND ${CMAKE_COMMAND} -E echo "------------------------------------"
125+
COMMAND ${CMAKE_COMMAND} -E echo " AMReX is installed correctly"
126+
COMMAND ${CMAKE_COMMAND} -E echo " Enjoy! "
127+
COMMAND ${CMAKE_COMMAND} -E echo "------------------------------------"
128+
COMMAND ${CMAKE_COMMAND} -E echo ""
129+
COMMAND ${CMAKE_COMMAND} -E remove_directory ${_builddir} # So we can run it again from scratch
130+
)
131+
132+
endmacro()

0 commit comments

Comments
 (0)