diff options
author | Christian Pfeiffer <cpfeiffer@live.de> | 2017-04-18 15:43:25 (GMT) |
---|---|---|
committer | Christian Pfeiffer <cpfeiffer@live.de> | 2017-04-18 15:43:25 (GMT) |
commit | 3ed9f63551c2b51af60088b85625c4ce71512aa8 (patch) | |
tree | 4b05aa4a32c92f48c5f3531ecfc27f0dcaf484b0 /Tests/FindMPI | |
parent | 86979bb533a7835fc20f87b1f9d74590ebec4915 (diff) | |
download | CMake-3ed9f63551c2b51af60088b85625c4ce71512aa8.zip CMake-3ed9f63551c2b51af60088b85625c4ce71512aa8.tar.gz CMake-3ed9f63551c2b51af60088b85625c4ce71512aa8.tar.bz2 |
FindMPI: Add test case
Diffstat (limited to 'Tests/FindMPI')
-rw-r--r-- | Tests/FindMPI/CMakeLists.txt | 21 | ||||
-rw-r--r-- | Tests/FindMPI/Test/CMakeLists.txt | 41 | ||||
-rw-r--r-- | Tests/FindMPI/Test/main.c | 7 | ||||
-rw-r--r-- | Tests/FindMPI/Test/main.f90 | 7 |
4 files changed, 76 insertions, 0 deletions
diff --git a/Tests/FindMPI/CMakeLists.txt b/Tests/FindMPI/CMakeLists.txt new file mode 100644 index 0000000..121d978 --- /dev/null +++ b/Tests/FindMPI/CMakeLists.txt @@ -0,0 +1,21 @@ +foreach(c C CXX Fortran) + if(CMake_TEST_FindMPI_${c}) + set(CMake_TEST_FindMPI_FLAG_${c} 1) + else() + set(CMake_TEST_FindMPI_FLAG_${c} 0) + endif() +endforeach() + +add_test(NAME FindMPI.Test COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindMPI/Test" + "${CMake_BINARY_DIR}/Tests/FindMPI/Test" + ${build_generator_args} + --build-project TestFindMPI + --build-options ${build_options} + -DMPI_TEST_C=${CMake_TEST_FindMPI_FLAG_C} + -DMPI_TEST_CXX=${CMake_TEST_FindMPI_FLAG_CXX} + -DMPI_TEST_Fortran=${CMake_TEST_FindMPI_FLAG_Fortran} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) diff --git a/Tests/FindMPI/Test/CMakeLists.txt b/Tests/FindMPI/Test/CMakeLists.txt new file mode 100644 index 0000000..6f177f9 --- /dev/null +++ b/Tests/FindMPI/Test/CMakeLists.txt @@ -0,0 +1,41 @@ +cmake_minimum_required(VERSION 3.8) +project(TestFindMPI) +include(CTest) + +macro(source_code_mapper_helper LANG_NAME) + if("${LANG_NAME}" STREQUAL "C") + set(MPITEST_SOURCE_FILE "main.c") + elseif("${LANG_NAME}" STREQUAL "CXX") + configure_file("main.c" "main.cxx" COPYONLY) + set(MPITEST_SOURCE_FILE "main.cxx") + elseif("${LANG_NAME}" STREQUAL "Fortran") + set(MPITEST_SOURCE_FILE "main.f90") + endif() +endmacro() + +foreach(c C CXX Fortran) + if("${MPI_TEST_${c}}") + message("Testing ${c}") + enable_language(${c}) + endif() +endforeach() + +find_package(MPI REQUIRED) + +foreach(c C CXX Fortran) + if(NOT "${MPI_TEST_${c}}") + continue() + endif() + source_code_mapper_helper(${c}) + add_executable(test_tgt_${c} ${MPITEST_SOURCE_FILE}) + target_link_libraries(test_tgt_${c} MPI::MPI_${c}) + add_test(NAME test_tgt_${c} COMMAND test_tgt_${c}) + + add_executable(test_var_${c} ${MPITEST_SOURCE_FILE}) + target_include_directories(test_var_${c} PRIVATE "${MPI_${c}_INCLUDE_PATH}") + target_link_libraries(test_var_${c} PRIVATE "${MPI_${c}_LINK_FLAGS}" "${MPI_${c}_LIBRARIES}") + set(copied_MPI_${c}_OPTIONS "${MPI_${c}_COMPILE_FLAGS}") + separate_arguments(copied_MPI_${c}_OPTIONS) + target_compile_options(test_var_${c} PRIVATE "${copied_MPI_${c}_OPTIONS}") + add_test(NAME test_var_${c} COMMAND test_var_${c}) +endforeach() diff --git a/Tests/FindMPI/Test/main.c b/Tests/FindMPI/Test/main.c new file mode 100644 index 0000000..7b7f175 --- /dev/null +++ b/Tests/FindMPI/Test/main.c @@ -0,0 +1,7 @@ +#include <mpi.h> + +int main(int argc, char** argv) +{ + MPI_Init(&argc, &argv); + MPI_Finalize(); +} diff --git a/Tests/FindMPI/Test/main.f90 b/Tests/FindMPI/Test/main.f90 new file mode 100644 index 0000000..6fb6fd3 --- /dev/null +++ b/Tests/FindMPI/Test/main.f90 @@ -0,0 +1,7 @@ +program mpi_test + include 'mpif.h' + integer ierror + + call MPI_INIT(ierror) + call MPI_FINALIZE(ierror) +end program mpi_test |