1 # Try to find gnu scientific library GSL
3 # http://www.gnu.org/software/gsl/ and
4 # http://gnuwin32.sourceforge.net/packages/gsl.htm
6 # Based on a script of Felix Woelk and Jan Woetzel
7 # (www.mip.informatik.uni-kiel.de)
9 # It defines the following variables:
10 # GSL_FOUND - system has GSL lib
11 # GSL_INCLUDE_DIRS - where to find headers
12 # GSL_LIBRARIES - full path to the libraries
13 # GSL_LIBRARY_DIRS, the directory where the PLplot library is found.
15 # CMAKE_GSL_CXX_FLAGS = Unix compiler flags for GSL, essentially "`gsl-config --cxxflags`"
16 # GSL_LINK_DIRECTORIES = link directories, useful for rpath on Unix
17 # GSL_EXE_LINKER_FLAGS = rpath on Unix
20 set( GSL_CBLAS_FOUND OFF )
22 # Windows, but not for Cygwin and MSys where gsl-config is available
23 if( WIN32 AND NOT CYGWIN AND NOT MSYS )
25 find_path( GSL_INCLUDE_DIR
26 NAMES gsl/gsl_cdf.h gsl/gsl_randist.h
29 # look for gsl library
30 find_library( GSL_LIBRARY
34 set( GSL_INCLUDE_DIRS ${GSL_INCLUDE_DIR} )
35 get_filename_component( GSL_LIBRARY_DIRS ${GSL_LIBRARY} PATH )
39 # look for gsl cblas library
40 find_library( GSL_CBLAS_LIBRARY
43 if( GSL_CBLAS_LIBRARY )
44 set( GSL_CBLAS_FOUND ON )
45 endif( GSL_CBLAS_LIBRARY )
47 set( GSL_LIBRARIES ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY} )
48 endif( GSL_INCLUDE_DIR )
55 else( WIN32 AND NOT CYGWIN AND NOT MSYS )
57 find_program( GSL_CONFIG_EXECUTABLE gsl-config
62 if( GSL_CONFIG_EXECUTABLE )
65 # run the gsl-config program to get cxxflags
67 COMMAND sh "${GSL_CONFIG_EXECUTABLE}" --cflags
68 OUTPUT_VARIABLE GSL_CFLAGS
73 string( STRIP "${GSL_CFLAGS}" GSL_CFLAGS )
74 separate_arguments( GSL_CFLAGS )
76 # parse definitions from cflags; drop -D* from CFLAGS
77 string( REGEX MATCHALL "-D[^;]+"
78 GSL_DEFINITIONS "${GSL_CFLAGS}" )
79 string( REGEX REPLACE "-D[^;]+;" ""
80 GSL_CFLAGS "${GSL_CFLAGS}" )
82 # parse include dirs from cflags; drop -I prefix
83 string( REGEX MATCHALL "-I[^;]+"
84 GSL_INCLUDE_DIRS "${GSL_CFLAGS}" )
85 string( REPLACE "-I" ""
86 GSL_INCLUDE_DIRS "${GSL_INCLUDE_DIRS}")
87 string( REGEX REPLACE "-I[^;]+;" ""
88 GSL_CFLAGS "${GSL_CFLAGS}")
90 message("GSL_DEFINITIONS=${GSL_DEFINITIONS}")
91 message("GSL_INCLUDE_DIRS=${GSL_INCLUDE_DIRS}")
92 message("GSL_CFLAGS=${GSL_CFLAGS}")
94 set( GSL_FOUND FALSE )
97 # run the gsl-config program to get the libs
99 COMMAND sh "${GSL_CONFIG_EXECUTABLE}" --libs
100 OUTPUT_VARIABLE GSL_LIBRARIES
105 string(STRIP "${GSL_LIBRARIES}" GSL_LIBRARIES )
106 separate_arguments( GSL_LIBRARIES )
108 # extract linkdirs (-L) for rpath (i.e., LINK_DIRECTORIES)
109 string( REGEX MATCHALL "-L[^;]+"
110 GSL_LIBRARY_DIRS "${GSL_LIBRARIES}" )
111 string( REPLACE "-L" ""
112 GSL_LIBRARY_DIRS "${GSL_LIBRARY_DIRS}" )
114 set( GSL_FOUND FALSE )
120 message( STATUS "Using GSL from ${GSL_PREFIX}" )
121 else( GSL_CONFIG_EXECUTABLE )
122 message( STATUS "FindGSL: gsl-config not found.")
123 endif( GSL_CONFIG_EXECUTABLE )
124 endif( UNIX OR MSYS )
125 endif( WIN32 AND NOT CYGWIN AND NOT MSYS )
128 if( NOT GSL_FIND_QUIETLY )
129 message( STATUS "FindGSL: Found both GSL headers and library" )
130 endif( NOT GSL_FIND_QUIETLY )
132 if( GSL_FIND_REQUIRED )
133 message( FATAL_ERROR "FindGSL: Could not find GSL headers or library" )
134 endif( GSL_FIND_REQUIRED )