From e73152eaf3c84b2fd9a228d848e00f144433f719 Mon Sep 17 00:00:00 2001
From: Chuck Atkins <chuck.atkins@kitware.com>
Date: Tue, 12 Sep 2017 14:30:31 -0400
Subject: [PATCH] CMake: Port examples to use new FindMPI module

---
 examples/basics/globalArray/CMakeLists.txt    |  3 +--
 examples/basics/joinedArray/CMakeLists.txt    |  3 +--
 examples/basics/localArray/CMakeLists.txt     |  3 +--
 examples/basics/values/CMakeLists.txt         |  3 +--
 .../experimental/multistep/CMakeLists.txt     |  8 ++-----
 .../runtimeconfig/hello/CMakeLists.txt        |  3 +--
 examples/heatTransfer/read/CMakeLists.txt     | 12 ++--------
 examples/heatTransfer/write/CMakeLists.txt    | 23 ++++++-------------
 examples/hello/adios1Writer/CMakeLists.txt    |  3 +--
 .../hello/bpAttributeWriter/CMakeLists.txt    |  3 +--
 examples/hello/bpBZip2Wrapper/CMakeLists.txt  |  3 +--
 examples/hello/bpFlushWriter/CMakeLists.txt   |  3 +--
 examples/hello/bpTimeWriter/CMakeLists.txt    |  3 +--
 examples/hello/bpWriter/CMakeLists.txt        | 19 ++++-----------
 examples/hello/bpZfpWrapper/CMakeLists.txt    |  3 +--
 examples/hello/datamanReader/CMakeLists.txt   |  3 +--
 examples/hello/datamanWriter/CMakeLists.txt   |  3 +--
 examples/hello/hdf5Writer/CMakeLists.txt      |  3 +--
 18 files changed, 29 insertions(+), 75 deletions(-)

diff --git a/examples/basics/globalArray/CMakeLists.txt b/examples/basics/globalArray/CMakeLists.txt
index 621925932..756f67c42 100644
--- a/examples/basics/globalArray/CMakeLists.txt
+++ b/examples/basics/globalArray/CMakeLists.txt
@@ -7,6 +7,5 @@ add_executable(globalArray_write globalArray_write.cpp)
 target_link_libraries(globalArray_write adios2)
 
 if(ADIOS2_HAVE_MPI)
-  target_include_directories(globalArray_write PRIVATE ${MPI_C_INCLUDE_PATH})
-  target_link_libraries(globalArray_write ${MPI_C_LIBRARIES})
+  target_link_libraries(globalArray_write MPI::MPI_C)
 endif()
diff --git a/examples/basics/joinedArray/CMakeLists.txt b/examples/basics/joinedArray/CMakeLists.txt
index a0a7b0641..9d52c2f00 100644
--- a/examples/basics/joinedArray/CMakeLists.txt
+++ b/examples/basics/joinedArray/CMakeLists.txt
@@ -7,6 +7,5 @@ add_executable(joinedArray_write joinedArray_write.cpp)
 target_link_libraries(joinedArray_write adios2)
 
 if(ADIOS2_HAVE_MPI)
-  target_include_directories(joinedArray_write PRIVATE ${MPI_C_INCLUDE_PATH})
-  target_link_libraries(joinedArray_write ${MPI_C_LIBRARIES})
+  target_link_libraries(joinedArray_write MPI::MPI_C)
 endif()
diff --git a/examples/basics/localArray/CMakeLists.txt b/examples/basics/localArray/CMakeLists.txt
index a42506de0..253298edd 100644
--- a/examples/basics/localArray/CMakeLists.txt
+++ b/examples/basics/localArray/CMakeLists.txt
@@ -7,6 +7,5 @@ add_executable(localArray_write localArray_write.cpp)
 target_link_libraries(localArray_write adios2)
 
 if(ADIOS2_HAVE_MPI)
-  target_include_directories(localArray_write PRIVATE ${MPI_C_INCLUDE_PATH})
-  target_link_libraries(localArray_write ${MPI_C_LIBRARIES})
+  target_link_libraries(localArray_write MPI::MPI_C)
 endif()
diff --git a/examples/basics/values/CMakeLists.txt b/examples/basics/values/CMakeLists.txt
index 79e27ea60..3f354e6fb 100644
--- a/examples/basics/values/CMakeLists.txt
+++ b/examples/basics/values/CMakeLists.txt
@@ -7,6 +7,5 @@ add_executable(values_write values_write.cpp)
 target_link_libraries(values_write adios2)
 
 if(ADIOS2_HAVE_MPI)
-  target_include_directories(values_write PRIVATE ${MPI_C_INCLUDE_PATH})
-  target_link_libraries(values_write ${MPI_C_LIBRARIES})
+  target_link_libraries(values_write MPI::MPI_C)
 endif()
diff --git a/examples/experimental/multistep/CMakeLists.txt b/examples/experimental/multistep/CMakeLists.txt
index 546074f51..6da2c803f 100644
--- a/examples/experimental/multistep/CMakeLists.txt
+++ b/examples/experimental/multistep/CMakeLists.txt
@@ -3,15 +3,11 @@
 # accompanying file Copyright.txt for details.
 #------------------------------------------------------------------------------#
 
-add_executable(writer_multistep writer_multistep.cpp)
-add_executable(reader_stepping reader_stepping.cpp)
-add_executable(reader_allsteps reader_allsteps.cpp)
-
 foreach(tgt IN ITEMS writer_multistep reader_stepping reader_allsteps)
+  add_executable(${tgt} ${tgt}.cpp)
   target_link_libraries(${tgt} adios2)
 
   if(ADIOS2_HAVE_MPI)
-    target_include_directories(${tgt} PRIVATE ${MPI_C_INCLUDE_PATH})
-    target_link_libraries(${tgt} ${MPI_C_LIBRARIES})
+    target_link_libraries(${tgt} MPI::MPI_C)
   endif()
 endforeach()
diff --git a/examples/experimental/runtimeconfig/hello/CMakeLists.txt b/examples/experimental/runtimeconfig/hello/CMakeLists.txt
index 9770b299c..d448030a5 100644
--- a/examples/experimental/runtimeconfig/hello/CMakeLists.txt
+++ b/examples/experimental/runtimeconfig/hello/CMakeLists.txt
@@ -1,7 +1,6 @@
 if(ADIOS2_HAVE_MPI)
   add_executable(helloBPWriterXML helloBPWriterXML.cpp)
-  target_include_directories(helloBPWriterXML PRIVATE ${MPI_C_INCLUDE_PATH})
-  target_link_libraries(helloBPWriterXML ${MPI_C_LIBRARIES})
+  target_link_libraries(helloBPWriterXML MPI::MPI_C)
 else()
   add_executable(helloBPWriterXML helloBPWriterXML_nompi.cpp)
 endif()
diff --git a/examples/heatTransfer/read/CMakeLists.txt b/examples/heatTransfer/read/CMakeLists.txt
index 30797b43a..f14e54596 100644
--- a/examples/heatTransfer/read/CMakeLists.txt
+++ b/examples/heatTransfer/read/CMakeLists.txt
@@ -5,18 +5,10 @@
 
 if(ADIOS2_HAVE_MPI)
   add_executable(heatTransfer_read_adios2 heatRead_adios2.cpp PrintData.h)
-  target_include_directories(heatTransfer_read_adios2
-    PRIVATE ${MPI_C_INCLUDE_PATH}
-  )
-  target_link_libraries(heatTransfer_read_adios2 adios2 ${MPI_C_LIBRARIES})
+  target_link_libraries(heatTransfer_read_adios2 adios2 MPI::MPI_C)
 
   if(ADIOS2_HAVE_ADIOS1)
     add_executable(heatTransfer_read_adios1 heatRead_adios1.cpp PrintData.h)
-    target_include_directories(heatTransfer_read_adios1
-      PRIVATE ${MPI_C_INCLUDE_PATH}
-    )
-    target_link_libraries(heatTransfer_read_adios1
-      adios1::adios ${MPI_C_LIBRARIES}
-    )
+    target_link_libraries(heatTransfer_read_adios1 adios1::adios MPI::MPI_C)
   endif()
 endif()
diff --git a/examples/heatTransfer/write/CMakeLists.txt b/examples/heatTransfer/write/CMakeLists.txt
index a6c459bca..51028cb8b 100644
--- a/examples/heatTransfer/write/CMakeLists.txt
+++ b/examples/heatTransfer/write/CMakeLists.txt
@@ -10,11 +10,8 @@ if(ADIOS2_HAVE_MPI)
     Settings.cpp
     IO_adios2.cpp
   )
-  target_include_directories(heatTransfer_write_adios2
-    PRIVATE ${MPI_C_INCLUDE_PATH}
-  )
   target_link_libraries(heatTransfer_write_adios2
-    adios2 ${MPI_C_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
+    adios2 MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT}
   )
   target_compile_definitions(heatTransfer_write_adios2 PRIVATE
    -DDEFAULT_CONFIG=${CMAKE_CURRENT_SOURCE_DIR}/config.xml
@@ -27,11 +24,8 @@ if(ADIOS2_HAVE_MPI)
       Settings.cpp
       IO_adios1.cpp
     )
-    target_include_directories(heatTransfer_write_adios1
-      PRIVATE ${MPI_C_INCLUDE_PATH}
-    )
     target_link_libraries(heatTransfer_write_adios1
-      adios1::adios ${MPI_C_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
+      adios1::adios MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT}
     )
   endif()
 
@@ -43,10 +37,10 @@ if(ADIOS2_HAVE_MPI)
       IO_hdf5_a.cpp
     )
     target_include_directories(heatTransfer_write_hdf5
-      PRIVATE ${MPI_C_INCLUDE_PATH} ${HDF5_C_INCLUDE_DIRS}
+      PRIVATE ${HDF5_C_INCLUDE_DIRS}
     )
     target_link_libraries(heatTransfer_write_hdf5
-      ${HDF5_C_LIBRARIES} ${MPI_C_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
+      ${HDF5_C_LIBRARIES} MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT}
     )
 
     add_executable(heatTransfer_write_ph5
@@ -56,10 +50,10 @@ if(ADIOS2_HAVE_MPI)
       IO_ph5.cpp
     )
     target_include_directories(heatTransfer_write_ph5
-      PRIVATE ${MPI_C_INCLUDE_PATH} ${HDF5_C_INCLUDE_DIRS}
+      PRIVATE ${HDF5_C_INCLUDE_DIRS}
     )
     target_link_libraries(heatTransfer_write_ph5
-      ${HDF5_C_LIBRARIES} ${MPI_C_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
+      ${HDF5_C_LIBRARIES} MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT}
     )
 
     add_executable(heatTransfer_write_a2h5
@@ -69,11 +63,8 @@ if(ADIOS2_HAVE_MPI)
       IO_ph5_adios2.cpp
     )
 
-    target_include_directories(heatTransfer_write_a2h5
-      PRIVATE ${MPI_C_INCLUDE_PATH}
-    )
     target_link_libraries(heatTransfer_write_a2h5
-      adios2 ${MPI_C_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
+      adios2 MPI::MPI_C ${CMAKE_THREAD_LIBS_INIT}
     )
   endif()
 endif()
diff --git a/examples/hello/adios1Writer/CMakeLists.txt b/examples/hello/adios1Writer/CMakeLists.txt
index 3b5c016b6..13f5f66f4 100644
--- a/examples/hello/adios1Writer/CMakeLists.txt
+++ b/examples/hello/adios1Writer/CMakeLists.txt
@@ -5,8 +5,7 @@
 
 if(ADIOS2_HAVE_MPI)
   add_executable(hello_adios1Writer helloADIOS1Writer.cpp)
-  target_include_directories(hello_adios1Writer PRIVATE ${MPI_C_INCLUDE_PATH})
-  target_link_libraries(hello_adios1Writer ${MPI_C_LIBRARIES})
+  target_link_libraries(hello_adios1Writer MPI::MPI_C)
 else()
   add_executable(hello_adios1Writer helloADIOS1Writer_nompi.cpp)
 endif()
diff --git a/examples/hello/bpAttributeWriter/CMakeLists.txt b/examples/hello/bpAttributeWriter/CMakeLists.txt
index 30faba4af..908d48c35 100644
--- a/examples/hello/bpAttributeWriter/CMakeLists.txt
+++ b/examples/hello/bpAttributeWriter/CMakeLists.txt
@@ -7,8 +7,7 @@ if(ADIOS2_HAVE_MPI)
   find_package(MPI COMPONENTS C REQUIRED)
 
   add_executable(hello_bpAttributeWriter helloBPAttributeWriter.cpp)
-  target_include_directories(hello_bpAttributeWriter PRIVATE ${MPI_C_INCLUDE_PATH})
-  target_link_libraries(hello_bpAttributeWriter ${MPI_C_LIBRARIES})
+  target_link_libraries(hello_bpAttributeWriter MPI::MPI_C)
   
 else()
   add_executable(hello_bpAttributeWriter helloBPAttributeWriter_nompi.cpp)
diff --git a/examples/hello/bpBZip2Wrapper/CMakeLists.txt b/examples/hello/bpBZip2Wrapper/CMakeLists.txt
index 702d5aaeb..e1654cf16 100644
--- a/examples/hello/bpBZip2Wrapper/CMakeLists.txt
+++ b/examples/hello/bpBZip2Wrapper/CMakeLists.txt
@@ -5,8 +5,7 @@
 
 if(ADIOS2_HAVE_MPI)
   add_executable(hello_bpBZip2Wrapper helloBPBZip2Wrapper.cpp)
-  target_include_directories(hello_bpBZip2Wrapper PRIVATE ${MPI_C_INCLUDE_PATH})
-  target_link_libraries(hello_bpBZip2Wrapper ${MPI_C_LIBRARIES})
+  target_link_libraries(hello_bpBZip2Wrapper MPI::MPI_C)
 else()
   add_executable(hello_bpBZip2Wrapper helloBPBZip2Wrapper_nompi.cpp)
 endif()
diff --git a/examples/hello/bpFlushWriter/CMakeLists.txt b/examples/hello/bpFlushWriter/CMakeLists.txt
index 777704ef2..43a55fc64 100644
--- a/examples/hello/bpFlushWriter/CMakeLists.txt
+++ b/examples/hello/bpFlushWriter/CMakeLists.txt
@@ -5,8 +5,7 @@
 
 if(ADIOS2_HAVE_MPI)
   add_executable(hello_bpFlushWriter helloBPFlushWriter.cpp)
-  target_include_directories(hello_bpFlushWriter PRIVATE ${MPI_C_INCLUDE_PATH})
-  target_link_libraries(hello_bpFlushWriter ${MPI_C_LIBRARIES})
+  target_link_libraries(hello_bpFlushWriter MPI::MPI_C)
 else()
   add_executable(hello_bpFlushWriter helloBPFlushWriter_nompi.cpp)
 endif()
diff --git a/examples/hello/bpTimeWriter/CMakeLists.txt b/examples/hello/bpTimeWriter/CMakeLists.txt
index 68834e288..d3f8bc7d8 100644
--- a/examples/hello/bpTimeWriter/CMakeLists.txt
+++ b/examples/hello/bpTimeWriter/CMakeLists.txt
@@ -5,8 +5,7 @@
 
 if(ADIOS2_HAVE_MPI)
   add_executable(hello_bpTimeWriter helloBPTimeWriter.cpp)
-  target_include_directories(hello_bpTimeWriter PRIVATE ${MPI_C_INCLUDE_PATH})
-  target_link_libraries(hello_bpTimeWriter ${MPI_C_LIBRARIES})
+  target_link_libraries(hello_bpTimeWriter MPI::MPI_C)
 else()
   add_executable(hello_bpTimeWriter helloBPTimeWriter_nompi.cpp)
 endif()
diff --git a/examples/hello/bpWriter/CMakeLists.txt b/examples/hello/bpWriter/CMakeLists.txt
index 8c834597a..3f3f19f4a 100644
--- a/examples/hello/bpWriter/CMakeLists.txt
+++ b/examples/hello/bpWriter/CMakeLists.txt
@@ -5,21 +5,14 @@
 
 if(ADIOS2_HAVE_MPI)
   add_executable(hello_bpWriter helloBPWriter.cpp)
-  target_include_directories(hello_bpWriter PRIVATE ${MPI_C_INCLUDE_PATH})
-  target_link_libraries(hello_bpWriter ${MPI_C_LIBRARIES})
+  target_link_libraries(hello_bpWriter MPI::MPI_C)
   
   add_executable(hello_bpWriter_c helloBPWriter.c)
-  target_include_directories(hello_bpWriter_c PRIVATE ${MPI_C_INCLUDE_PATH})
-  target_link_libraries(hello_bpWriter_c ${MPI_C_LIBRARIES})
+  target_link_libraries(hello_bpWriter_c MPI::MPI_C)
   
   if(ADIOS2_HAVE_Fortran)
     add_executable(hello_bpWriter_f helloBPWriter.f90)
-    target_include_directories(hello_bpWriter_f 
-                               PRIVATE ${MPI_Fortran_INCLUDE_PATH} 
-                                       ${MPI_C_INCLUDE_PATH})
-                                               
-    target_link_libraries(hello_bpWriter_f PRIVATE ${MPI_Fortran_LIBRARIES} 
-                                                   ${MPI_C_LIBRARIES})
+    target_link_libraries(hello_bpWriter_f MPI::MPI_Fortran adios2_f)
   endif()
   
 else()
@@ -28,13 +21,9 @@ else()
 
   if(ADIOS2_HAVE_Fortran)
     add_executable(hello_bpWriter_f helloBPWriter_nompi.f90)
+    target_link_libraries(hello_bpWriter_f adios2_f)
   endif()
-  
 endif()
 
 target_link_libraries(hello_bpWriter adios2)
 target_link_libraries(hello_bpWriter_c adios2)
-
-if(ADIOS2_HAVE_Fortran)
-  target_link_libraries(hello_bpWriter_f PRIVATE adios2_f)
-endif()
diff --git a/examples/hello/bpZfpWrapper/CMakeLists.txt b/examples/hello/bpZfpWrapper/CMakeLists.txt
index c6802384e..5593e42db 100644
--- a/examples/hello/bpZfpWrapper/CMakeLists.txt
+++ b/examples/hello/bpZfpWrapper/CMakeLists.txt
@@ -5,8 +5,7 @@
 
 if(ADIOS2_HAVE_MPI)
   add_executable(hello_bpZfpWrapper helloBPZfpWrapper.cpp)
-  target_include_directories(hello_bpZfpWrapper PRIVATE ${MPI_C_INCLUDE_PATH})
-  target_link_libraries(hello_bpZfpWrapper ${MPI_C_LIBRARIES})
+  target_link_libraries(hello_bpZfpWrapper MPI::MPI_C)
   
 else()
   add_executable(hello_bpZfpWrapper helloBPZfpWrapper_nompi.cpp)
diff --git a/examples/hello/datamanReader/CMakeLists.txt b/examples/hello/datamanReader/CMakeLists.txt
index 1c1baa846..66a87b889 100644
--- a/examples/hello/datamanReader/CMakeLists.txt
+++ b/examples/hello/datamanReader/CMakeLists.txt
@@ -5,8 +5,7 @@
 
 if(ADIOS2_HAVE_MPI)
   add_executable(hello_datamanReader helloDataManReader.cpp)
-  target_include_directories(hello_datamanReader PRIVATE ${MPI_C_INCLUDE_PATH})
-  target_link_libraries(hello_datamanReader ${MPI_C_LIBRARIES})
+  target_link_libraries(hello_datamanReader MPI::MPI_C)
 else()
   add_executable(hello_datamanReader helloDataManReader_nompi.cpp)
 endif()
diff --git a/examples/hello/datamanWriter/CMakeLists.txt b/examples/hello/datamanWriter/CMakeLists.txt
index 4a41f3e73..83196e95f 100644
--- a/examples/hello/datamanWriter/CMakeLists.txt
+++ b/examples/hello/datamanWriter/CMakeLists.txt
@@ -5,8 +5,7 @@
 
 if(ADIOS2_HAVE_MPI)
   add_executable(hello_datamanWriter helloDataManWriter.cpp)
-  target_include_directories(hello_datamanWriter PRIVATE ${MPI_C_INCLUDE_PATH})
-  target_link_libraries(hello_datamanWriter ${MPI_C_LIBRARIES})
+  target_link_libraries(hello_datamanWriter MPI::MPI_C)
 else()
   add_executable(hello_datamanWriter helloDataManWriter_nompi.cpp)
 endif()
diff --git a/examples/hello/hdf5Writer/CMakeLists.txt b/examples/hello/hdf5Writer/CMakeLists.txt
index d5d431125..6ca2b2752 100644
--- a/examples/hello/hdf5Writer/CMakeLists.txt
+++ b/examples/hello/hdf5Writer/CMakeLists.txt
@@ -5,8 +5,7 @@
 
 if(ADIOS2_HAVE_MPI)
   add_executable(hello_hdf5Writer helloHDF5Writer.cpp)
-  target_include_directories(hello_hdf5Writer PRIVATE ${MPI_C_INCLUDE_PATH})
-  target_link_libraries(hello_hdf5Writer ${MPI_C_LIBRARIES})
+  target_link_libraries(hello_hdf5Writer MPI::MPI_C)
 else()
   add_executable(hello_hdf5Writer helloHDF5Writer_nompi.cpp)
 endif()
-- 
GitLab