mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-04 04:40:56 -06:00
Merge topic 'findmpi-add-imported-targets'
3ed9f635FindMPI: Add test case86979bb5FindMPI: Add IMPORTED targets Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !707
This commit is contained in:
4
Help/release/dev/FindMPI-add-imported-targets.rst
Normal file
4
Help/release/dev/FindMPI-add-imported-targets.rst
Normal file
@@ -0,0 +1,4 @@
|
||||
FindMPI-add-imported-targets
|
||||
------------------------------
|
||||
|
||||
* The :module:`FindMPI` module now provides imported targets.
|
||||
@@ -29,6 +29,12 @@
|
||||
# MPI_<lang>_LINK_FLAGS Linking flags for MPI programs
|
||||
# MPI_<lang>_LIBRARIES All libraries to link MPI programs against
|
||||
#
|
||||
# Additionally, the following :prop_tgt:`IMPORTED` targets are defined:
|
||||
#
|
||||
# ::
|
||||
#
|
||||
# MPI::MPI_<lang> Target for using MPI from <lang>
|
||||
#
|
||||
# Additionally, FindMPI sets the following variables for running MPI
|
||||
# programs from the command line:
|
||||
#
|
||||
@@ -621,6 +627,29 @@ foreach (lang C CXX Fortran)
|
||||
else()
|
||||
find_package_handle_standard_args(MPI_${lang} DEFAULT_MSG MPI_${lang}_LIBRARIES MPI_${lang}_INCLUDE_PATH)
|
||||
endif()
|
||||
|
||||
if(MPI_${lang}_FOUND)
|
||||
if(NOT TARGET MPI::MPI_${lang})
|
||||
add_library(MPI::MPI_${lang} INTERFACE IMPORTED)
|
||||
endif()
|
||||
if(MPI_${lang}_COMPILE_FLAGS)
|
||||
set(_MPI_${lang}_COMPILE_OPTIONS "${MPI_${lang}_COMPILE_FLAGS}")
|
||||
separate_arguments(_MPI_${lang}_COMPILE_OPTIONS)
|
||||
set_property(TARGET MPI::MPI_${lang} PROPERTY
|
||||
INTERFACE_COMPILE_OPTIONS "${_MPI_${lang}_COMPILE_OPTIONS}")
|
||||
endif()
|
||||
|
||||
unset(_MPI_${lang}_LINK_LINE)
|
||||
if(MPI_${lang}_LINK_FLAGS)
|
||||
list(APPEND _MPI_${lang}_LINK_LINE "${MPI_${lang}_LINK_FLAGS}")
|
||||
endif()
|
||||
list(APPEND _MPI_${lang}_LINK_LINE "${MPI_${lang}_LIBRARIES}")
|
||||
set_property(TARGET MPI::MPI_${lang} PROPERTY
|
||||
INTERFACE_LINK_LIBRARIES "${_MPI_${lang}_LINK_LINE}")
|
||||
|
||||
set_property(TARGET MPI::MPI_${lang} PROPERTY
|
||||
INTERFACE_INCLUDE_DIRECTORIES "${MPI_${lang}_INCLUDE_PATH}")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
|
||||
@@ -1411,6 +1411,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release
|
||||
add_subdirectory(FindOpenSSL)
|
||||
endif()
|
||||
|
||||
if(CMake_TEST_FindMPI)
|
||||
add_subdirectory(FindMPI)
|
||||
endif()
|
||||
|
||||
if(CMake_TEST_FindPNG)
|
||||
add_subdirectory(FindPNG)
|
||||
endif()
|
||||
|
||||
21
Tests/FindMPI/CMakeLists.txt
Normal file
21
Tests/FindMPI/CMakeLists.txt
Normal file
@@ -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>
|
||||
)
|
||||
41
Tests/FindMPI/Test/CMakeLists.txt
Normal file
41
Tests/FindMPI/Test/CMakeLists.txt
Normal file
@@ -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()
|
||||
7
Tests/FindMPI/Test/main.c
Normal file
7
Tests/FindMPI/Test/main.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <mpi.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
MPI_Init(&argc, &argv);
|
||||
MPI_Finalize();
|
||||
}
|
||||
7
Tests/FindMPI/Test/main.f90
Normal file
7
Tests/FindMPI/Test/main.f90
Normal file
@@ -0,0 +1,7 @@
|
||||
program mpi_test
|
||||
include 'mpif.h'
|
||||
integer ierror
|
||||
|
||||
call MPI_INIT(ierror)
|
||||
call MPI_FINALIZE(ierror)
|
||||
end program mpi_test
|
||||
Reference in New Issue
Block a user