Skip to content

Commit 1eb9ce1

Browse files
authored
Merge pull request #253 from sourceryinstitute/better-cmake-mpi-passing-#39
Better cmake mpi passing Fixes #39
2 parents 3e92b21 + ddd43cd commit 1eb9ce1

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

.travis.yml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ env:
99
- MPICH_DIR="$HOME/.local/usr/mpich"
1010
- MPICH_BOT_URL_HEAD="https://github.com/sourceryinstitute/opencoarrays/files/452136/"
1111
- MPICH_BOT_URL_TAIL="mpich-3.2_2.yosemite.bottle.1.tar.gz"
12+
- FC=gfortran-6
13+
- CC=gcc-6
14+
- CXX=g++-6
1215

1316
matrix:
1417
include:
@@ -84,9 +87,6 @@ before_install:
8487
[[ -d "$CACHE/bin" ]] || mkdir -p "$CACHE/bin"
8588
[[ -d "$MPICH_DIR" ]] || mkdir -p "$MPICH_DIR"
8689
export PATH="$CACHE/bin:$PATH"
87-
export FC=gfortran-6
88-
export CC=gcc-6
89-
export CXX=g++-6
9090
$FC --version
9191
$CC --version
9292
$CXX --version
@@ -103,8 +103,6 @@ install:
103103
[[ "$(brew ls --versions $pkg)" ]] || brew install --force-bottle $pkg
104104
brew outdated $pkg || brew upgrade --force-bottle $pkg
105105
done
106-
export FC=gfortran-6
107-
export CC=gcc-6
108106
if ! [[ "$(brew ls --versions mpich)" ]] && [[ "X$BUILD_TYPE" != "XInstallScript" ]]; then
109107
wget ${MPICH_BOT_URL_HEAD}${MPICH_BOT_URL_TAIL}
110108
brew install --force-bottle ${MPICH_BOT_URL_TAIL}
@@ -114,8 +112,6 @@ install:
114112
mpif90 --version
115113
mpicc --version
116114
cmake --version
117-
export FC=mpif90
118-
export CC=mpicc
119115
elif [[ "X$BUILD_TYPE" = "XInstallScript" ]]; then # uninstall some stuff if present
120116
[[ "$(brew ls --versions cmake)" ]] && brew rm cmake || true
121117
[[ "$(brew ls --versions mpich)" ]] && brew rm mpich || true
@@ -143,17 +139,13 @@ install:
143139
mpif90 --version
144140
mpicc --version
145141
cmake --version
146-
export FC=mpif90
147-
export CC=mpicc
148142
fi
149143
set +o errexit
150144
151145
script:
152146
- |
153147
set -o errexit
154148
if [[ "X$BUILD_TYPE" = "XInstallScript" ]]; then
155-
export FC=gfortran-6
156-
export CC=gcc-6
157149
[[ -d "$HOME/opt" ]] || mkdir "$HOME/opt"
158150
[[ -d "$HOME/bin" ]] || mkdir "$HOME/bin"
159151
ln -fs "$(which gfortran-6)" "$HOME/bin/gfortran"

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)