Skip to content

Commit 547f0da

Browse files
authored
Merge pull request #346 from astro-informatics/tk/spack-install-fixes
Make tests and examples self-contained
2 parents 4fb99e2 + 34d020e commit 547f0da

File tree

10 files changed

+53
-42
lines changed

10 files changed

+53
-42
lines changed

CMakeLists.txt

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,26 +50,15 @@ if(NOT PURIFY_OPENMP)
5050
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
5151
endif()
5252

53-
if(tests) # Adds ctest
54-
enable_testing()
55-
find_package(Catch2)
56-
include(AddCatchTest)
57-
endif()
58-
5953
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-command-line-argument")
6054

6155
if(tests AND coverage)
6256
# Enable code coverage.
63-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
64-
# Build with debugging information to make the output meaningful.
65-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
66-
# Disable optimizations to get the most accurate results.
67-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
68-
endif()
69-
70-
if(benchmarks)
71-
set(GBenchmark_GIT_TAG "v1.3.0")
72-
include(AddBenchmark)
57+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
58+
# Build with debugging information to make the output meaningful.
59+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
60+
# Disable optimizations to get the most accurate results.
61+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
7362
endif()
7463

7564
add_subdirectory(cpp)

cmake_files/AddCatchTest.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function(add_catch_test testname)
9797
endif()
9898
if(NOT catch_NOTEST)
9999
add_catch_test_with_seed(
100-
test_${testname} "test_${testname}" "${catch_SEED}" ${catch_UNPARSED_ARGUMENTS}
100+
test_${testname} "./test_${testname}" "${catch_SEED}" ${catch_UNPARSED_ARGUMENTS}
101101
${catch_NOCATCHLABEL} WORKING_DIRECTORY ${catch_WORKING_DIRECTORY}
102102
LABELS ${catch_LABELS} ARGUMENTS ${catch_ARGUMENTS}
103103
)

cmake_files/AddExample.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function(add_example targetname)
3333
if(example_WORKING_DIRECTORY)
3434
set(EXTRA_ARGS WORKING_DIRECTORY ${example_WORKING_DIRECTORY})
3535
endif()
36-
add_test(NAME test_example_${targetname} COMMAND example_${targetname} ${EXTRA_ARGS})
36+
add_test(NAME test_example_${targetname} COMMAND "./example_${targetname}" ${EXTRA_ARGS})
3737

3838
list(APPEND example_LABELS examples)
3939
set_tests_properties(test_example_${targetname} PROPERTIES LABELS "${example_LABELS}")

cmake_files/dependencies.cmake

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ else()
1717
message(FATAL_ERROR "Eigen is required")
1818
endif()
1919

20-
find_package(CFitsIO MODULE REQUIRED)
20+
find_package(CFitsIO REQUIRED)
2121

2222
cmake_policy(SET CMP0167 OLD)
2323
find_package(Boost COMPONENTS system filesystem REQUIRED)
@@ -54,10 +54,25 @@ if(docs)
5454
find_package(Doxygen REQUIRED dot)
5555
endif()
5656

57+
if(tests) # Adds ctest
58+
enable_testing()
59+
find_package(Catch2)
60+
include(AddCatchTest)
61+
endif()
62+
5763
if(examples)
5864
find_package(TIFF REQUIRED)
5965
endif()
6066

67+
if(tests OR examples)
68+
file(COPY data DESTINATION .)
69+
endif()
70+
71+
if(benchmarks)
72+
find_package(benchmark REQUIRED)
73+
#include(AddBenchmark)
74+
endif()
75+
6176
# Always find open-mp, since it may be used by sopt
6277
if (openmp)
6378
cmake_policy(SET CMP0074 NEW)

cpp/benchmarks/CMakeLists.txt

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
include_directories("${PROJECT_SOURCE_DIR}/cpp" "${CMAKE_CURRENT_BINARY_DIR}/include")
22

3-
add_benchmark(measurement_operator utilities.cc LIBRARIES libpurify)
4-
add_benchmark(padmm utilities.cc LIBRARIES libpurify)
5-
add_benchmark(wavelet_operator utilities.cc LIBRARIES libpurify)
6-
add_benchmark(fft utilities.cc LIBRARIES libpurify)
7-
add_benchmark(degridding utilities.cc LIBRARIES libpurify)
8-
if(doaf)
9-
add_benchmark(measurement_operator_af utilities.cc LIBRARIES libpurify)
10-
add_benchmark(measurement_operator_cpu measurement_operator_af.cc utilities.cc LIBRARIES libpurify)
11-
target_compile_definitions(benchmark_measurement_operator_cpu PRIVATE PURIFY_CPU)
12-
endif()
3+
add_executable(measurement_operator utilities.cc measurement_operator.cc)
4+
target_link_libraries(measurement_operator benchmark libpurify)
5+
add_executable(padmm utilities.cc padmm.cc)
6+
target_link_libraries(padmm benchmark libpurify)
7+
add_executable(wavelet_operator utilities.cc wavelet_operator.cc)
8+
target_link_libraries(wavelet_operator benchmark libpurify)
9+
add_executable(fft utilities.cc fft.cc)
10+
target_link_libraries(fft benchmark libpurify)
11+
add_executable(degridding utilities.cc degridding.cc)
12+
target_link_libraries(degridding benchmark libpurify)
13+
14+
# Skip ArrayFire benchmarks for now, add back later if needed
15+
# if(doaf)
16+
# add_benchmark(measurement_operator_af utilities.cc LIBRARIES libpurify)
17+
# add_benchmark(measurement_operator_cpu measurement_operator_af.cc utilities.cc LIBRARIES libpurify)
18+
# target_compile_definitions(benchmark_measurement_operator_cpu PRIVATE PURIFY_CPU)
19+
# endif()
1320

1421
if(dompi)
1522
add_executable(mpi_benchmark_MO main.cc utilities.cc measurement_operator_mpi.cc)
16-
target_link_libraries(mpi_benchmark_MO ${MPI_LIBRARIES} gbenchmark libpurify)
17-
target_include_directories(mpi_benchmark_MO PUBLIC "${PROJECT_SOURCE_DIR}/cpp" "${CMAKE_CURRENT_BINARY_DIR}/include")
23+
target_link_libraries(mpi_benchmark_MO ${MPI_LIBRARIES} benchmark libpurify)
24+
#target_include_directories(mpi_benchmark_MO PUBLIC "${PROJECT_SOURCE_DIR}/cpp" "${CMAKE_CURRENT_BINARY_DIR}/include")
1825
add_executable(mpi_benchmark_MO_wproj main.cc utilities.cc measurement_operator_wproj.cc)
19-
target_link_libraries(mpi_benchmark_MO_wproj ${MPI_LIBRARIES} gbenchmark libpurify)
20-
target_include_directories(mpi_benchmark_MO_wproj PUBLIC "${PROJECT_SOURCE_DIR}/cpp" "${CMAKE_CURRENT_BINARY_DIR}/include")
26+
target_link_libraries(mpi_benchmark_MO_wproj ${MPI_LIBRARIES} benchmark libpurify)
27+
#target_include_directories(mpi_benchmark_MO_wproj PUBLIC "${PROJECT_SOURCE_DIR}/cpp" "${CMAKE_CURRENT_BINARY_DIR}/include")
2128
add_executable(mpi_benchmark_PADMM main.cc utilities.cc padmm_mpi.cc)
22-
target_link_libraries(mpi_benchmark_PADMM ${MPI_LIBRARIES} gbenchmark libpurify)
23-
target_include_directories(mpi_benchmark_PADMM PUBLIC "${PROJECT_SOURCE_DIR}/cpp" "${CMAKE_CURRENT_BINARY_DIR}/include")
29+
target_link_libraries(mpi_benchmark_PADMM ${MPI_LIBRARIES} benchmark libpurify)
30+
#target_include_directories(mpi_benchmark_PADMM PUBLIC "${PROJECT_SOURCE_DIR}/cpp" "${CMAKE_CURRENT_BINARY_DIR}/include")
2431
add_executable(mpi_benchmark_WLO main.cc utilities.cc wavelet_operator_mpi.cc)
25-
target_link_libraries(mpi_benchmark_WLO ${MPI_LIBRARIES} gbenchmark libpurify)
26-
target_include_directories(mpi_benchmark_WLO PUBLIC "${PROJECT_SOURCE_DIR}/cpp" "${CMAKE_CURRENT_BINARY_DIR}/include")
32+
target_link_libraries(mpi_benchmark_WLO ${MPI_LIBRARIES} benchmark libpurify)
33+
#target_include_directories(mpi_benchmark_WLO PUBLIC "${PROJECT_SOURCE_DIR}/cpp" "${CMAKE_CURRENT_BINARY_DIR}/include")
2734
endif()

cpp/benchmarks/measurement_operator_mpi.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "benchmarks/utilities.h"
55
#include "purify/directories.h"
66
#include "purify/operators.h"
7-
#include "purify/pfitsio.h"
87
#include <sopt/imaging_padmm.h>
98
#include <sopt/mpi/communicator.h>
109
#include <sopt/mpi/session.h>

cpp/benchmarks/measurement_operator_wproj.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "benchmarks/utilities.h"
55
#include "purify/directories.h"
66
#include "purify/operators.h"
7-
#include "purify/pfitsio.h"
87
#include "purify/wide_field_utilities.h"
98
#include "purify/wproj_operators.h"
109
#include <sopt/imaging_padmm.h>

cpp/benchmarks/padmm_mpi.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "purify/distribute.h"
88
#include "purify/mpi_utilities.h"
99
#include "purify/operators.h"
10-
#include "purify/pfitsio.h"
1110
#include "purify/utilities.h"
1211
#include <sopt/imaging_padmm.h>
1312
#include <sopt/mpi/communicator.h>

cpp/tests/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ if(PURIFY_MPI)
7070
add_test(NAME ${testname}
7171
COMMAND
7272
${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS}
73-
$<TARGET_FILE:test_${testname}> ${arguments})
73+
"./test_${testname}" ${arguments})
7474
set_tests_properties(${testname} PROPERTIES LABELS "catch;mpi")
7575
endfunction()
7676

@@ -85,3 +85,6 @@ if(PURIFY_MPI)
8585
add_mpi_test(mpi_wide_field_utilities LIBRARIES libpurify)
8686
add_mpi_test(parallel_mpi_utilities LIBRARIES libpurify)
8787
endif()
88+
89+
install(DIRECTORY ${CMAKE_SOURCE_DIR}/data DESTINATION .)
90+

cpp/tests/directories.in.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace purify {
77
namespace notinstalled {
88

99
//! Holds data and such
10-
inline std::string data_directory() { return "@PROJECT_SOURCE_DIR@/data"; }
10+
inline std::string data_directory() { return "@CMAKE_INSTALL_PREFIX@/data"; }
1111
//! Holds data and such
1212
inline std::string data_filename(std::string const &filename) {
1313
return data_directory() + "/" + filename;

0 commit comments

Comments
 (0)