Skip to content

Commit 193546d

Browse files
committed
Use find_package(MPI) rather than compiler wrapper
The more canonical CMake way of selecting MPI is to use the Find_MPI module (i.e., `find_package(MPI)`) and set `FC` and `CC` to the actual compiler. Fixes #39
1 parent 3e92b21 commit 193546d

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,21 @@ if(gfortran_compiler)
102102
unset(CMAKE_REQUIRED_FLAGS)
103103
endif()
104104

105+
106+
#----------------------------------------------------------------------------
107+
# Find MPI and set some flags so that FC and CC can point to gfortran and gcc
108+
#----------------------------------------------------------------------------
109+
find_package(MPI REQUIRED)
110+
111+
set(CMAKE_C_COMPILE_FLAGS ${CMAKE_C_COMPILE_FLAGS} ${MPI_C_COMPILE_FLAGS})
112+
set(CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} ${MPI_C_LINK_FLAGS})
113+
set(CMAKE_Fortran_COMPILE_FLAGS ${CMAKE_Fortran_COMPILE_FLAGS} ${MPI_Fortran_COMPILE_FLAGS})
114+
set(CMAKE_Fortran_LINK_FLAGS ${CMAKE_Fortran_LINK_FLAGS} ${MPI_Fortran_LINK_FLAGS})
115+
include_directories(BEFORE ${MPI_C_INCLUDE_PATH} ${MPI_Fortran_INCLUDE_PATH})
116+
117+
#-------------------------------
118+
# Recurse into the src directory
119+
#-------------------------------
105120
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
106121

107122
add_subdirectory(src)

src/mpi/CMakeLists.txt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/mod)
22

3-
find_package(MPI REQUIRED)
3+
if (NOT MPI_C_FOUND)
4+
find_package(MPI REQUIRED)
5+
6+
set(CMAKE_C_COMPILE_FLAGS ${CMAKE_C_COMPILE_FLAGS} ${MPI_C_COMPILE_FLAGS})
7+
set(CMAKE_C_LINK_FLAGS ${CMAKE_C_LINK_FLAGS} ${MPI_C_LINK_FLAGS})
8+
set(CMAKE_Fortran_COMPILE_FLAGS ${CMAKE_Fortran_COMPILE_FLAGS} ${MPI_Fortran_COMPILE_FLAGS})
9+
set(CMAKE_Fortran_LINK_FLAGS ${CMAKE_Fortran_LINK_FLAGS} ${MPI_Fortran_LINK_FLAGS})
10+
include_directories(BEFORE ${MPI_C_INCLUDE_PATH} ${MPI_Fortran_INCLUDE_PATH})
11+
endif()
412

513
if("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "GNU")
614
set(gfortran_compiler true)
@@ -21,6 +29,7 @@ if(CAF_EXPOSE_INIT_FINALIZE)
2129
endif()
2230

2331
add_library(caf_mpi mpi_caf.c ../common/caf_auxiliary.c ../extensions/opencoarrays.F90)
32+
target_link_libraries(caf_mpi PRIVATE ${MPI_C_LIBRARIES} ${MPI_Fortran_LIBRARIES})
2433

2534
set_target_properties ( caf_mpi
2635
PROPERTIES
@@ -29,7 +38,6 @@ set_target_properties ( caf_mpi
2938
)
3039

3140

32-
target_include_directories(caf_mpi PRIVATE ${MPI_C_INCLUDE_PATH})
3341
if (gfortran_compiler)
3442
target_compile_options(caf_mpi INTERFACE -fcoarray=lib)
3543
endif()
@@ -91,7 +99,4 @@ file(APPEND "${caf_launcher}" "caf_version=${PROJECT_VERSION}\n")
9199
file(READ ${CMAKE_CURRENT_SOURCE_DIR}/../extensions/cafrun-foot FOOTER)
92100
file(APPEND "${caf_launcher}" "${FOOTER}")
93101

94-
# This could be needed to produce shared libraries:
95-
#target_link_libraries(caf_mpi PRIVATE ${MPI_C_LIBRARIES})
96-
97102
#set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${exe_dir}/cafrun;${exe_dir}/caf;${exe_dir}/test-caf-tally.sh")

0 commit comments

Comments
 (0)