diff --git a/.github/workflows/ba-windows.yml b/.github/workflows/ba-windows.yml index 87d18a94f6baa1fb7645e79f02ff43fc3707f6da..d6e35ddf5e6d03da45b1f718f6b926c2c0459904 100644 --- a/.github/workflows/ba-windows.yml +++ b/.github/workflows/ba-windows.yml @@ -167,7 +167,7 @@ jobs: run: | cd ${{github.workspace}}\build set PATH=${{github.workspace}}\nsis-3.04;%PATH% - cpack -c Release + cpack --debug -c Release - name: Upload CPack log uses: actions/upload-artifact@v2 diff --git a/Core/CMakeLists.txt b/Core/CMakeLists.txt index 9886baddede99412bacd74464aaeb8586d769979..17649fdcc09dcee0faa0b1f5a6b4d3257750018d 100644 --- a/Core/CMakeLists.txt +++ b/Core/CMakeLists.txt @@ -2,6 +2,8 @@ # CMakeLists.txt file for building libBornAgainCore library ############################################################################ +message(STATUS "Configuring BornAgain GUI") + set(library_name BornAgainCore) if(BORNAGAIN_TIDY) @@ -161,9 +163,9 @@ endif() 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} ${FFTW_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} ${FFTW_LIBRARY} ${GSL_LIBRARIES} +target_link_libraries(${library_name} ${Boost_LIBRARIES} ${FFTW3_LIBRARIES} ${GSL_LIBRARIES} ${Faddeeva_LIBRARY} ${tspectrum_LIBRARY}) if(BORNAGAIN_MPI) @@ -235,10 +237,16 @@ if(WIN32) install(FILES ${UTF_PATH}/${UTF_BASE_NAME}.dll DESTINATION ${destination_lib} COMPONENT Libraries) - install(FILES - ${FFTW_LIBRARY_DLL} - ${TIFF_LIBRARY_DLL} - DESTINATION ${destination_lib} COMPONENT Libraries) + set(DLL_MSG "") + 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) + string(APPEND DLL_MSG " ${DLL}") + endforeach() + message(STATUS "Other dlls: ${DLL_MSG}") else() # Install thisbornagain.sh. diff --git a/cmake/bornagain/modules/SearchInstalledSoftware.cmake b/cmake/bornagain/modules/SearchInstalledSoftware.cmake index 2681c7427818dfc4bf0c93a046342f6e4fab411b..ad084b7254300b2865ea6563525369f4b501415b 100644 --- a/cmake/bornagain/modules/SearchInstalledSoftware.cmake +++ b/cmake/bornagain/modules/SearchInstalledSoftware.cmake @@ -1,7 +1,7 @@ # Search for installed software required by BornAgain find_package(Threads REQUIRED) -find_package(FFTW REQUIRED) +find_package(FFTW3 REQUIRED) find_package(GSL REQUIRED) # --- Eigen3 is a git submodule; throw an error if submodule is not initialized --- @@ -44,7 +44,7 @@ endif() # --- Tiff --- if(BORNAGAIN_TIFF_SUPPORT) message(STATUS "Looking for libtiff (use -DBORNAGAIN_TIFF_SUPPORT=OFF to disable)") - find_package(TIFF 4.0.2 REQUIRED) + find_package(TIFF 4.0.2 REQUIRED COMPONENTS CXX) endif() # --- Python --- diff --git a/cmake/generic/modules/FindFFTW.cmake b/cmake/generic/modules/FindFFTW.cmake deleted file mode 100644 index c80164cb271d8f95a724b1d09396b6dc9773b2fc..0000000000000000000000000000000000000000 --- a/cmake/generic/modules/FindFFTW.cmake +++ /dev/null @@ -1,52 +0,0 @@ -# Find the FFTW includes and library. -# -# This module defines -# FFTW_INCLUDE_DIR, where to locate fftw3.h file -# FFTW_LIBRARIES, the libraries to link against to use fftw3 -# FFTW_LIBRARY, where to find the libfftw3 library. - -# --- Looking for headers ----- - -find_path(FFTW_INCLUDE_DIR fftw3.h) -if(NOT FFTW_INCLUDE_DIR) - message(ERROR " Missed dependency. Can't find FFTW headers, please make sure that you've installed FFTW development version.") -endif() - -# --- Looking for library ----- - -set(FFTW_NAMES ${FFTW_NAMES} fftw3 fftw3-3 libfftw3-3) -set( ba_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) - -if (NOT APPLE AND NOT WIN32) - set(CMAKE_FIND_LIBRARY_SUFFIXES .so) # require shared version of library -endif() - -find_library(FFTW_LIBRARY NAMES ${FFTW_NAMES} QUIET) -set(CMAKE_FIND_LIBRARY_SUFFIXES ${ba_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) - -if (WIN32) - string( REPLACE ".lib" ".dll" FFTW_LIBRARY_DLL "${FFTW_LIBRARY}" ) - if (NOT EXISTS ${FFTW_LIBRARY_DLL}) - message(FATAL_ERROR "File ${FFTW_LIBRARY_DLL} does not exist") - endif(NOT EXISTS ${FFTW_LIBRARY_DLL}) -endif() - -# --- Processing variables ----- - -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(FFTW REQUIRED_VARS FFTW_LIBRARY FFTW_INCLUDE_DIR) - -if(FFTW_FOUND) - set( FFTW_LIBRARIES ${FFTW_LIBRARY} ) -endif() - -if(FFTW_FOUND) - message(STATUS "Found FFTW: includes at ${FFTW_INCLUDE_DIR}, libraries at ${FFTW_LIBRARIES}") -else() - message(STATUS "Cant'f find fftw3 library: ${FFTW_INCLUDE_DIR}, ${FFTW_LIBRARIES}.") - if (NOT WIN32 AND NOT APPLE) - message(STATUS "Please note, that shared version of FFTW library is required (use enable-shared during configuration phase).") - endif() -endif() - -mark_as_advanced(FFTW_INCLUDE_DIR FFTW_LIBRARY FFTW_LIBRARY_DLL) diff --git a/cmake/generic/modules/FindFFTW3.cmake b/cmake/generic/modules/FindFFTW3.cmake new file mode 100644 index 0000000000000000000000000000000000000000..667ef6e6efee544bfd14a9019b7cef2baeec9562 --- /dev/null +++ b/cmake/generic/modules/FindFFTW3.cmake @@ -0,0 +1,45 @@ +# Find the FFTW includes and library. +# +# This module defines +# FFTW3_INCLUDE_DIR, where to locate fftw3.h file +# FFTW3_LIBRARIES, the libraries to link against to use fftw3 +# FFTW3_LIBRARY, where to find the libfftw3 library. + +# --- Looking for headers ----- + +find_path(FFTW3_INCLUDE_DIR fftw3.h) +if(NOT FFTW3_INCLUDE_DIR) + message(ERROR " Missed dependency. Can't find FFTW headers, please make sure that you've installed FFTW development version.") +endif() + +# --- Looking for library ----- + +set(FFTW3_NAMES ${FFTW3_NAMES} fftw3 fftw3-3 libfftw3-3) +set(ba_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES}) + +if (NOT APPLE AND NOT WIN32) + set(CMAKE_FIND_LIBRARY_SUFFIXES .so) # require shared version of library +endif() + +find_library(FFTW3_LIBRARY NAMES ${FFTW3_NAMES} QUIET) +set(CMAKE_FIND_LIBRARY_SUFFIXES ${ba_ORIG_CMAKE_FIND_LIBRARY_SUFFIXES}) + +# --- Processing variables ----- + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(FFTW3 REQUIRED_VARS FFTW3_LIBRARY FFTW3_INCLUDE_DIR) + +if(FFTW3_FOUND) + set(FFTW3_LIBRARIES ${FFTW3_LIBRARY} ) +endif() + +if(FFTW3_FOUND) + message(STATUS "Found FFTW3: includes at ${FFTW3_INCLUDE_DIR}, libraries at ${FFTW3_LIBRARIES}") +else() + message(STATUS "Cant'f find fftw3 library: ${FFTW3_INCLUDE_DIR}, ${FFTW3_LIBRARIES}.") + if (NOT WIN32 AND NOT APPLE) + message(STATUS "Please note, that shared version of FFTW3 library is required (use enable-shared during configuration phase).") + endif() +endif() + +mark_as_advanced(FFTW3_INCLUDE_DIR FFTW3_LIBRARY FFTW3_LIBRARY_DLL) diff --git a/cmake/generic/modules/FindGSL.cmake b/cmake/generic/modules/FindGSL.cmake deleted file mode 100644 index 1528e3b83263876374d87049d073308a17bec4de..0000000000000000000000000000000000000000 --- a/cmake/generic/modules/FindGSL.cmake +++ /dev/null @@ -1,239 +0,0 @@ -#.rst: -# FindGSL -# -------- -# -# Find the native GSL includes and libraries. -# -# The GNU Scientific Library (GSL) is a numerical library for C and C++ -# programmers. It is free software under the GNU General Public -# License. -# -# Imported Targets -# ^^^^^^^^^^^^^^^^ -# -# If GSL is found, this module defines the following :prop_tgt:`IMPORTED` -# targets:: -# -# GSL::gsl - The main GSL library. -# GSL::gslcblas - The CBLAS support library used by GSL. -# -# Result Variables -# ^^^^^^^^^^^^^^^^ -# -# This module will set the following variables in your project:: -# -# GSL_FOUND - True if GSL found on the local system -# GSL_INCLUDE_DIRS - Location of GSL header files. -# GSL_LIBRARIES - The GSL libraries. -# GSL_VERSION - The version of the discovered GSL install. -# -# Hints -# ^^^^^ -# -# Set ``GSL_ROOT_DIR`` to a directory that contains a GSL installation. -# -# This script expects to find libraries at ``$GSL_ROOT_DIR/lib`` and the GSL -# headers at ``$GSL_ROOT_DIR/include/gsl``. The library directory may -# optionally provide Release and Debug folders. For Unix-like systems, this -# script will use ``$GSL_ROOT_DIR/bin/gsl-config`` (if found) to aid in the -# discovery GSL. -# -# Cache Variables -# ^^^^^^^^^^^^^^^ -# -# This module may set the following variables depending on platform and type -# of GSL installation discovered. These variables may optionally be set to -# help this module find the correct files:: -# -# GSL_CLBAS_LIBRARY - Location of the GSL CBLAS library. -# GSL_CBLAS_LIBRARY_DEBUG - Location of the debug GSL CBLAS library (if any). -# GSL_CONFIG_EXECUTABLE - Location of the ``gsl-config`` script (if any). -# GSL_LIBRARY - Location of the GSL library. -# GSL_LIBRARY_DEBUG - Location of the debug GSL library (if any). -# - -#============================================================================= -# Copyright 2014 Kelly Thompson <kgt@lanl.gov> -# -# Distributed under the OSI-approved BSD License (the "License"); -# see accompanying file Copyright.txt for details. -# -# This software is distributed WITHOUT ANY WARRANTY; without even the -# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the License for more information. -#============================================================================= -# (To distribute this file outside of CMake, substitute the full -# License text for the above reference.) - -# Include these modules to handle the QUIETLY and REQUIRED arguments. -#include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) # original -include(FindPackageHandleStandardArgs) # patched JWu 4/16 - -#============================================================================= -# If the user has provided ``GSL_ROOT_DIR``, use it! Choose items found -# at this location over system locations. -if( EXISTS "$ENV{GSL_ROOT_DIR}" ) - file( TO_CMAKE_PATH "$ENV{GSL_ROOT_DIR}" GSL_ROOT_DIR ) - set( GSL_ROOT_DIR "${GSL_ROOT_DIR}" CACHE PATH "Prefix for GSL installation." ) -endif() -if( NOT EXISTS "${GSL_ROOT_DIR}" ) - set( GSL_USE_PKGCONFIG ON ) -endif() - -#============================================================================= -# As a first try, use the PkgConfig module. This will work on many -# *NIX systems. See :module:`findpkgconfig` -# This will return ``GSL_INCLUDEDIR`` and ``GSL_LIBDIR`` used below. -if( GSL_USE_PKGCONFIG ) - find_package(PkgConfig) - pkg_check_modules( GSL QUIET gsl ) - - if( EXISTS "${GSL_INCLUDEDIR}" ) - get_filename_component( GSL_ROOT_DIR "${GSL_INCLUDEDIR}" DIRECTORY CACHE) - endif() -endif() - -#============================================================================= -# Set GSL_INCLUDE_DIRS and GSL_LIBRARIES. If we skipped the PkgConfig step, try -# to find the libraries at $GSL_ROOT_DIR (if provided) or in standard system -# locations. These find_library and find_path calls will prefer custom -# locations over standard locations (HINTS). If the requested file is not found -# at the HINTS location, standard system locations will be still be searched -# (/usr/lib64 (Redhat), lib/i386-linux-gnu (Debian)). - -find_path( GSL_INCLUDE_DIR - NAMES gsl/gsl_sf.h - HINTS ${GSL_ROOT_DIR}/include ${GSL_INCLUDEDIR} -) -find_library( GSL_LIBRARY - NAMES gsl - HINTS ${GSL_ROOT_DIR}/lib ${GSL_LIBDIR} - PATH_SUFFIXES Release Debug -) -find_library( GSL_CBLAS_LIBRARY - NAMES gslcblas cblas - HINTS ${GSL_ROOT_DIR}/lib ${GSL_LIBDIR} - PATH_SUFFIXES Release Debug -) -# Do we also have debug versions? -find_library( GSL_LIBRARY_DEBUG - NAMES gsl - HINTS ${GSL_ROOT_DIR}/lib ${GSL_LIBDIR} - PATH_SUFFIXES Debug -) -find_library( GSL_CBLAS_LIBRARY_DEBUG - NAMES gslcblas cblas - HINTS ${GSL_ROOT_DIR}/lib ${GSL_LIBDIR} - PATH_SUFFIXES Debug -) -set( GSL_INCLUDE_DIRS ${GSL_INCLUDE_DIR} ) -set( GSL_LIBRARIES ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY} ) - -# If we didn't use PkgConfig, try to find the version via gsl-config or by -# reading gsl_version.h. -if( NOT GSL_VERSION ) - # 1. If gsl-config exists, query for the version. - find_program( GSL_CONFIG_EXECUTABLE - NAMES gsl-config - HINTS "${GSL_ROOT_DIR}/bin" - ) - if( EXISTS "${GSL_CONFIG_EXECUTABLE}" ) - execute_process( - COMMAND "${GSL_CONFIG_EXECUTABLE}" --version - OUTPUT_VARIABLE GSL_VERSION - OUTPUT_STRIP_TRAILING_WHITESPACE ) - endif() - - # 2. If gsl-config is not available, try looking in gsl/gsl_version.h - if( NOT GSL_VERSION AND EXISTS "${GSL_INCLUDE_DIRS}/gsl/gsl_version.h" ) - file( STRINGS "${GSL_INCLUDE_DIRS}/gsl/gsl_version.h" gsl_version_h_contents REGEX "define GSL_VERSION" ) - string( REGEX REPLACE ".*([0-9].[0-9][0-9]).*" "\\1" GSL_VERSION ${gsl_version_h_contents} ) - endif() - - # might also try scraping the directory name for a regex match "gsl-X.X" -endif() - -#============================================================================= -# handle the QUIETLY and REQUIRED arguments and set GSL_FOUND to TRUE if all -# listed variables are TRUE -find_package_handle_standard_args( GSL - FOUND_VAR - GSL_FOUND - REQUIRED_VARS - GSL_INCLUDE_DIR - GSL_LIBRARY - GSL_CBLAS_LIBRARY - VERSION_VAR - GSL_VERSION - ) - -mark_as_advanced( GSL_ROOT_DIR GSL_VERSION GSL_LIBRARY GSL_INCLUDE_DIR - GSL_CBLAS_LIBRARY GSL_LIBRARY_DEBUG GSL_CBLAS_LIBRARY_DEBUG - GSL_USE_PKGCONFIG GSL_CONFIG ) - -#============================================================================= -# Register imported libraries: -# 1. If we can find a Windows .dll file (or if we can find both Debug and -# Release libraries), we will set appropriate target properties for these. -# 2. However, for most systems, we will only register the import location and -# include directory. - -# Look for dlls, or Release and Debug libraries. -if(WIN32) - string( REPLACE ".lib" ".dll" GSL_LIBRARY_DLL "${GSL_LIBRARY}" ) - string( REPLACE ".lib" ".dll" GSL_CBLAS_LIBRARY_DLL "${GSL_CBLAS_LIBRARY}" ) - string( REPLACE ".lib" ".dll" GSL_LIBRARY_DEBUG_DLL "${GSL_LIBRARY_DEBUG}" ) - string( REPLACE ".lib" ".dll" GSL_CBLAS_LIBRARY_DEBUG_DLL "${GSL_CBLAS_LIBRARY_DEBUG}" ) -endif() - -if( GSL_FOUND AND NOT TARGET GSL::gsl ) - if( EXISTS "${GSL_LIBRARY_DLL}" AND EXISTS "${GSL_CBLAS_LIBRARY_DLL}") - - # Windows systems with dll libraries. - add_library( GSL::gsl SHARED IMPORTED ) - add_library( GSL::gslcblas SHARED IMPORTED ) - - # Windows with dlls, but only Release libraries. - set_target_properties( GSL::gslcblas PROPERTIES - IMPORTED_LOCATION_RELEASE "${GSL_CBLAS_LIBRARY_DLL}" - IMPORTED_IMPLIB "${GSL_CBLAS_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${GSL_INCLUDE_DIRS}" - IMPORTED_CONFIGURATIONS Release - IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) - set_target_properties( GSL::gsl PROPERTIES - IMPORTED_LOCATION_RELEASE "${GSL_LIBRARY_DLL}" - IMPORTED_IMPLIB "${GSL_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${GSL_INCLUDE_DIRS}" - IMPORTED_CONFIGURATIONS Release - IMPORTED_LINK_INTERFACE_LANGUAGES "C" - INTERFACE_LINK_LIBRARIES GSL::gslcblas ) - - # If we have both Debug and Release libraries - if( EXISTS "${GSL_LIBRARY_DEBUG_DLL}" AND EXISTS "${GSL_CBLAS_LIBRARY_DEBUG_DLL}") - set_property( TARGET GSL::gslcblas APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) - set_target_properties( GSL::gslcblas PROPERTIES - IMPORTED_LOCATION_DEBUG "${GSL_CBLAS_LIBRARY_DEBUG_DLL}" - IMPORTED_IMPLIB_DEBUG "${GSL_CBLAS_LIBRARY_DEBUG}" ) - set_property( TARGET GSL::gsl APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) - set_target_properties( GSL::gsl PROPERTIES - IMPORTED_LOCATION_DEBUG "${GSL_LIBRARY_DEBUG_DLL}" - IMPORTED_IMPLIB_DEBUG "${GSL_LIBRARY_DEBUG}" ) - endif() - - else() - - # For all other environments (ones without dll libraries), create - # the imported library targets. - add_library( GSL::gsl UNKNOWN IMPORTED ) - add_library( GSL::gslcblas UNKNOWN IMPORTED ) - set_target_properties( GSL::gslcblas PROPERTIES - IMPORTED_LOCATION "${GSL_CBLAS_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${GSL_INCLUDE_DIRS}" - IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) - set_target_properties( GSL::gsl PROPERTIES - IMPORTED_LOCATION "${GSL_LIBRARY}" - INTERFACE_INCLUDE_DIRECTORIES "${GSL_INCLUDE_DIRS}" - IMPORTED_LINK_INTERFACE_LANGUAGES "C" - INTERFACE_LINK_LIBRARIES GSL::gslcblas ) - endif() -endif() diff --git a/cmake/generic/modules/FindTIFF.cmake b/cmake/generic/modules/FindTIFF.cmake index ecd840a63391e4bacada4f236ede5ce98eb5e62c..6459342279756eea71c65a2fd2edfd4d8dbec5c5 100644 --- a/cmake/generic/modules/FindTIFF.cmake +++ b/cmake/generic/modules/FindTIFF.cmake @@ -1,36 +1,88 @@ -#.rst: -# FindTIFF -# -------- -# -# Find TIFF and TIFF/C++libraries -# -# This module defines -# -# :: -# -# TIFF_INCLUDE_DIR, where to find tiff.h, etc. -# TIFF_LIBRARIES, libraries to link against to use TIFF. -# TIFF_FOUND, If false, do not try to use TIFF. -# -# also defined, but not for general use are -# -# :: -# -# TIFF_LIBRARY, where to find the TIFF library. - -# This is a heavily patched version of the CMake module FindTIFF.cmake -# Copyright 2002-2009 Kitware, Inc. -# Copyright 2013- BornAgain team -# Distributed under the OSI-approved BSD License - -if(WIN32) - find_path(TIFF_INCLUDE_DIR tiff.h PATHS ${CMAKE_INCLUDE_PATH}/libtiff NO_SYSTEM_ENVIRONMENT_PATH) -else() - find_path(TIFF_INCLUDE_DIR tiff.h) -endif() +# This FindTIFF.cmake has been contributed by us to upstream CMake. +# It is expected to be released with CMake 3.19. +# See https://gitlab.kitware.com/cmake/cmake/-/merge_requests/4934. + +# Therefore we shall delete this file from BornAgain in a couple of years +# when our minimum required CMake version has been incremented to 3.19. +# - JWu, jun2020. + +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +#[=======================================================================[.rst: +FindTIFF +-------- + +Find the TIFF library (``libtiff``, https://libtiff.gitlab.io/libtiff/). + +Optional COMPONENTS +^^^^^^^^^^^^^^^^^^^ + +This module supports the optional component `CXX`, for use with the COMPONENTS +argument of the :command:`find_package` command. This component has an associated +imported target, as described below. + +Imported targets +^^^^^^^^^^^^^^^^ + +This module defines the following :prop_tgt:`IMPORTED` targets: + +``TIFF::TIFF`` + The TIFF library, if found. + +``TIFF::CXX`` + The C++ wrapper libtiffxx, if requested by the `COMPONENTS CXX` option, + if the compiler is not MSVC (which includes the C++ wrapper in libtiff), + and if found. + +Result variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project: + +``TIFF_FOUND`` + true if the TIFF headers and libraries were found +``TIFF_INCLUDE_DIR`` + the directory containing the TIFF headers +``TIFF_INCLUDE_DIRS`` + the directory containing the TIFF headers +``TIFF_LIBRARIES`` + TIFF libraries to be linked + +Cache variables +^^^^^^^^^^^^^^^ -set(TIFF_NAMES ${TIFF_NAMES} libtiff tiff libtiff3 tiff3) -find_library(TIFF_LIBRARY NAMES ${TIFF_NAMES}) +The following cache variables may also be set: + +``TIFF_INCLUDE_DIR`` + the directory containing the TIFF headers +``TIFF_LIBRARY_RELEASE`` + the path to the TIFF library for release configurations +``TIFF_LIBRARY_DEBUG`` + the path to the TIFF library for debug configurations +``TIFFXX_LIBRARY_RELEASE`` + the path to the TIFFXX library for release configurations +``TIFFXX_LIBRARY_DEBUG`` + the path to the TIFFXX library for debug configurations +#]=======================================================================] + +cmake_policy(PUSH) +cmake_policy(SET CMP0057 NEW) + +find_path(TIFF_INCLUDE_DIR tiff.h) + +set(TIFF_NAMES ${TIFF_NAMES} tiff libtiff tiff3 libtiff3) +foreach(name ${TIFF_NAMES}) + list(APPEND TIFF_NAMES_DEBUG "${name}d") +endforeach() + +if(NOT TIFF_LIBRARY) + find_library(TIFF_LIBRARY_RELEASE NAMES ${TIFF_NAMES}) + find_library(TIFF_LIBRARY_DEBUG NAMES ${TIFF_NAMES_DEBUG}) + include(SelectLibraryConfigurations) # patched because we are outside CMake + select_library_configurations(TIFF) + mark_as_advanced(TIFF_LIBRARY_RELEASE TIFF_LIBRARY_DEBUG) +endif() if(TIFF_INCLUDE_DIR AND EXISTS "${TIFF_INCLUDE_DIR}/tiffvers.h") file(STRINGS "${TIFF_INCLUDE_DIR}/tiffvers.h" tiff_version_str @@ -41,40 +93,109 @@ if(TIFF_INCLUDE_DIR AND EXISTS "${TIFF_INCLUDE_DIR}/tiffvers.h") unset(tiff_version_str) endif() -# handle the QUIETLY and REQUIRED arguments and set TIFF_FOUND to TRUE if -# all listed variables are TRUE -include(FindPackageHandleStandardArgs) +foreach(_comp IN LISTS TIFF_FIND_COMPONENTS) + if(_comp STREQUAL "CXX") + if(MSVC) + # C++ bindings are built into the main tiff library. + set(TIFF_CXX_FOUND 1) + else() + foreach(name ${TIFF_NAMES}) + list(APPEND TIFFXX_NAMES "${name}xx") + list(APPEND TIFFXX_NAMES_DEBUG "${name}xxd") + endforeach() + find_library(TIFFXX_LIBRARY_RELEASE NAMES ${TIFFXX_NAMES}) + find_library(TIFFXX_LIBRARY_DEBUG NAMES ${TIFFXX_NAMES_DEBUG}) + include(SelectLibraryConfigurations) # patched because we are outside CMake + select_library_configurations(TIFFXX) + mark_as_advanced(TIFFXX_LIBRARY_RELEASE TIFFXX_LIBRARY_DEBUG) + unset(TIFFXX_NAMES) + unset(TIFFXX_NAMES_DEBUG) + if(TIFFXX_LIBRARY) + set(TIFF_CXX_FOUND 1) + endif() + endif() + endif() +endforeach() +unset(_comp) + +unset(TIFF_NAMES) +unset(TIFF_NAMES_DEBUG) + +include(FindPackageHandleStandardArgs) # patched because we are outside CMake FIND_PACKAGE_HANDLE_STANDARD_ARGS(TIFF + HANDLE_COMPONENTS REQUIRED_VARS TIFF_LIBRARY TIFF_INCLUDE_DIR VERSION_VAR TIFF_VERSION_STRING) if(TIFF_FOUND) - set( TIFF_LIBRARIES ${TIFF_LIBRARY} ) -endif() + set(TIFF_LIBRARIES ${TIFF_LIBRARY}) + if("CXX" IN_LIST TIFF_FIND_COMPONENTS AND NOT MSVC) + list(APPEND TIFF_LIBRARIES ${TIFFXX_LIBRARY}) + endif() -if(TIFF_FOUND) - message(STATUS "Found TIFF version ${TIFF_VERSION_STRING}, includes at ${TIFF_INCLUDE_DIR}, libraries at ${TIFF_LIBRARIES}") - - if(NOT WIN32) - # looking for C++ version of library libtiffxx.so - list(LENGTH TIFF_LIBRARIES len) - if(len EQUAL 1) - get_filename_component(tiff_library_name ${TIFF_LIBRARIES} NAME_WE ) - get_filename_component(tiff_path ${TIFF_LIBRARIES} DIRECTORY ) - get_filename_component(tiff_ext ${TIFF_LIBRARIES} EXT ) - set(cpp_tiff_library "${tiff_path}/${tiff_library_name}xx${tiff_ext}") - if(NOT EXISTS ${cpp_tiff_library}) - message(FATAL_ERROR "Could NOT find TIFF/C++ library ${cpp_tiff_library}.") - endif() - message(STATUS "Found TIFF C++ library ${cpp_tiff_library}") - set(TIFF_LIBRARIES ${TIFF_LIBRARIES};${cpp_tiff_library}) - endif() + set(TIFF_INCLUDE_DIRS "${TIFF_INCLUDE_DIR}") + + if(NOT TARGET TIFF::TIFF) + add_library(TIFF::TIFF UNKNOWN IMPORTED) + if(TIFF_INCLUDE_DIRS) + set_target_properties(TIFF::TIFF PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${TIFF_INCLUDE_DIRS}") + endif() + if(EXISTS "${TIFF_LIBRARY}") + set_target_properties(TIFF::TIFF PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "C" + IMPORTED_LOCATION "${TIFF_LIBRARY}") + endif() + if(EXISTS "${TIFF_LIBRARY_RELEASE}") + set_property(TARGET TIFF::TIFF APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties(TIFF::TIFF PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "C" + IMPORTED_LOCATION_RELEASE "${TIFF_LIBRARY_RELEASE}") + endif() + if(EXISTS "${TIFF_LIBRARY_DEBUG}") + set_property(TARGET TIFF::TIFF APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_target_properties(TIFF::TIFF PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "C" + IMPORTED_LOCATION_DEBUG "${TIFF_LIBRARY_DEBUG}") + endif() + endif() + + if(NOT TARGET TIFF::CXX) + if(MSVC) + add_library(TIFF::CXX INTERFACE IMPORTED) + set_property(TARGET TIFF::CXX PROPERTY INTERFACE_LINK_LIBRARIES TIFF::TIFF) 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) + add_library(TIFF::CXX UNKNOWN IMPORTED) + set_property(TARGET TIFF::CXX PROPERTY INTERFACE_LINK_LIBRARIES TIFF::TIFF) + if(TIFF_INCLUDE_DIRS) + set_target_properties(TIFF::CXX PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${TIFF_INCLUDE_DIRS}") + endif() + if(EXISTS "${TIFFXX_LIBRARY}") + set_target_properties(TIFF::CXX PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES "CXX" + IMPORTED_LOCATION "${TIFFXX_LIBRARY}") + endif() + if(EXISTS "${TIFFXX_LIBRARY_RELEASE}") + set_property(TARGET TIFF::CXX APPEND PROPERTY + IMPORTED_CONFIGURATIONS RELEASE) + set_target_properties(TIFF::CXX PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_RELEASE "CXX" + IMPORTED_LOCATION_RELEASE "${TIFFXX_LIBRARY_RELEASE}") + endif() + if(EXISTS "${TIFFXX_LIBRARY_DEBUG}") + set_property(TARGET TIFF::CXX APPEND PROPERTY + IMPORTED_CONFIGURATIONS DEBUG) + set_target_properties(TIFF::CXX PROPERTIES + IMPORTED_LINK_INTERFACE_LANGUAGES_DEBUG "CXX" + IMPORTED_LOCATION_DEBUG "${TIFFXX_LIBRARY_DEBUG}") + endif() + endif() + endif() + endif() -mark_as_advanced(TIFF_INCLUDE_DIR TIFF_LIBRARY TIFF_LIBRARY_DLL) +mark_as_advanced(TIFF_INCLUDE_DIR) +cmake_policy(POP)