]> git.treefish.org Git - phys/heatbath.git/blob - FindGSL.cmake
...
[phys/heatbath.git] / FindGSL.cmake
1 # Try to find gnu scientific library GSL
2 # See
3 # http://www.gnu.org/software/gsl/  and
4 # http://gnuwin32.sourceforge.net/packages/gsl.htm
5 #
6 # Based on a script of Felix Woelk and Jan Woetzel
7 # (www.mip.informatik.uni-kiel.de)
8 #
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.
14  
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
18  
19 set( GSL_FOUND OFF )
20 set( GSL_CBLAS_FOUND OFF )
21  
22 # Windows, but not for Cygwin and MSys where gsl-config is available
23 if( WIN32 AND NOT CYGWIN AND NOT MSYS )
24   # look for headers
25   find_path( GSL_INCLUDE_DIR
26     NAMES gsl/gsl_cdf.h gsl/gsl_randist.h
27     )
28   if( GSL_INCLUDE_DIR )
29     # look for gsl library
30     find_library( GSL_LIBRARY
31       NAMES gsl
32     ) 
33     if( GSL_LIBRARY )
34       set( GSL_INCLUDE_DIRS ${GSL_INCLUDE_DIR} )
35       get_filename_component( GSL_LIBRARY_DIRS ${GSL_LIBRARY} PATH )
36       set( GSL_FOUND ON )
37     endif( GSL_LIBRARY )
38  
39     # look for gsl cblas library
40     find_library( GSL_CBLAS_LIBRARY
41         NAMES gslcblas
42       )
43     if( GSL_CBLAS_LIBRARY )
44       set( GSL_CBLAS_FOUND ON )
45     endif( GSL_CBLAS_LIBRARY )
46        
47     set( GSL_LIBRARIES ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY} )
48   endif( GSL_INCLUDE_DIR )
49    
50   mark_as_advanced(
51     GSL_INCLUDE_DIR
52     GSL_LIBRARY
53     GSL_CBLAS_LIBRARY
54   )
55 else( WIN32 AND NOT CYGWIN AND NOT MSYS )
56   if( UNIX OR MSYS )
57     find_program( GSL_CONFIG_EXECUTABLE gsl-config
58       /usr/bin/
59       /usr/local/bin
60     )
61      
62     if( GSL_CONFIG_EXECUTABLE )
63       set( GSL_FOUND ON )
64        
65       # run the gsl-config program to get cxxflags
66       execute_process(
67         COMMAND sh "${GSL_CONFIG_EXECUTABLE}" --cflags
68         OUTPUT_VARIABLE GSL_CFLAGS
69         RESULT_VARIABLE RET
70         ERROR_QUIET
71         )
72       if( RET EQUAL 0 )
73         string( STRIP "${GSL_CFLAGS}" GSL_CFLAGS )
74         separate_arguments( GSL_CFLAGS )
75  
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}" )
81  
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}")
89  
90         message("GSL_DEFINITIONS=${GSL_DEFINITIONS}")
91         message("GSL_INCLUDE_DIRS=${GSL_INCLUDE_DIRS}")
92         message("GSL_CFLAGS=${GSL_CFLAGS}")
93       else( RET EQUAL 0 )
94         set( GSL_FOUND FALSE )
95       endif( RET EQUAL 0 )
96  
97       # run the gsl-config program to get the libs
98       execute_process(
99         COMMAND sh "${GSL_CONFIG_EXECUTABLE}" --libs
100         OUTPUT_VARIABLE GSL_LIBRARIES
101         RESULT_VARIABLE RET
102         ERROR_QUIET
103         )
104       if( RET EQUAL 0 )
105         string(STRIP "${GSL_LIBRARIES}" GSL_LIBRARIES )
106         separate_arguments( GSL_LIBRARIES )
107  
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}" )
113       else( RET EQUAL 0 )
114         set( GSL_FOUND FALSE )
115       endif( RET EQUAL 0 )
116        
117       MARK_AS_ADVANCED(
118         GSL_CFLAGS
119       )
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 )
126  
127 if( GSL_FOUND )
128   if( NOT GSL_FIND_QUIETLY )
129     message( STATUS "FindGSL: Found both GSL headers and library" )
130   endif( NOT GSL_FIND_QUIETLY )
131 else( GSL_FOUND )
132   if( GSL_FIND_REQUIRED )
133     message( FATAL_ERROR "FindGSL: Could not find GSL headers or library" )
134   endif( GSL_FIND_REQUIRED )
135 endif( GSL_FOUND )