From b012a9f7412a58ff1e341c8423bfdfd7f5c9f479 Mon Sep 17 00:00:00 2001
From: Chuck Atkins <chuck.atkins@kitware.com>
Date: Mon, 21 Aug 2017 10:59:02 -0400
Subject: [PATCH] CMake: Remove local dependency searching from examples

---
 examples/basics/globalArray/CMakeLists.txt    |  1 -
 examples/basics/joinedArray/CMakeLists.txt    |  1 -
 examples/basics/localArray/CMakeLists.txt     |  1 -
 examples/basics/values/CMakeLists.txt         |  1 -
 .../experimental/multistep/CMakeLists.txt     | 21 +++------
 .../runtimeconfig/hello/CMakeLists.txt        |  2 -
 examples/heatTransfer/read/CMakeLists.txt     | 20 +++------
 examples/heatTransfer/write/CMakeLists.txt    | 44 +++++--------------
 examples/hello/adios1Writer/CMakeLists.txt    |  2 -
 examples/hello/bpBZip2Wrapper/CMakeLists.txt  |  4 --
 examples/hello/bpFlushWriter/CMakeLists.txt   |  2 -
 examples/hello/bpTimeWriter/CMakeLists.txt    |  2 -
 examples/hello/bpWriter/CMakeLists.txt        |  7 +--
 examples/hello/bpZfpWrapper/CMakeLists.txt    |  3 --
 examples/hello/datamanReader/CMakeLists.txt   |  2 -
 examples/hello/datamanWriter/CMakeLists.txt   |  2 -
 examples/hello/hdf5Writer/CMakeLists.txt      |  2 -
 17 files changed, 26 insertions(+), 91 deletions(-)

diff --git a/examples/basics/globalArray/CMakeLists.txt b/examples/basics/globalArray/CMakeLists.txt
index f9a9b07dd..621925932 100644
--- a/examples/basics/globalArray/CMakeLists.txt
+++ b/examples/basics/globalArray/CMakeLists.txt
@@ -7,7 +7,6 @@ add_executable(globalArray_write globalArray_write.cpp)
 target_link_libraries(globalArray_write adios2)
 
 if(ADIOS2_HAVE_MPI)
-  find_package(MPI COMPONENTS C REQUIRED)
   target_include_directories(globalArray_write PRIVATE ${MPI_C_INCLUDE_PATH})
   target_link_libraries(globalArray_write ${MPI_C_LIBRARIES})
 endif()
diff --git a/examples/basics/joinedArray/CMakeLists.txt b/examples/basics/joinedArray/CMakeLists.txt
index f8d775e84..a0a7b0641 100644
--- a/examples/basics/joinedArray/CMakeLists.txt
+++ b/examples/basics/joinedArray/CMakeLists.txt
@@ -7,7 +7,6 @@ add_executable(joinedArray_write joinedArray_write.cpp)
 target_link_libraries(joinedArray_write adios2)
 
 if(ADIOS2_HAVE_MPI)
-  find_package(MPI COMPONENTS C REQUIRED)
   target_include_directories(joinedArray_write PRIVATE ${MPI_C_INCLUDE_PATH})
   target_link_libraries(joinedArray_write ${MPI_C_LIBRARIES})
 endif()
diff --git a/examples/basics/localArray/CMakeLists.txt b/examples/basics/localArray/CMakeLists.txt
index 3f46669a6..a42506de0 100644
--- a/examples/basics/localArray/CMakeLists.txt
+++ b/examples/basics/localArray/CMakeLists.txt
@@ -7,7 +7,6 @@ add_executable(localArray_write localArray_write.cpp)
 target_link_libraries(localArray_write adios2)
 
 if(ADIOS2_HAVE_MPI)
-  find_package(MPI COMPONENTS C REQUIRED)
   target_include_directories(localArray_write PRIVATE ${MPI_C_INCLUDE_PATH})
   target_link_libraries(localArray_write ${MPI_C_LIBRARIES})
 endif()
diff --git a/examples/basics/values/CMakeLists.txt b/examples/basics/values/CMakeLists.txt
index 619fdc326..79e27ea60 100644
--- a/examples/basics/values/CMakeLists.txt
+++ b/examples/basics/values/CMakeLists.txt
@@ -7,7 +7,6 @@ add_executable(values_write values_write.cpp)
 target_link_libraries(values_write adios2)
 
 if(ADIOS2_HAVE_MPI)
-  find_package(MPI COMPONENTS C REQUIRED)
   target_include_directories(values_write PRIVATE ${MPI_C_INCLUDE_PATH})
   target_link_libraries(values_write ${MPI_C_LIBRARIES})
 endif()
diff --git a/examples/experimental/multistep/CMakeLists.txt b/examples/experimental/multistep/CMakeLists.txt
index b5f75bb22..546074f51 100644
--- a/examples/experimental/multistep/CMakeLists.txt
+++ b/examples/experimental/multistep/CMakeLists.txt
@@ -6,19 +6,12 @@
 add_executable(writer_multistep writer_multistep.cpp)
 add_executable(reader_stepping reader_stepping.cpp)
 add_executable(reader_allsteps reader_allsteps.cpp)
-target_link_libraries(writer_multistep adios2)
-target_link_libraries(reader_stepping adios2)
-target_link_libraries(reader_allsteps adios2)
 
-if(ADIOS2_HAVE_MPI)
-  find_package(MPI COMPONENTS C REQUIRED)
+foreach(tgt IN ITEMS writer_multistep reader_stepping reader_allsteps)
+  target_link_libraries(${tgt} adios2)
 
-  target_include_directories(writer_multistep PRIVATE ${MPI_C_INCLUDE_PATH})
-  target_link_libraries(writer_multistep ${MPI_C_LIBRARIES})
-
-  target_include_directories(reader_stepping PRIVATE ${MPI_C_INCLUDE_PATH})
-  target_link_libraries(reader_stepping ${MPI_C_LIBRARIES})
-
-  target_include_directories(reader_allsteps PRIVATE ${MPI_C_INCLUDE_PATH})
-  target_link_libraries(reader_allsteps ${MPI_C_LIBRARIES})
-endif()
+  if(ADIOS2_HAVE_MPI)
+    target_include_directories(${tgt} PRIVATE ${MPI_C_INCLUDE_PATH})
+    target_link_libraries(${tgt} ${MPI_C_LIBRARIES})
+  endif()
+endforeach()
diff --git a/examples/experimental/runtimeconfig/hello/CMakeLists.txt b/examples/experimental/runtimeconfig/hello/CMakeLists.txt
index 28adedce7..9770b299c 100644
--- a/examples/experimental/runtimeconfig/hello/CMakeLists.txt
+++ b/examples/experimental/runtimeconfig/hello/CMakeLists.txt
@@ -1,6 +1,4 @@
 if(ADIOS2_HAVE_MPI)
-  find_package(MPI COMPONENTS C REQUIRED)
-
   add_executable(helloBPWriterXML helloBPWriterXML.cpp)
   target_include_directories(helloBPWriterXML PRIVATE ${MPI_C_INCLUDE_PATH})
   target_link_libraries(helloBPWriterXML ${MPI_C_LIBRARIES})
diff --git a/examples/heatTransfer/read/CMakeLists.txt b/examples/heatTransfer/read/CMakeLists.txt
index d1b7e2853..30797b43a 100644
--- a/examples/heatTransfer/read/CMakeLists.txt
+++ b/examples/heatTransfer/read/CMakeLists.txt
@@ -4,20 +4,13 @@
 #------------------------------------------------------------------------------#
 
 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})
 
   if(ADIOS2_HAVE_ADIOS1)
-  
-    find_package(MPI COMPONENTS C REQUIRED)
-    find_package(ADIOS1 REQUIRED)
-    
-    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}
-    )
-
     add_executable(heatTransfer_read_adios1 heatRead_adios1.cpp PrintData.h)
     target_include_directories(heatTransfer_read_adios1
       PRIVATE ${MPI_C_INCLUDE_PATH}
@@ -26,5 +19,4 @@ if(ADIOS2_HAVE_MPI)
       adios1::adios ${MPI_C_LIBRARIES}
     )
   endif()
-  
-endif()
\ No newline at end of file
+endif()
diff --git a/examples/heatTransfer/write/CMakeLists.txt b/examples/heatTransfer/write/CMakeLists.txt
index a40186bb0..a6c459bca 100644
--- a/examples/heatTransfer/write/CMakeLists.txt
+++ b/examples/heatTransfer/write/CMakeLists.txt
@@ -4,9 +4,6 @@
 #------------------------------------------------------------------------------#
 
 if(ADIOS2_HAVE_MPI)
-  find_package(MPI COMPONENTS C REQUIRED)
-  find_package(Threads REQUIRED)
-
   add_executable(heatTransfer_write_adios2
     main.cpp
     HeatTransfer.cpp
@@ -16,15 +13,14 @@ if(ADIOS2_HAVE_MPI)
   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})
+  target_link_libraries(heatTransfer_write_adios2
+    adios2 ${MPI_C_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
+  )
   target_compile_definitions(heatTransfer_write_adios2 PRIVATE
-   -DDEFAULT_CONFIG=${CMAKE_CURRENT_SOURCE_DIR}/config.xml)
+   -DDEFAULT_CONFIG=${CMAKE_CURRENT_SOURCE_DIR}/config.xml
+  )
 
   if(ADIOS2_HAVE_ADIOS1)
-    find_package(ADIOS1 REQUIRED)
-    find_package(MPI COMPONENTS C REQUIRED)
-
     add_executable(heatTransfer_write_adios1
       main.cpp
       HeatTransfer.cpp
@@ -40,9 +36,6 @@ if(ADIOS2_HAVE_MPI)
   endif()
 
   if(ADIOS2_HAVE_HDF5)
-    find_package(HDF5 REQUIRED)
-    find_package(MPI COMPONENTS C REQUIRED)
-
     add_executable(heatTransfer_write_hdf5
       main.cpp
       HeatTransfer.cpp
@@ -53,14 +46,8 @@ if(ADIOS2_HAVE_MPI)
       PRIVATE ${MPI_C_INCLUDE_PATH} ${HDF5_C_INCLUDE_DIRS}
     )
     target_link_libraries(heatTransfer_write_hdf5
-      ${MPI_C_LIBRARIES} ${HDF5_C_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
+      ${HDF5_C_LIBRARIES} ${MPI_C_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
     )
-  endif()
-
-
-  if(ADIOS2_HAVE_HDF5)
-    find_package(HDF5 REQUIRED)
-    find_package(MPI COMPONENTS C REQUIRED)
 
     add_executable(heatTransfer_write_ph5
       main.cpp
@@ -72,15 +59,10 @@ if(ADIOS2_HAVE_MPI)
       PRIVATE ${MPI_C_INCLUDE_PATH} ${HDF5_C_INCLUDE_DIRS}
     )
     target_link_libraries(heatTransfer_write_ph5
-      ${MPI_C_LIBRARIES} ${HDF5_C_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
+      ${HDF5_C_LIBRARIES} ${MPI_C_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
     )
-  endif()
-
-
-  if(ADIOS2_HAVE_HDF5)
-     find_package(MPI COMPONENTS C REQUIRED)
 
-     add_executable(heatTransfer_write_a2h5
+    add_executable(heatTransfer_write_a2h5
       main.cpp
       HeatTransfer.cpp
       Settings.cpp
@@ -90,12 +72,8 @@ if(ADIOS2_HAVE_MPI)
     target_include_directories(heatTransfer_write_a2h5
       PRIVATE ${MPI_C_INCLUDE_PATH}
     )
-    #target_link_libraries(heatTransfer_write_a2h5
-    #  ${MPI_C_LIBRARIES} 
-    #)
-    target_link_libraries(heatTransfer_write_a2h5 PUBLIC adios2 
-                          ${CMAKE_THREAD_LIBS_INIT})
-
+    target_link_libraries(heatTransfer_write_a2h5
+      adios2 ${MPI_C_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
+    )
   endif()
-
 endif()
diff --git a/examples/hello/adios1Writer/CMakeLists.txt b/examples/hello/adios1Writer/CMakeLists.txt
index f8e52ae9d..3b5c016b6 100644
--- a/examples/hello/adios1Writer/CMakeLists.txt
+++ b/examples/hello/adios1Writer/CMakeLists.txt
@@ -4,8 +4,6 @@
 #------------------------------------------------------------------------------#
 
 if(ADIOS2_HAVE_MPI)
-  find_package(MPI COMPONENTS C REQUIRED)
-
   add_executable(hello_adios1Writer helloADIOS1Writer.cpp)
   target_include_directories(hello_adios1Writer PRIVATE ${MPI_C_INCLUDE_PATH})
   target_link_libraries(hello_adios1Writer ${MPI_C_LIBRARIES})
diff --git a/examples/hello/bpBZip2Wrapper/CMakeLists.txt b/examples/hello/bpBZip2Wrapper/CMakeLists.txt
index 3803a998a..702d5aaeb 100644
--- a/examples/hello/bpBZip2Wrapper/CMakeLists.txt
+++ b/examples/hello/bpBZip2Wrapper/CMakeLists.txt
@@ -4,15 +4,11 @@
 #------------------------------------------------------------------------------#
 
 if(ADIOS2_HAVE_MPI)
-  find_package(MPI COMPONENTS C REQUIRED)
-
   add_executable(hello_bpBZip2Wrapper helloBPBZip2Wrapper.cpp)
   target_include_directories(hello_bpBZip2Wrapper PRIVATE ${MPI_C_INCLUDE_PATH})
   target_link_libraries(hello_bpBZip2Wrapper ${MPI_C_LIBRARIES})
-  
 else()
   add_executable(hello_bpBZip2Wrapper helloBPBZip2Wrapper_nompi.cpp)
-  
 endif()
 
 target_link_libraries(hello_bpBZip2Wrapper adios2)
diff --git a/examples/hello/bpFlushWriter/CMakeLists.txt b/examples/hello/bpFlushWriter/CMakeLists.txt
index ed554a4b4..777704ef2 100644
--- a/examples/hello/bpFlushWriter/CMakeLists.txt
+++ b/examples/hello/bpFlushWriter/CMakeLists.txt
@@ -4,8 +4,6 @@
 #------------------------------------------------------------------------------#
 
 if(ADIOS2_HAVE_MPI)
-  find_package(MPI COMPONENTS C REQUIRED)
-
   add_executable(hello_bpFlushWriter helloBPFlushWriter.cpp)
   target_include_directories(hello_bpFlushWriter PRIVATE ${MPI_C_INCLUDE_PATH})
   target_link_libraries(hello_bpFlushWriter ${MPI_C_LIBRARIES})
diff --git a/examples/hello/bpTimeWriter/CMakeLists.txt b/examples/hello/bpTimeWriter/CMakeLists.txt
index 30551c498..68834e288 100644
--- a/examples/hello/bpTimeWriter/CMakeLists.txt
+++ b/examples/hello/bpTimeWriter/CMakeLists.txt
@@ -4,8 +4,6 @@
 #------------------------------------------------------------------------------#
 
 if(ADIOS2_HAVE_MPI)
-  find_package(MPI COMPONENTS C REQUIRED)
-
   add_executable(hello_bpTimeWriter helloBPTimeWriter.cpp)
   target_include_directories(hello_bpTimeWriter PRIVATE ${MPI_C_INCLUDE_PATH})
   target_link_libraries(hello_bpTimeWriter ${MPI_C_LIBRARIES})
diff --git a/examples/hello/bpWriter/CMakeLists.txt b/examples/hello/bpWriter/CMakeLists.txt
index ba4172948..2bd5b2881 100644
--- a/examples/hello/bpWriter/CMakeLists.txt
+++ b/examples/hello/bpWriter/CMakeLists.txt
@@ -4,8 +4,6 @@
 #------------------------------------------------------------------------------#
 
 if(ADIOS2_HAVE_MPI)
-  find_package(MPI COMPONENTS C REQUIRED)
-
   add_executable(hello_bpWriter helloBPWriter.cpp)
   target_include_directories(hello_bpWriter PRIVATE ${MPI_C_INCLUDE_PATH})
   target_link_libraries(hello_bpWriter ${MPI_C_LIBRARIES})
@@ -18,15 +16,14 @@ if(ADIOS2_HAVE_MPI)
   
 else()
   add_executable(hello_bpWriter helloBPWriter_nompi.cpp)
-  
+
   if(ADIOS2_HAVE_C)
     add_executable(hello_bpWriter_c helloBPWriter_nompi.c)
   endif()
-  
 endif()
 
 target_link_libraries(hello_bpWriter adios2)
 
 if(ADIOS2_HAVE_C)
   target_link_libraries(hello_bpWriter_c adios2_c adios2)
-endif()
\ No newline at end of file
+endif()
diff --git a/examples/hello/bpZfpWrapper/CMakeLists.txt b/examples/hello/bpZfpWrapper/CMakeLists.txt
index c5cb52b74..c6802384e 100644
--- a/examples/hello/bpZfpWrapper/CMakeLists.txt
+++ b/examples/hello/bpZfpWrapper/CMakeLists.txt
@@ -4,15 +4,12 @@
 #------------------------------------------------------------------------------#
 
 if(ADIOS2_HAVE_MPI)
-  find_package(MPI COMPONENTS C REQUIRED)
-
   add_executable(hello_bpZfpWrapper helloBPZfpWrapper.cpp)
   target_include_directories(hello_bpZfpWrapper PRIVATE ${MPI_C_INCLUDE_PATH})
   target_link_libraries(hello_bpZfpWrapper ${MPI_C_LIBRARIES})
   
 else()
   add_executable(hello_bpZfpWrapper helloBPZfpWrapper_nompi.cpp)
-  
 endif()
 
 target_link_libraries(hello_bpZfpWrapper adios2)
diff --git a/examples/hello/datamanReader/CMakeLists.txt b/examples/hello/datamanReader/CMakeLists.txt
index f180c9062..1c1baa846 100644
--- a/examples/hello/datamanReader/CMakeLists.txt
+++ b/examples/hello/datamanReader/CMakeLists.txt
@@ -4,8 +4,6 @@
 #------------------------------------------------------------------------------#
 
 if(ADIOS2_HAVE_MPI)
-  find_package(MPI COMPONENTS C REQUIRED)
-
   add_executable(hello_datamanReader helloDataManReader.cpp)
   target_include_directories(hello_datamanReader PRIVATE ${MPI_C_INCLUDE_PATH})
   target_link_libraries(hello_datamanReader ${MPI_C_LIBRARIES})
diff --git a/examples/hello/datamanWriter/CMakeLists.txt b/examples/hello/datamanWriter/CMakeLists.txt
index 3e5c95583..4a41f3e73 100644
--- a/examples/hello/datamanWriter/CMakeLists.txt
+++ b/examples/hello/datamanWriter/CMakeLists.txt
@@ -4,8 +4,6 @@
 #------------------------------------------------------------------------------#
 
 if(ADIOS2_HAVE_MPI)
-  find_package(MPI COMPONENTS C REQUIRED)
-  
   add_executable(hello_datamanWriter helloDataManWriter.cpp)
   target_include_directories(hello_datamanWriter PRIVATE ${MPI_C_INCLUDE_PATH})
   target_link_libraries(hello_datamanWriter ${MPI_C_LIBRARIES})
diff --git a/examples/hello/hdf5Writer/CMakeLists.txt b/examples/hello/hdf5Writer/CMakeLists.txt
index a2f7e6abd..d5d431125 100644
--- a/examples/hello/hdf5Writer/CMakeLists.txt
+++ b/examples/hello/hdf5Writer/CMakeLists.txt
@@ -4,8 +4,6 @@
 #------------------------------------------------------------------------------#
 
 if(ADIOS2_HAVE_MPI)
-  find_package(MPI COMPONENTS C REQUIRED)
-
   add_executable(hello_hdf5Writer helloHDF5Writer.cpp)
   target_include_directories(hello_hdf5Writer PRIVATE ${MPI_C_INCLUDE_PATH})
   target_link_libraries(hello_hdf5Writer ${MPI_C_LIBRARIES})
-- 
GitLab