Warning, /graphics/krita/cmake/modules/FindGSL.cmake is written in an unsupported language. File is not indexed.
0001 # SPDX-FileCopyrightText: 2000-2023 Kitware, Inc. and Contributors 0002 # SPDX-FileCopyrightText: 2023 L. E. Segovia <amy@amyspark.me> 0003 # SPDX-License-Ref: BSD-3-Clause 0004 0005 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying 0006 # file Copyright.txt or https://cmake.org/licensing for details. 0007 0008 #[=======================================================================[.rst: 0009 FindGSL 0010 -------- 0011 0012 .. versionadded:: 3.2 0013 0014 Find the native GNU Scientific Library (GSL) includes and libraries. 0015 0016 The GNU Scientific Library (GSL) is a numerical library for C and C++ 0017 programmers. It is free software under the GNU General Public 0018 License. 0019 0020 Imported Targets 0021 ^^^^^^^^^^^^^^^^ 0022 0023 If GSL is found, this module defines the following :prop_tgt:`IMPORTED` 0024 targets:: 0025 0026 GSL::gsl - The main GSL library. 0027 GSL::gslcblas - The CBLAS support library used by GSL. 0028 0029 Result Variables 0030 ^^^^^^^^^^^^^^^^ 0031 0032 This module will set the following variables in your project:: 0033 0034 GSL_FOUND - True if GSL found on the local system 0035 GSL_INCLUDE_DIRS - Location of GSL header files. 0036 GSL_LIBRARIES - The GSL libraries. 0037 GSL_VERSION - The version of the discovered GSL install. 0038 0039 Hints 0040 ^^^^^ 0041 0042 Set ``GSL_ROOT_DIR`` to a directory that contains a GSL installation. 0043 0044 This script expects to find libraries at ``$GSL_ROOT_DIR/lib`` and the GSL 0045 headers at ``$GSL_ROOT_DIR/include/gsl``. The library directory may 0046 optionally provide Release and Debug folders. If available, the libraries 0047 named ``gsld``, ``gslblasd`` or ``cblasd`` are recognized as debug libraries. 0048 For Unix-like systems, this script will use ``$GSL_ROOT_DIR/bin/gsl-config`` 0049 (if found) to aid in the discovery of GSL. 0050 0051 Cache Variables 0052 ^^^^^^^^^^^^^^^ 0053 0054 This module may set the following variables depending on platform and type 0055 of GSL installation discovered. These variables may optionally be set to 0056 help this module find the correct files:: 0057 0058 GSL_CBLAS_LIBRARY - Location of the GSL CBLAS library. 0059 GSL_CBLAS_LIBRARY_DEBUG - Location of the debug GSL CBLAS library (if any). 0060 GSL_CONFIG_EXECUTABLE - Location of the ``gsl-config`` script (if any). 0061 GSL_LIBRARY - Location of the GSL library. 0062 GSL_LIBRARY_DEBUG - Location of the debug GSL library (if any). 0063 0064 #]=======================================================================] 0065 0066 include(FindPackageHandleStandardArgs) 0067 0068 #============================================================================= 0069 # If the user has provided ``GSL_ROOT_DIR``, use it! Choose items found 0070 # at this location over system locations. 0071 if( EXISTS "$ENV{GSL_ROOT_DIR}" ) 0072 file( TO_CMAKE_PATH "$ENV{GSL_ROOT_DIR}" GSL_ROOT_DIR ) 0073 set( GSL_ROOT_DIR "${GSL_ROOT_DIR}" CACHE PATH "Prefix for GSL installation." ) 0074 endif() 0075 if( NOT EXISTS "${GSL_ROOT_DIR}" ) 0076 set( GSL_USE_PKGCONFIG ON ) 0077 endif() 0078 0079 #============================================================================= 0080 # As a first try, use the PkgConfig module. This will work on many 0081 # *NIX systems. See :module:`findpkgconfig` 0082 # This will return ``GSL_INCLUDEDIR`` and ``GSL_LIBDIR`` used below. 0083 if( GSL_USE_PKGCONFIG ) 0084 find_package(PkgConfig QUIET) 0085 pkg_check_modules( GSL QUIET gsl ) 0086 0087 if( EXISTS "${GSL_INCLUDEDIR}" ) 0088 get_filename_component( GSL_ROOT_DIR "${GSL_INCLUDEDIR}" DIRECTORY CACHE) 0089 endif() 0090 endif() 0091 0092 #============================================================================= 0093 # Set GSL_INCLUDE_DIRS and GSL_LIBRARIES. If we skipped the PkgConfig step, try 0094 # to find the libraries at $GSL_ROOT_DIR (if provided) or in standard system 0095 # locations. These find_library and find_path calls will prefer custom 0096 # locations over standard locations (HINTS). If the requested file is not found 0097 # at the HINTS location, standard system locations will be still be searched 0098 # (/usr/lib64 (Redhat), lib/i386-linux-gnu (Debian)). 0099 0100 find_path( GSL_INCLUDE_DIR 0101 NAMES gsl/gsl_sf.h 0102 HINTS ${GSL_ROOT_DIR}/include ${GSL_INCLUDEDIR} 0103 ) 0104 find_library( GSL_LIBRARY 0105 NAMES gsl 0106 HINTS ${GSL_ROOT_DIR}/lib ${GSL_LIBDIR} 0107 PATH_SUFFIXES Release Debug 0108 ) 0109 find_library( GSL_CBLAS_LIBRARY 0110 NAMES gslcblas cblas 0111 HINTS ${GSL_ROOT_DIR}/lib ${GSL_LIBDIR} 0112 PATH_SUFFIXES Release Debug 0113 ) 0114 # Do we also have debug versions? 0115 find_library( GSL_LIBRARY_DEBUG 0116 NAMES gsld gsl 0117 HINTS ${GSL_ROOT_DIR}/lib ${GSL_LIBDIR} 0118 PATH_SUFFIXES Debug 0119 ) 0120 find_library( GSL_CBLAS_LIBRARY_DEBUG 0121 NAMES gslcblasd cblasd gslcblas cblas 0122 HINTS ${GSL_ROOT_DIR}/lib ${GSL_LIBDIR} 0123 PATH_SUFFIXES Debug 0124 ) 0125 set( GSL_INCLUDE_DIRS ${GSL_INCLUDE_DIR} ) 0126 set( GSL_LIBRARIES ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY} ) 0127 0128 # If we didn't use PkgConfig, try to find the version via gsl-config or by 0129 # reading gsl_version.h. 0130 if( NOT GSL_VERSION ) 0131 # 1. If gsl-config exists, query for the version. 0132 find_program( GSL_CONFIG_EXECUTABLE 0133 NAMES gsl-config 0134 HINTS "${GSL_ROOT_DIR}/bin" 0135 ) 0136 if( EXISTS "${GSL_CONFIG_EXECUTABLE}" ) 0137 execute_process( 0138 COMMAND "${GSL_CONFIG_EXECUTABLE}" --version 0139 OUTPUT_VARIABLE GSL_VERSION 0140 OUTPUT_STRIP_TRAILING_WHITESPACE ) 0141 endif() 0142 0143 # 2. If gsl-config is not available, try looking in gsl/gsl_version.h 0144 if( NOT GSL_VERSION AND EXISTS "${GSL_INCLUDE_DIRS}/gsl/gsl_version.h" ) 0145 file( STRINGS "${GSL_INCLUDE_DIRS}/gsl/gsl_version.h" gsl_version_h_contents REGEX "define GSL_VERSION" ) 0146 string( REGEX REPLACE ".*define[ ]+GSL_VERSION[ ]+\"([^\"]*)\".*" "\\1" GSL_VERSION ${gsl_version_h_contents} ) 0147 endif() 0148 0149 # might also try scraping the directory name for a regex match "gsl-X.X" 0150 endif() 0151 0152 #============================================================================= 0153 # handle the QUIETLY and REQUIRED arguments and set GSL_FOUND to TRUE if all 0154 # listed variables are TRUE 0155 find_package_handle_standard_args( GSL 0156 FOUND_VAR 0157 GSL_FOUND 0158 REQUIRED_VARS 0159 GSL_INCLUDE_DIR 0160 GSL_LIBRARY 0161 GSL_CBLAS_LIBRARY 0162 VERSION_VAR 0163 GSL_VERSION 0164 ) 0165 0166 mark_as_advanced( GSL_ROOT_DIR GSL_VERSION GSL_LIBRARY GSL_INCLUDE_DIR 0167 GSL_CBLAS_LIBRARY GSL_LIBRARY_DEBUG GSL_CBLAS_LIBRARY_DEBUG 0168 GSL_USE_PKGCONFIG GSL_CONFIG ) 0169 0170 #============================================================================= 0171 # Register imported libraries: 0172 # 1. If we can find a Windows .dll file (or if we can find both Debug and 0173 # Release libraries), we will set appropriate target properties for these. 0174 # 2. However, for most systems, we will only register the import location and 0175 # include directory. 0176 0177 # Look for dlls, or Release and Debug libraries. 0178 # XXX: CMake's logic here is wrong, it assumes Windows == MSVC *and* 0179 # that the library will always be built dynamically 0180 # if(WIN32) 0181 # string( REPLACE ".lib" ".dll" GSL_LIBRARY_DLL "${GSL_LIBRARY}" ) 0182 # string( REPLACE ".lib" ".dll" GSL_CBLAS_LIBRARY_DLL "${GSL_CBLAS_LIBRARY}" ) 0183 # string( REPLACE ".lib" ".dll" GSL_LIBRARY_DEBUG_DLL "${GSL_LIBRARY_DEBUG}" ) 0184 # string( REPLACE ".lib" ".dll" GSL_CBLAS_LIBRARY_DEBUG_DLL "${GSL_CBLAS_LIBRARY_DEBUG}" ) 0185 # endif() 0186 if(WIN32) 0187 if (MSVC) 0188 string( REGEX REPLACE ".lib$" ".dll" GSL_LIBRARY_DLL "${GSL_LIBRARY}" ) 0189 string( REGEX REPLACE ".lib$" ".dll" GSL_CBLAS_LIBRARY_DLL "${GSL_CBLAS_LIBRARY}" ) 0190 string( REGEX REPLACE ".lib$" ".dll" GSL_LIBRARY_DEBUG_DLL "${GSL_LIBRARY_DEBUG}" ) 0191 string( REGEX REPLACE ".lib$" ".dll" GSL_CBLAS_LIBRARY_DEBUG_DLL "${GSL_CBLAS_LIBRARY_DEBUG}" ) 0192 elseif ("${GSL_LIBRARY}" MATCHES "\.dll\.a$") 0193 string( REGEX REPLACE ".a$" "" GSL_LIBRARY_DLL "${GSL_LIBRARY}" ) 0194 string( REGEX REPLACE ".a$" "" GSL_CBLAS_LIBRARY_DLL "${GSL_CBLAS_LIBRARY}" ) 0195 string( REGEX REPLACE ".a$" "" GSL_LIBRARY_DEBUG_DLL "${GSL_LIBRARY_DEBUG}" ) 0196 string( REGEX REPLACE ".a$" "" GSL_CBLAS_LIBRARY_DEBUG_DLL "${GSL_CBLAS_LIBRARY_DEBUG}" ) 0197 else() 0198 string( REGEX REPLACE ".a$" ".dll" GSL_LIBRARY_DLL "${GSL_LIBRARY}" ) 0199 string( REGEX REPLACE ".a$" ".dll" GSL_CBLAS_LIBRARY_DLL "${GSL_CBLAS_LIBRARY}" ) 0200 string( REGEX REPLACE ".a$" ".dll" GSL_LIBRARY_DEBUG_DLL "${GSL_LIBRARY_DEBUG}" ) 0201 string( REGEX REPLACE ".a$" ".dll" GSL_CBLAS_LIBRARY_DEBUG_DLL "${GSL_CBLAS_LIBRARY_DEBUG}" ) 0202 endif() 0203 endif() 0204 0205 if( GSL_FOUND AND NOT TARGET GSL::gsl ) 0206 if( EXISTS "${GSL_LIBRARY_DLL}" AND EXISTS "${GSL_CBLAS_LIBRARY_DLL}") 0207 0208 # Windows systems with dll libraries. 0209 add_library( GSL::gsl SHARED IMPORTED ) 0210 add_library( GSL::gslcblas SHARED IMPORTED ) 0211 0212 # Windows with dlls, but only Release libraries. 0213 set_target_properties( GSL::gslcblas PROPERTIES 0214 IMPORTED_LOCATION_RELEASE "${GSL_CBLAS_LIBRARY_DLL}" 0215 IMPORTED_IMPLIB "${GSL_CBLAS_LIBRARY}" 0216 INTERFACE_INCLUDE_DIRECTORIES "${GSL_INCLUDE_DIRS}" 0217 IMPORTED_CONFIGURATIONS Release 0218 IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) 0219 set_target_properties( GSL::gsl PROPERTIES 0220 IMPORTED_LOCATION_RELEASE "${GSL_LIBRARY_DLL}" 0221 IMPORTED_IMPLIB "${GSL_LIBRARY}" 0222 INTERFACE_INCLUDE_DIRECTORIES "${GSL_INCLUDE_DIRS}" 0223 IMPORTED_CONFIGURATIONS Release 0224 IMPORTED_LINK_INTERFACE_LANGUAGES "C" 0225 INTERFACE_LINK_LIBRARIES GSL::gslcblas ) 0226 0227 # If we have both Debug and Release libraries 0228 if( EXISTS "${GSL_LIBRARY_DEBUG_DLL}" AND EXISTS "${GSL_CBLAS_LIBRARY_DEBUG_DLL}") 0229 set_property( TARGET GSL::gslcblas APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) 0230 set_target_properties( GSL::gslcblas PROPERTIES 0231 IMPORTED_LOCATION_DEBUG "${GSL_CBLAS_LIBRARY_DEBUG_DLL}" 0232 IMPORTED_IMPLIB_DEBUG "${GSL_CBLAS_LIBRARY_DEBUG}" ) 0233 set_property( TARGET GSL::gsl APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) 0234 set_target_properties( GSL::gsl PROPERTIES 0235 IMPORTED_LOCATION_DEBUG "${GSL_LIBRARY_DEBUG_DLL}" 0236 IMPORTED_IMPLIB_DEBUG "${GSL_LIBRARY_DEBUG}" ) 0237 endif() 0238 0239 else() 0240 0241 # For all other environments (ones without dll libraries), create 0242 # the imported library targets. 0243 add_library( GSL::gsl UNKNOWN IMPORTED ) 0244 add_library( GSL::gslcblas UNKNOWN IMPORTED ) 0245 set_target_properties( GSL::gslcblas PROPERTIES 0246 IMPORTED_LOCATION "${GSL_CBLAS_LIBRARY}" 0247 INTERFACE_INCLUDE_DIRECTORIES "${GSL_INCLUDE_DIRS}" 0248 IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) 0249 set_target_properties( GSL::gsl PROPERTIES 0250 IMPORTED_LOCATION "${GSL_LIBRARY}" 0251 INTERFACE_INCLUDE_DIRECTORIES "${GSL_INCLUDE_DIRS}" 0252 IMPORTED_LINK_INTERFACE_LANGUAGES "C" 0253 INTERFACE_LINK_LIBRARIES GSL::gslcblas ) 0254 endif() 0255 endif()