From 80aa1908e258bf223326556a150a93b745de3cb8 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de>
Date: Mon, 22 Jun 2020 18:23:46 +0200
Subject: [PATCH] CMake: move and merge code that locates DLLs

---
 Core/CMakeLists.txt                   | 13 ++++++++-----
 cmake/generic/modules/FindFFTW3.cmake |  7 -------
 cmake/generic/modules/FindTIFF.cmake  |  7 +------
 3 files changed, 9 insertions(+), 18 deletions(-)

diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt
index d0c436967d5..0278029f617 100644
--- a/Core/CMakeLists.txt
+++ b/Core/CMakeLists.txt
@@ -163,7 +163,7 @@ target_include_directories(${library_name} PUBLIC ${include_dirs})
 target_include_directories(${library_name} SYSTEM PUBLIC ${EIGEN3_INCLUDE_DIR})
 target_include_directories(${library_name} PUBLIC ${Boost_INCLUDE_DIRS} ${FFTW3_INCLUDE_DIR}
     ${GSL_INCLUDE_DIR} ${tspectrum_INCLUDE_DIR} PRIVATE ${Faddeeva_INCLUDE_DIR})
-target_link_libraries(${library_name} ${Boost_LIBRARIES} ${FFTW3_LIBRARY} ${GSL_LIBRARIES}
+target_link_libraries(${library_name} ${Boost_LIBRARIES} ${FFTW3_LIBRARIES} ${GSL_LIBRARIES}
     ${Faddeeva_LIBRARY} ${tspectrum_LIBRARY})
 
 if(BORNAGAIN_MPI)
@@ -235,10 +235,13 @@ if(WIN32)
     install(FILES ${UTF_PATH}/${UTF_BASE_NAME}.dll
         DESTINATION ${destination_lib} COMPONENT Libraries)
 
-    install(FILES
-        ${FFTW3_LIBRARY_DLL}
-        ${TIFF_LIBRARY_DLL}
-        DESTINATION ${destination_lib} COMPONENT Libraries)
+    foreach(LIB IN LISTS ${FFTW3_LIBRARIES} ${TIFF_LIBRARIES})
+        string(REPLACE ".lib" ".dll" DLL "${LIB}")
+        if (NOT EXISTS ${DLL})
+            message(FATAL_ERROR "Dynamic load library ${DLL} (derived from ${LIB}) does not exist")
+        endif()
+        install(FILES ${DLL} DESTINATION ${destination_lib} COMPONENT Libraries)
+    endforeach()
 
 else()
     # Install thisbornagain.sh.
diff --git a/cmake/generic/modules/FindFFTW3.cmake b/cmake/generic/modules/FindFFTW3.cmake
index f3e59584c0b..667ef6e6efe 100644
--- a/cmake/generic/modules/FindFFTW3.cmake
+++ b/cmake/generic/modules/FindFFTW3.cmake
@@ -24,13 +24,6 @@ endif()
 find_library(FFTW3_LIBRARY NAMES ${FFTW3_NAMES} QUIET)
 set(CMAKE_FIND_LIBRARY_SUFFIXES ${ba_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES})
 
-if (WIN32)
-    string( REPLACE ".lib" ".dll" FFTW3_LIBRARY_DLL "${FFTW3_LIBRARY}" )
-    if (NOT EXISTS ${FFTW3_LIBRARY_DLL})
-        message(FATAL_ERROR "File ${FFTW3_LIBRARY_DLL} does not exist")
-    endif(NOT EXISTS ${FFTW3_LIBRARY_DLL})
-endif()
-
 # --- Processing variables -----
 
 include(FindPackageHandleStandardArgs)
diff --git a/cmake/generic/modules/FindTIFF.cmake b/cmake/generic/modules/FindTIFF.cmake
index ecd840a6339..fed5d769fe6 100644
--- a/cmake/generic/modules/FindTIFF.cmake
+++ b/cmake/generic/modules/FindTIFF.cmake
@@ -69,12 +69,7 @@ if(TIFF_FOUND)
             message(STATUS "Found TIFF C++ library ${cpp_tiff_library}")
             set(TIFF_LIBRARIES ${TIFF_LIBRARIES};${cpp_tiff_library})
         endif()
-    else()
-        string( REPLACE ".lib" ".dll" TIFF_LIBRARY_DLL "${TIFF_LIBRARY}" )
-        if (NOT EXISTS ${TIFF_LIBRARY_DLL})
-            message(FATAL_ERROR "File ${TIFF_LIBRARY_DLL} does not exist")
-        endif (NOT EXISTS ${TIFF_LIBRARY_DLL})
-    endif(NOT WIN32)
+    endif()
 endif()
 
 mark_as_advanced(TIFF_INCLUDE_DIR TIFF_LIBRARY TIFF_LIBRARY_DLL)
-- 
GitLab