From 92e04d70117b1df72d43f82cdfaea30172c5e060 Mon Sep 17 00:00:00 2001
From: Chuck Atkins <chuck.atkins@kitware.com>
Date: Fri, 15 Feb 2019 09:46:30 -0500
Subject: [PATCH] Make generation of adios2-config work without Fortran enabled

---
 CMakeLists.txt                             |  6 +-
 cmake/install/CMakeLists.txt               |  5 ++
 cmake/install/generate-adios2-config.sh.in | 72 ++++++++++++++--------
 3 files changed, 54 insertions(+), 29 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index f683626af..7fe6d828e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -199,10 +199,12 @@ endif()
 #------------------------------------------------------------------------------#
 GenerateADIOSPackageConfig()
 
-# It's certainly a little awkward to have this lass add_subdirectory but it's
+# It's certainly a little awkward to have this last add_subdirectory but it's
 # currently the only way to guarantee installation order for the static config
 # generation script
-add_subdirectory(cmake/install)
+if(UNIX)
+  add_subdirectory(cmake/install)
+endif()
 
 #------------------------------------------------------------------------------#
 # Configuration summary
diff --git a/cmake/install/CMakeLists.txt b/cmake/install/CMakeLists.txt
index b08a8c688..403c82daa 100644
--- a/cmake/install/CMakeLists.txt
+++ b/cmake/install/CMakeLists.txt
@@ -1,3 +1,8 @@
+if(ADIOS2_HAVE_Fortran)
+  set(ADIOS2_CONFIG_FORTRAN 1)
+else()
+  set(ADIOS2_CONFIG_FORTRAN 0)
+endif()
 configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/generate-adios2-config.sh.in
   ${CMAKE_CURRENT_BINARY_DIR}/generate-adios2-config.sh
diff --git a/cmake/install/generate-adios2-config.sh.in b/cmake/install/generate-adios2-config.sh.in
index 63866c0fd..1349a7af9 100755
--- a/cmake/install/generate-adios2-config.sh.in
+++ b/cmake/install/generate-adios2-config.sh.in
@@ -53,49 +53,67 @@ BUILD_DIR=$(mktemp -d)
 pushd ${BUILD_DIR}
 
 echo "Configuring adios2-config dummy CMake project"
-if ! ${CMAKE} -G "Unix Makefiles" ${SOURCE_DIR} 
+if ! ${CMAKE} -G "Unix Makefiles" ${SOURCE_DIR} ${EXTRA_CMAKE_ARGS}
 then
   echo "Failed"
   exit 1
 fi
 
-echo "Extacting build flags with and without ADIOS"
-make_target_flags without_C
-make_target_flags without_CXX
-make_target_flags without_Fortran
-make_target_flags with_C
-make_target_flags with_CXX
-make_target_flags with_Fortran
+rm -f adios2.flags
 
+echo "Extacting ADIOS flags for C bindings"
+echo "  Without ADIOS"
+make_target_flags without_C
 without_C_CFLAGS=$(head -1 without_C.flags)
 without_C_LDFLAGS=$(tail -1 without_C.flags)
-without_CXX_CXXFLAGS=$(head -1 without_CXX.flags)
-without_CXX_LDFLAGS=$(tail -1 without_CXX.flags)
-without_Fortran_FFLAGS=$(head -1 without_Fortran.flags)
-without_Fortran_LDFLAGS=$(tail -1 without_Fortran.flags)
-
+echo "  With ADIOS"
+make_target_flags with_C
 with_C_CFLAGS=$(head -1 with_C.flags)
 with_C_LDFLAGS=$(tail -1 with_C.flags)
-with_CXX_CXXFLAGS=$(head -1 with_CXX.flags)
-with_CXX_LDFLAGS=$(tail -1 with_CXX.flags)
-with_Fortran_FFLAGS=$(head -1 with_Fortran.flags)
-with_Fortran_LDFLAGS=$(tail -1 with_Fortran.flags)
-
-echo "Computing diff"
+echo "  Extracting diff"
 ADIOS2_C_CFLAGS="$(prefixify $(flag_diff "${without_C_CFLAGS}" "${with_C_CFLAGS}"))"
 ADIOS2_C_LDFLAGS="$(prefixify $(flag_diff "${without_C_LDFLAGS}" "${with_C_LDFLAGS}"))"
-ADIOS2_CXX_CXXFLAGS="$(prefixify $(flag_diff "${without_CXX_CXXFLAGS}" "${with_CXX_CXXFLAGS}"))"
-ADIOS2_CXX_LDFLAGS="$(prefixify $(flag_diff "${without_CXX_LDFLAGS}" "${with_CXX_LDFLAGS}"))"
-ADIOS2_Fortran_FFLAGS="$(prefixify $(flag_diff "${without_Fortran_FFLAGS}" "${with_Fortran_FFLAGS}"))"
-ADIOS2_Fortran_LDFLAGS="$(prefixify $(flag_diff "${without_Fortran_LDFLAGS}" "${with_Fortran_LDFLAGS}"))"
-
-rm -f adios2.flags
+echo "  Exporting"
 echo ADIOS2_C_CFLAGS=\"${ADIOS2_C_CFLAGS}\" >> adios2.flags
 echo ADIOS2_C_LDFLAGS=\"${ADIOS2_C_LDFLAGS}\" >> adios2.flags
+
+echo "Extacting ADIOS flags for C++ bindings"
+echo "  Without ADIOS"
+make_target_flags without_CXX
+without_CXX_CXXFLAGS=$(head -1 without_CXX.flags)
+without_CXX_LDFLAGS=$(tail -1 without_CXX.flags)
+echo "  With ADIOS"
+make_target_flags with_CXX
+with_CXX_CXXFLAGS=$(head -1 with_CXX.flags)
+with_CXX_LDFLAGS=$(tail -1 with_CXX.flags)
+echo "  Extracting diff"
+ADIOS2_CXX_CXXFLAGS="$(prefixify $(flag_diff "${without_CXX_CXXFLAGS}" "${with_CXX_CXXFLAGS}"))"
+ADIOS2_CXX_LDFLAGS="$(prefixify $(flag_diff "${without_CXX_LDFLAGS}" "${with_CXX_LDFLAGS}"))"
+echo "  Exporting"
 echo ADIOS2_CXX_CXXFLAGS=\"${ADIOS2_CXX_CXXFLAGS}\" >> adios2.flags
 echo ADIOS2_CXX_LDFLAGS=\"${ADIOS2_CXX_LDFLAGS}\" >> adios2.flags
-echo ADIOS2_Fortran_FFLAGS=\"${ADIOS2_Fortran_FFLAGS}\" >> adios2.flags
-echo ADIOS2_Fortran_LDFLAGS=\"${ADIOS2_Fortran_LDFLAGS}\" >> adios2.flags
+
+if [ @ADIOS2_CONFIG_FORTRAN@ -eq 1 ]
+then
+  echo "Extacting ADIOS flags for Fortran bindings"
+  echo "  Without ADIOS"
+  make_target_flags without_Fortran
+  without_Fortran_FFLAGS=$(head -1 without_Fortran.flags)
+  without_Fortran_LDFLAGS=$(tail -1 without_Fortran.flags)
+  echo "  With ADIOS"
+  make_target_flags with_Fortran
+  with_Fortran_FFLAGS=$(head -1 with_Fortran.flags)
+  with_Fortran_LDFLAGS=$(tail -1 with_Fortran.flags)
+  echo "  Extracting diff"
+  ADIOS2_Fortran_FFLAGS="$(prefixify $(flag_diff "${without_Fortran_FFLAGS}" "${with_Fortran_FFLAGS}"))"
+  ADIOS2_Fortran_LDFLAGS="$(prefixify $(flag_diff "${without_Fortran_LDFLAGS}" "${with_Fortran_LDFLAGS}"))"
+  echo "  Exporting"
+  echo ADIOS2_Fortran_FFLAGS=\"${ADIOS2_Fortran_FFLAGS}\" >> adios2.flags
+  echo ADIOS2_Fortran_LDFLAGS=\"${ADIOS2_Fortran_LDFLAGS}\" >> adios2.flags
+else
+  echo ADIOS2_Fortran_FFLAGS="" >> adios2.flags
+  echo ADIOS2_Fortran_LDFLAGS="" >> adios2.flags
+fi
 
 echo "Writing @CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_BINDIR@/adios2-config"
 cat \
-- 
GitLab