Statistics
| Branch: | Tag: | Revision:

root / cmake / Modules / FindGSL.cmake @ accb9f2f

History | View | Annotate | Download (4.3 kB)

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
INCLUDE(FindPkgConfig)
20
PKG_CHECK_MODULES(GSL "gsl >= 1.10")
21
IF(NOT GSL_FOUND)
22
23
set( GSL_FOUND OFF )
24
set( GSL_CBLAS_FOUND OFF )
25
26
# Windows, but not for Cygwin and MSys where gsl-config is available
27
if( WIN32 AND NOT CYGWIN AND NOT MSYS )
28
	# look for headers
29
  find_path( GSL_INCLUDE_DIR
30
    NAMES gsl/gsl_cdf.h gsl/gsl_randist.h
31
    )
32
  if( GSL_INCLUDE_DIR )
33
  	# look for gsl library
34
    find_library( GSL_LIBRARY
35
      NAMES gsl
36
    )
37
    if( GSL_LIBRARY )
38
      set( GSL_INCLUDE_DIRS ${GSL_INCLUDE_DIR} )
39
      get_filename_component( GSL_LIBRARY_DIRS ${GSL_LIBRARY} PATH )
40
      set( GSL_FOUND ON )
41
    endif( GSL_LIBRARY )
42
43
		# look for gsl cblas library
44
    find_library( GSL_CBLAS_LIBRARY
45
        NAMES gslcblas
46
      )
47
    if( GSL_CBLAS_LIBRARY )
48
      set( GSL_CBLAS_FOUND ON )
49
    endif( GSL_CBLAS_LIBRARY )
50
51
    set( GSL_LIBRARIES ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY} )
52
  endif( GSL_INCLUDE_DIR )
53
54
  #mark_as_advanced(
55
  #  GSL_INCLUDE_DIR
56
  #  GSL_LIBRARY
57
  #  GSL_CBLAS_LIBRARY
58
  #)
59
else( WIN32 AND NOT CYGWIN AND NOT MSYS )
60
  if( UNIX OR MSYS )
61
		find_program( GSL_CONFIG_EXECUTABLE gsl-config
62
			/usr/bin/
63
			/usr/local/bin
64
		)
65
66
		if( GSL_CONFIG_EXECUTABLE )
67
			set( GSL_FOUND ON )
68
69
      # run the gsl-config program to get cxxflags
70
      execute_process(
71
        COMMAND sh "${GSL_CONFIG_EXECUTABLE}" --cflags
72
        OUTPUT_VARIABLE GSL_CFLAGS
73
        RESULT_VARIABLE RET
74
        ERROR_QUIET
75
        )
76
      if( RET EQUAL 0 )
77
        string( STRIP "${GSL_CFLAGS}" GSL_CFLAGS )
78
        separate_arguments( GSL_CFLAGS )
79
80
        # parse definitions from cflags; drop -D* from CFLAGS
81
        string( REGEX MATCHALL "-D[^;]+"
82
          GSL_DEFINITIONS  "${GSL_CFLAGS}" )
83
        string( REGEX REPLACE "-D[^;]+;" ""
84
          GSL_CFLAGS "${GSL_CFLAGS}" )
85
86
        # parse include dirs from cflags; drop -I prefix
87
        string( REGEX MATCHALL "-I[^;]+"
88
          GSL_INCLUDE_DIRS "${GSL_CFLAGS}" )
89
        string( REPLACE "-I" ""
90
          GSL_INCLUDE_DIRS "${GSL_INCLUDE_DIRS}")
91
        string( REGEX REPLACE "-I[^;]+;" ""
92
          GSL_CFLAGS "${GSL_CFLAGS}")
93
94
        message("GSL_DEFINITIONS=${GSL_DEFINITIONS}")
95
        message("GSL_INCLUDE_DIRS=${GSL_INCLUDE_DIRS}")
96
        message("GSL_CFLAGS=${GSL_CFLAGS}")
97
      else( RET EQUAL 0 )
98
        set( GSL_FOUND FALSE )
99
      endif( RET EQUAL 0 )
100
101
      # run the gsl-config program to get the libs
102
      execute_process(
103
        COMMAND sh "${GSL_CONFIG_EXECUTABLE}" --libs
104
        OUTPUT_VARIABLE GSL_LIBRARIES
105
        RESULT_VARIABLE RET
106
        ERROR_QUIET
107
        )
108
      if( RET EQUAL 0 )
109
        string(STRIP "${GSL_LIBRARIES}" GSL_LIBRARIES )
110
        separate_arguments( GSL_LIBRARIES )
111
112
        # extract linkdirs (-L) for rpath (i.e., LINK_DIRECTORIES)
113
        string( REGEX MATCHALL "-L[^;]+"
114
          GSL_LIBRARY_DIRS "${GSL_LIBRARIES}" )
115
        string( REPLACE "-L" ""
116
          GSL_LIBRARY_DIRS "${GSL_LIBRARY_DIRS}" )
117
      else( RET EQUAL 0 )
118
        set( GSL_FOUND FALSE )
119
      endif( RET EQUAL 0 )
120
121
			MARK_AS_ADVANCED(
122
				GSL_CFLAGS
123
			)
124
			message( STATUS "Using GSL from ${GSL_PREFIX}" )
125
		else( GSL_CONFIG_EXECUTABLE )
126
			message( STATUS "FindGSL: gsl-config not found.")
127
		endif( GSL_CONFIG_EXECUTABLE )
128
	endif( UNIX OR MSYS )
129
endif( WIN32 AND NOT CYGWIN AND NOT MSYS )
130
131
if( GSL_FOUND )
132
  if( NOT GSL_FIND_QUIETLY )
133
    message( STATUS "FindGSL: Found both GSL headers and library" )
134
  endif( NOT GSL_FIND_QUIETLY )
135
else( GSL_FOUND )
136
  if( GSL_FIND_REQUIRED )
137
    message( FATAL_ERROR "FindGSL: Could not find GSL headers or library" )
138
  endif( GSL_FIND_REQUIRED )
139
endif( GSL_FOUND )
140
141
INCLUDE(FindPackageHandleStandardArgs)
142
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GSL DEFAULT_MSG GSL_LIBRARIES GSL_INCLUDE_DIRS)
143
ENDIF(NOT GSL_FOUND)