summaryrefslogtreecommitdiffstats
path: root/Tests/FindMPI/Test/CMakeLists.txt
blob: 3910c254f567d7e58e5a1cbcc0cfd28b14d5ea1f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
cmake_minimum_required(VERSION 3.8)
project(TestFindMPI NONE)
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()