Description: Use ${CAF_LIB_NAME} for library name, so we can produce
 two versions (mpich, openmpi)
Author: Alastair McKinstry <mckinstry@debian.org>
Last-Updated: 2018-12-14
Forwarded: no

Index: open-coarrays-2.4.0/CMakeLists.txt
===================================================================
--- open-coarrays-2.4.0.orig/CMakeLists.txt
+++ open-coarrays-2.4.0/CMakeLists.txt
@@ -31,6 +31,7 @@ option( CAF_ENABLE_ISO_Fortran_BINDING
   "Build and install F2018 C interop iso_fortran_binding.h header; experimental!"
   ${_TF} )
 
+SET(CAF_LIB_NAME "caf_mpi" CACHE STRING "Default name of the CAF library.")
 
 # Name project and specify source languages
 # Parse version from .VERSION file so that more info can be added and easier to get from scripts
@@ -623,7 +624,7 @@ install(
 
 add_library(OpenCoarrays INTERFACE)
 target_compile_options(OpenCoarrays INTERFACE $<$<COMPILE_LANGUAGE:Fortran>:"-fcoarray=lib")
-target_link_libraries(OpenCoarrays INTERFACE caf_mpi)
+target_link_libraries(OpenCoarrays INTERFACE ${CAF_LIB_NAME})
 
 #------------------------------------------
 # Add portable unistall command to makefile
Index: open-coarrays-2.4.0/src/mpi/CMakeLists.txt
===================================================================
--- open-coarrays-2.4.0.orig/src/mpi/CMakeLists.txt
+++ open-coarrays-2.4.0/src/mpi/CMakeLists.txt
@@ -29,9 +29,9 @@ target_link_libraries(opencoarrays_mod
 target_include_directories(opencoarrays_mod
   PRIVATE $<$<COMPILE_LANGUAGE:Fortran>:${MPI_Fortran_INCLUDE_PATH}>)
 
-add_library(caf_mpi SHARED mpi_caf.c ../common/caf_auxiliary.c)
+add_library(${CAF_LIB_NAME} SHARED mpi_caf.c ../common/caf_auxiliary.c)
 add_library(caf_mpi_static STATIC  mpi_caf.c ../common/caf_auxiliary.c)
-target_link_libraries(caf_mpi
+target_link_libraries(${CAF_LIB_NAME}
   PUBLIC ${MPI_C_LINK_FLAGS}
   PUBLIC ${MPI_C_LIBRARIES}
   PRIVATE opencoarrays_mod)
@@ -39,11 +39,11 @@ target_link_libraries(caf_mpi_static
   PUBLIC ${MPI_C_LINK_FLAGS}
   PUBLIC ${MPI_C_LIBRARIES}
   PRIVATE opencoarrays_mod)
-target_include_directories(caf_mpi
+target_include_directories(${CAF_LIB_NAME}
   PUBLIC $<$<COMPILE_LANGUAGE:C>:${MPI_C_INCLUDE_PATH}>)
 target_include_directories(caf_mpi_static
   PUBLIC $<$<COMPILE_LANGUAGE:C>:${MPI_C_INCLUDE_PATH}>)
-target_compile_options(caf_mpi
+target_compile_options(${CAF_LIB_NAME}
   PUBLIC $<$<COMPILE_LANGUAGE:C>:${MPI_C_COMPILE_FLAGS}>)
 target_compile_options(caf_mpi_static
   PUBLIC $<$<COMPILE_LANGUAGE:C>:${MPI_C_COMPILE_FLAGS}>)
@@ -59,7 +59,7 @@ if(gfortran_compiler)
   endif()
 endif()
 
-set_target_properties ( caf_mpi
+set_target_properties ( ${CAF_LIB_NAME}
   PROPERTIES
   SOVERSION ${CAF_SO_VERSION}
 #  VERSION ${PROJECT_VERSION}
@@ -67,7 +67,7 @@ set_target_properties ( caf_mpi
 
 # Create a symlink in the include dir
 if(UNIX)
-  add_custom_command(TARGET caf_mpi
+  add_custom_command(TARGET ${CAF_LIB_NAME}
     POST_BUILD
     COMMAND ${CMAKE_COMMAND} -E create_symlink "./${mod_dir_tail}/opencoarrays.mod" "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR}/opencoarrays.mod"
     COMMENT "Creating symlink ${CMAKE_INSTALL_INCLUDEDIR}/opencoarrays.mod --> ${CMAKE_INSTALL_INCLUDEDIR}/${mod_dir_tail}/opencoarrays.mod")
@@ -83,7 +83,7 @@ set_target_properties( caf_mpi_static
 )
 
 if (gfortran_compiler)
-  target_compile_options(caf_mpi INTERFACE $<$<COMPILE_LANGUAGE:Fortran>:"-fcoarray=lib">)
+  target_compile_options(${CAF_LIB_NAME} INTERFACE $<$<COMPILE_LANGUAGE:Fortran>:"-fcoarray=lib">)
   target_compile_options(caf_mpi_static INTERFACE $<$<COMPILE_LANGUAGE:Fortran>:"-fcoarray=lib">)
 endif()
 
@@ -91,7 +91,7 @@ install(TARGETS opencoarrays_mod EXPORT
   DESTINATION "${CMAKE_INSTALL_LIBDIR}"
   LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
 )
-install(TARGETS caf_mpi EXPORT OpenCoarraysTargets
+install(TARGETS ${CAF_LIB_NAME} EXPORT OpenCoarraysTargets
   DESTINATION "${CMAKE_INSTALL_LIBDIR}"
   LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
 )
@@ -136,7 +136,7 @@ endif()
 include(CheckIncludeFile)
 CHECK_INCLUDE_FILE("alloca.h" HAVE_ALLOCA)
 if(NOT HAVE_ALLOCA)
-  target_compile_definitions(caf_mpi
+  target_compile_definitions(${CAF_LIB_NAME}
     PRIVATE -DALLOCA_MISSING)
   target_compile_definitions(caf_mpi_static
     PRIVATE -DALLOCA_MISSING)
@@ -162,7 +162,7 @@ if(NOT HAVE_SIGKILL) # try -D_POSIX, nee
   CHECK_SYMBOL_EXISTS(SIGKILL "signal.h" HAVE_SIGKILL2)
   if(HAVE_SIGKILL2)
     set(HAVE_SIGKILL ${HAVE_SIGKILL2})
-    foreach(lib caf_mpi caf_mpi_static)
+    foreach(lib ${CAF_LIB_NAME} caf_mpi_static)
       target_compile_definitions(${lib}
     	PUBLIC -D_POSIX)
     endforeach()
@@ -199,7 +199,7 @@ set(MPI_HEADERS mpi.h)
 include(CheckIncludeFiles)
 CHECK_INCLUDE_FILES("mpi.h;mpi-ext.h" HAVE_MPI_EXT)
 if(HAVE_MPI_EXT)
-    foreach(lib caf_mpi caf_mpi_static)
+    foreach(lib ${CAF_LIB_NAME} caf_mpi_static)
       target_compile_definitions(${lib}
     	PRIVATE -DHAVE_MPI_EXT_H)
     endforeach()
@@ -237,7 +237,7 @@ else()
 endif()
 
 if(CAF_ENABLE_FAILED_IMAGES)
-  foreach(lib caf_mpi caf_mpi_static)
+  foreach(lib ${CAF_LIB_NAME} caf_mpi_static)
     target_compile_definitions(${lib}
       PUBLIC -DUSE_FAILED_IMAGES)
   endforeach()
@@ -255,7 +255,7 @@ endif()
 CHECK_INCLUDE_FILES("mpi.h" HAVE_MPI_H)
 CHECK_SYMBOL_EXISTS(I_MPI_VERSION "mpi.h" HAVE_Intel_MPI)
 if(HAVE_Intel_MPI AND WIN32)
-  foreach(lib caf_mpi caf_mpi_static)
+  foreach(lib ${CAF_LIB_NAME} caf_mpi_static)
     target_compile_definitions(${lib}
       PUBLIC -DUSE_GCC)
   endforeach()
