1
+ # Silence warnings about dereferencing unset variables
2
+ if (NOT CMAKE_REQUIRED_FLAGS )
3
+ set (CMAKE_REQUIRED_FLAGS "" )
4
+ endif ()
5
+ if (NOT CMAKE_REQUIRED_LIBRARIES )
6
+ set (CMAKE_REQUIRED_LIBRARIES "" )
7
+ endif ()
8
+ if (NOT CMAKE_REQUIRED_INCLUDES )
9
+ set (CMAKE_REQUIRED_INCLUDES "" )
10
+ endif ()
11
+
1
12
if (NOT MPI_C_FOUND )
2
13
find_package (MPI REQUIRED )
14
+ endif ()
15
+
16
+ #-----------------------------------------------------------
17
+ # Add the actual library targets, then adjust them as needed
18
+ #-----------------------------------------------------------
19
+ add_library (opencoarrays_mod STATIC ../extensions/opencoarrays.F90 )
20
+ set_target_properties (opencoarrays_mod
21
+ PROPERTIES
22
+ Fortran_MODULE_DIRECTORY "${CMAKE_BINARY_DIR} /${CMAKE_INSTALL_INCLUDEDIR} /${mod_dir_tail} "
23
+ POSITION_INDEPENDENT_CODE TRUE )
24
+ target_compile_options (opencoarrays_mod
25
+ PRIVATE $< $< COMPILE_LANGUAGE:Fortran> :${MPI_Fortran_COMPILE_FLAGS} > )
26
+ target_link_libraries (opencoarrays_mod
27
+ PUBLIC ${MPI_Fortran_LINK_FLAGS}
28
+ PUBLIC ${MPI_Fortran_LIBRARIES} )
29
+ target_include_directories (opencoarrays_mod
30
+ PRIVATE $< $< COMPILE_LANGUAGE:Fortran> :${MPI_Fortran_INCLUDE_PATH} > )
31
+
32
+ add_library (caf_mpi SHARED mpi_caf.c ../common/caf_auxiliary.c )
33
+ add_library (caf_mpi_static STATIC mpi_caf.c ../common/caf_auxiliary.c )
34
+ target_link_libraries (caf_mpi
35
+ PUBLIC ${MPI_C_LINK_FLAGS}
36
+ PUBLIC ${MPI_C_LIBRARIES}
37
+ PRIVATE opencoarrays_mod )
38
+ target_link_libraries (caf_mpi_static
39
+ PUBLIC ${MPI_C_LINK_FLAGS}
40
+ PUBLIC ${MPI_C_LIBRARIES}
41
+ PRIVATE opencoarrays_mod )
42
+ target_include_directories (caf_mpi
43
+ PUBLIC $< $< COMPILE_LANGUAGE:C> :${MPI_C_INCLUDE_PATH} > )
44
+ target_include_directories (caf_mpi_static
45
+ PUBLIC $< $< COMPILE_LANGUAGE:C> :${MPI_C_INCLUDE_PATH} > )
46
+ target_compile_options (caf_mpi
47
+ PUBLIC $< $< COMPILE_LANGUAGE:C> :${MPI_C_COMPILE_FLAGS} > )
48
+ target_compile_options (caf_mpi_static
49
+ PUBLIC $< $< COMPILE_LANGUAGE:C> :${MPI_C_COMPILE_FLAGS} > )
3
50
4
- set (CMAKE_C_COMPILE_FLAGS "${CMAKE_C_COMPILE_FLAGS} ${MPI_C_COMPILE_FLAGS} " )
5
- set (CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} ${MPI_C_LINK_FLAGS} " )
6
- set (CMAKE_Fortran_COMPILE_FLAGS "${CMAKE_Fortran_COMPILE_FLAGS} ${MPI_Fortran_COMPILE_FLAGS} " )
7
- set (CMAKE_Fortran_LINK_FLAGS "${CMAKE_Fortran_LINK_FLAGS} ${MPI_Fortran_LINK_FLAGS} " )
8
- include_directories (BEFORE ${MPI_C_INCLUDE_PATH} ${MPI_Fortran_INCLUDE_PATH} )
51
+ set (CAF_SO_VERSION 0 )
52
+ if (gfortran_compiler )
53
+ if (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 8.0.0 )
54
+ set (CAF_SO_VERSION 3 )
55
+ elseif (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 7.0.0 )
56
+ set (CAF_SO_VERSION 2 )
57
+ elseif (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 6.0.0 )
58
+ set (CAF_SO_VERSION 1 )
59
+ endif ()
9
60
endif ()
10
61
62
+ set_target_properties ( caf_mpi
63
+ PROPERTIES
64
+ SOVERSION ${CAF_SO_VERSION}
65
+ # VERSION ${PROJECT_VERSION}
66
+ )
67
+
68
+ # Create a symlink in the include dir
69
+ if (UNIX )
70
+ add_custom_command (TARGET caf_mpi
71
+ POST_BUILD
72
+ COMMAND ${CMAKE_COMMAND} -E create_symlink "./${mod_dir_tail} /opencoarrays.mod" "${CMAKE_BINARY_DIR} /${CMAKE_INSTALL_INCLUDEDIR} /opencoarrays.mod"
73
+ COMMENT "Creating symlink ${CMAKE_INSTALL_INCLUDEDIR} /opencoarrays.mod --> ${CMAKE_INSTALL_INCLUDEDIR} /${mod_dir_tail} /opencoarrays.mod" )
74
+ endif ()
75
+
76
+ install (DIRECTORY "${CMAKE_BINARY_DIR} /${CMAKE_INSTALL_INCLUDEDIR} /" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR} "
77
+ FILES_MATCHING PATTERN "*.mod" )
78
+
79
+ set_target_properties ( caf_mpi_static
80
+ PROPERTIES
81
+ SOVERSION ${CAF_SO_VERSION}
82
+ # VERSION ${PROJECT_VERSION}
83
+ )
84
+
85
+ if (gfortran_compiler )
86
+ target_compile_options (caf_mpi INTERFACE $< $< COMPILE_LANGUAGE:Fortran> :"-fcoarray=lib"> )
87
+ target_compile_options (caf_mpi_static INTERFACE $< $< COMPILE_LANGUAGE:Fortran> :"-fcoarray=lib"> )
88
+ endif ()
89
+
90
+ install (TARGETS caf_mpi EXPORT OpenCoarraysTargets
91
+ DESTINATION "${CMAKE_INSTALL_LIBDIR} "
92
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR} "
93
+ )
94
+ install (TARGETS caf_mpi_static EXPORT OpenCoarraysTargets
95
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR} "
96
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR} "
97
+ )
98
+
11
99
#----------------------------------
12
100
# Determine if we're using Open MPI
13
101
#----------------------------------
14
102
cmake_host_system_information (RESULT N_CPU QUERY NUMBER_OF_LOGICAL_CORES )
15
103
set (N_CPU ${N_CPU} PARENT_SCOPE )
16
104
cmake_host_system_information (RESULT HOST_NAME QUERY HOSTNAME )
17
- set (HOSTNAME ${HOSTNAME } PARENT_SCOPE )
105
+ set (HOST_NAME ${HOST_NAME } PARENT_SCOPE )
18
106
execute_process (COMMAND ${MPIEXEC} --version
19
107
OUTPUT_VARIABLE mpi_version_out )
20
108
if (mpi_version_out MATCHES "[Oo]pen[ -][Mm][Pp][Ii]" )
@@ -33,19 +121,21 @@ elseif("${CMAKE_Fortran_COMPILER_ID}" STREQUAL "PGI")
33
121
endif ()
34
122
35
123
if (gfortran_compiler AND (NOT opencoarrays_aware_compiler ))
36
- # This applied to gfortran < 5.2
37
- add_definitions (-DCOMPILER_SUPPORTS_CAF_INTRINSICS )
124
+ target_compile_definitions (opencoarrays_mod PUBLIC -DCOMPILER_SUPPORTS_CAF_INTRINSICS )
38
125
endif ()
39
126
40
127
option (CAF_EXPOSE_INIT_FINALIZE "Expose caf_init and caf_finalize in opencoarrays module" FALSE )
41
128
if (CAF_EXPOSE_INIT_FINALIZE )
42
- add_definitions ( -DEXPOSE_INIT_FINALIZE )
129
+ target_compile_definitions ( opencoarrays_mod PRIVATE -DEXPOSE_INIT_FINALIZE )
43
130
endif ()
44
131
45
132
include (CheckIncludeFile )
46
133
CHECK_INCLUDE_FILE ("alloca.h" HAVE_ALLOCA )
47
134
if (NOT HAVE_ALLOCA )
48
- add_definitions (-DALLOCA_MISSING )
135
+ target_compile_definitions (caf_mpi
136
+ PRIVATE -DALLOCA_MISSING )
137
+ target_compile_definitions (caf_mpi_static
138
+ PRIVATE -DALLOCA_MISSING )
49
139
message (WARNING "Could not find <alloca.h>. Assuming functionality is provided elsewhere." )
50
140
endif ()
51
141
@@ -68,7 +158,10 @@ if(NOT HAVE_SIGKILL) # try -D_POSIX, needed for mingw-w64, maybe others, see #43
68
158
CHECK_SYMBOL_EXISTS (SIGKILL "signal.h" HAVE_SIGKILL2 )
69
159
if (HAVE_SIGKILL2 )
70
160
set (HAVE_SIGKILL ${HAVE_SIGKILL2} )
71
- add_definitions (-D_POSIX )
161
+ foreach (lib caf_mpi caf_mpi_static )
162
+ target_compile_definitions (${lib}
163
+ PUBLIC -D_POSIX )
164
+ endforeach ()
72
165
endif ()
73
166
endif ()
74
167
@@ -102,7 +195,10 @@ set(MPI_HEADERS mpi.h)
102
195
include (CheckIncludeFiles )
103
196
CHECK_INCLUDE_FILES ("mpi.h;mpi-ext.h" HAVE_MPI_EXT )
104
197
if (HAVE_MPI_EXT )
105
- add_definitions (-DHAVE_MPI_EXT_H )
198
+ foreach (lib caf_mpi caf_mpi_static )
199
+ target_compile_definitions (${lib}
200
+ PRIVATE -DHAVE_MPI_EXT_H )
201
+ endforeach ()
106
202
set (MPI_HEADERS ${MPI_HEADERS} ;mpi-ext.h )
107
203
endif ()
108
204
@@ -131,7 +227,10 @@ else()
131
227
endif ()
132
228
133
229
if (CAF_ENABLE_FAILED_IMAGES )
134
- add_definitions (-DUSE_FAILED_IMAGES )
230
+ foreach (lib caf_mpi caf_mpi_static )
231
+ target_compile_definitions (${lib}
232
+ PUBLIC -DUSE_FAILED_IMAGES )
233
+ endforeach ()
135
234
endif ()
136
235
137
236
#---------------------------------------------------
@@ -146,69 +245,13 @@ endif()
146
245
CHECK_INCLUDE_FILES ("mpi.h" HAVE_MPI_H )
147
246
CHECK_SYMBOL_EXISTS (I_MPI_VERSION "mpi.h" HAVE_Intel_MPI )
148
247
if (HAVE_Intel_MPI AND WIN32 )
149
- add_definitions (-DUSE_GCC )
248
+ foreach (lib caf_mpi caf_mpi_static )
249
+ target_compile_definitions (${lib}
250
+ PUBLIC -DUSE_GCC )
251
+ endforeach ()
150
252
endif ()
151
253
set (CMAKE_REQUIRED_INCLUDES ${old_cmake_required_includes} )
152
254
153
- add_library (opencoarrays_mod OBJECT ../extensions/opencoarrays.F90 )
154
- set_target_properties (opencoarrays_mod
155
- PROPERTIES
156
- Fortran_MODULE_DIRECTORY "${CMAKE_BINARY_DIR} /${CMAKE_INSTALL_INCLUDEDIR} /${mod_dir_tail} "
157
- POSITION_INDEPENDENT_CODE TRUE )
158
-
159
- add_library (caf_mpi SHARED mpi_caf.c ../common/caf_auxiliary.c $< TARGET_OBJECTS:opencoarrays_mod> )
160
- add_library (caf_mpi_static STATIC mpi_caf.c ../common/caf_auxiliary.c $< TARGET_OBJECTS:opencoarrays_mod> )
161
- target_link_libraries (caf_mpi PRIVATE ${MPI_C_LIBRARIES} ${MPI_Fortran_LIBRARIES} )
162
- target_link_libraries (caf_mpi_static PRIVATE ${MPI_C_LIBRARIES} ${MPI_Fortran_LIBRARIES} )
163
-
164
- set (CAF_SO_VERSION 0 )
165
- if (gfortran_compiler )
166
- if (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 8.0.0 )
167
- set (CAF_SO_VERSION 3 )
168
- elseif (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 7.0.0 )
169
- set (CAF_SO_VERSION 2 )
170
- elseif (NOT CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 6.0.0 )
171
- set (CAF_SO_VERSION 1 )
172
- endif ()
173
- endif ()
174
-
175
- set_target_properties ( caf_mpi
176
- PROPERTIES
177
- SOVERSION ${CAF_SO_VERSION}
178
- # VERSION ${PROJECT_VERSION}
179
- )
180
-
181
- # Create a symlink in the include dir
182
- if (UNIX )
183
- add_custom_command (TARGET caf_mpi
184
- POST_BUILD
185
- COMMAND ${CMAKE_COMMAND} -E create_symlink "./${mod_dir_tail} /opencoarrays.mod" "${CMAKE_BINARY_DIR} /${CMAKE_INSTALL_INCLUDEDIR} /opencoarrays.mod"
186
- COMMENT "Creating symlink ${CMAKE_INSTALL_INCLUDEDIR} /opencoarrays.mod --> ${CMAKE_INSTALL_INCLUDEDIR} /${mod_dir_tail} /opencoarrays.mod" )
187
- endif ()
188
-
189
- install (DIRECTORY "${CMAKE_BINARY_DIR} /${CMAKE_INSTALL_INCLUDEDIR} /" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR} "
190
- FILES_MATCHING PATTERN "*.mod" )
191
-
192
- set_target_properties ( caf_mpi_static
193
- PROPERTIES
194
- SOVERSION ${CAF_SO_VERSION}
195
- # VERSION ${PROJECT_VERSION}
196
- )
197
-
198
- if (gfortran_compiler )
199
- target_compile_options (caf_mpi INTERFACE -fcoarray=lib )
200
- target_compile_options (caf_mpi_static INTERFACE -fcoarray=lib )
201
- endif ()
202
-
203
- install (TARGETS caf_mpi EXPORT OpenCoarraysTargets
204
- DESTINATION "${CMAKE_INSTALL_LIBDIR} "
205
- LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR} "
206
- )
207
- install (TARGETS caf_mpi_static EXPORT OpenCoarraysTargets
208
- ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR} "
209
- LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR} "
210
- )
211
-
212
255
##############################################
213
256
# Configure `caf` and `cafrun` wrapper scripts
214
257
##############################################
@@ -227,7 +270,7 @@ set(CAF_MPI_LIBS "")
227
270
foreach ( lib IN LISTS MPI_Fortran_LIBRARIES )
228
271
set (CAF_MPI_LIBS "${CAF_MPI_LIBS} \" ${lib} \" " )
229
272
endforeach ()
230
- string (STRIP "${MPI_LIBS } " MPI_LIBS )
273
+ string (STRIP "${CAF_MPI_LIBS } " CAF_MPI_LIBS )
231
274
set (CAF_MPI_Fortran_LINK_FLAGS "" )
232
275
foreach ( lflag IN LISTS MPI_Fortran_LINK_FLAGS )
233
276
set (CAF_MPI_Fortran_LINK_FLAGS "${CAF_MPI_Fortran_LINK_FLAGS} ${lflag} " )
0 commit comments