Skip to content

Commit 789e755

Browse files
committed
Add a config option to compile & link against OC
- Passing `-fcoarray=lib` to gfortran causes the compiler to generate different modules & symbols. This is likely a bug in gfortran, but, a consequence is that you need to build libraries you link to with the same `-fcoarray=...` flag.
1 parent 42e731a commit 789e755

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ include ( "cmake/checkOutOfSource.cmake" )
3636
#---------------------
3737
project ( jsonfortran NONE )
3838

39+
if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
40+
option(JSON_FORTRAN_USE_OpenCoarrays
41+
"Build JSON-Fortran with support for linking against OpenCoarray programs" OFF)
42+
endif()
43+
if(JSON_FORTRAN_USE_OpenCoarrays)
44+
find_package(OpenCoarrays)
45+
endif()
46+
3947
#---------------------
4048
# Real and Integer kinds
4149
#---------------------
@@ -161,6 +169,14 @@ endif ()
161169
set ( LIB_NAME ${CMAKE_PROJECT_NAME} )
162170
add_library ( ${LIB_NAME} SHARED ${JF_LIB_SRCS} )
163171
add_library ( ${LIB_NAME}-static STATIC ${JF_LIB_SRCS} )
172+
173+
if(JSON_FORTRAN_USE_OpenCoarrays)
174+
target_link_libraries(${LIB_NAME}
175+
PRIVATE OpenCoarrays::caf_mpi_static)
176+
target_link_libraries(${LIB_NAME}-static
177+
PRIVATE OpenCoarrays::caf_mpi_static)
178+
endif()
179+
164180
set_target_properties ( ${LIB_NAME}-static
165181
PROPERTIES
166182
OUTPUT_NAME ${LIB_NAME}

0 commit comments

Comments
 (0)