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 # Once run this will define:
8 # GSL_FOUND = system has GSL lib
10 # GSL_LIBRARIES = full path to the libraries
11 # on Unix/Linux with additional linker flags from "gsl-config --libs"
13 # CMAKE_GSL_CXX_FLAGS = Unix compiler flags for GSL, essentially "`gsl-config --cxxflags`"
15 # GSL_INCLUDE_DIR = where to find headers
17 # GSL_LINK_DIRECTORIES = link directories, useful for rpath on Unix
18 # GSL_EXE_LINKER_FLAGS = rpath on Unix
23 # www.mip.informatik.uni-kiel.de
24 # --------------------------------
27 # JW tested with gsl-1.8, Windows XP, MSVS 7.1, MSVS 8.0
28 SET(GSL_POSSIBLE_ROOT_DIRS
35 $ENV{EXTERN_LIBS_DIR}/gsl
38 FIND_PATH(GSL_INCLUDE_DIR
39 NAMES gsl/gsl_cdf.h gsl/gsl_randist.h
40 PATHS ${GSL_POSSIBLE_ROOT_DIRS}
42 DOC "GSL header include dir"
45 FIND_LIBRARY(GSL_GSL_LIBRARY
47 PATHS ${GSL_POSSIBLE_ROOT_DIRS}
49 DOC "GSL library dir" )
51 FIND_LIBRARY(GSL_GSLCBLAS_LIBRARY
52 NAMES gslcblas libgslcblas
53 PATHS ${GSL_POSSIBLE_ROOT_DIRS}
55 DOC "GSL cblas library dir" )
57 SET(GSL_LIBRARIES ${GSL_GSL_LIBRARY})
60 # "GSL_GSL_LIBRARY=${GSL_GSL_LIBRARY}\n"
61 # "GSL_GSLCBLAS_LIBRARY=${GSL_GSLCBLAS_LIBRARY}\n"
62 # "GSL_LIBRARIES=${GSL_LIBRARIES}")
68 SET(GSL_CONFIG_PREFER_PATH
73 CACHE STRING "preferred path to GSL (gsl-config)")
74 FIND_PROGRAM(GSL_CONFIG gsl-config
75 ${GSL_CONFIG_PREFER_PATH}
78 # MESSAGE("DBG GSL_CONFIG ${GSL_CONFIG}")
82 MESSAGE(STATUS "GSL using gsl-config ${GSL_CONFIG}")
83 # set CXXFLAGS to be fed into CXX_FLAGS by the user:
84 EXEC_PROGRAM(${GSL_CONFIG}
86 OUTPUT_VARIABLE GSL_CXX_FLAGS )
87 #SET(GSL_CXX_FLAGS "`${GSL_CONFIG} --cflags`")
89 # set INCLUDE_DIRS to prefix+include
90 EXEC_PROGRAM(${GSL_CONFIG}
92 OUTPUT_VARIABLE GSL_PREFIX)
93 SET(GSL_INCLUDE_DIR ${GSL_PREFIX}/include CACHE STRING INTERNAL)
95 # set link libraries and link flags
97 #SET(GSL_LIBRARIES "`${GSL_CONFIG} --libs`")
99 # extract link dirs for rpath
100 EXEC_PROGRAM(${GSL_CONFIG}
102 OUTPUT_VARIABLE GSL_CONFIG_LIBS )
103 SET(GSL_LIBRARIES "${GSL_CONFIG_LIBS}")
105 # split off the link dirs (for rpath)
106 # use regular expression to match wildcard equivalent "-L*<endchar>"
107 # with <endchar> is a space or a semicolon
108 STRING(REGEX MATCHALL "[-][L]([^ ;])+"
109 GSL_LINK_DIRECTORIES_WITH_PREFIX
110 "${GSL_CONFIG_LIBS}" )
111 # MESSAGE("DBG GSL_LINK_DIRECTORIES_WITH_PREFIX=${GSL_LINK_DIRECTORIES_WITH_PREFIX}")
113 # remove prefix -L because we need the pure directory for LINK_DIRECTORIES
115 IF (GSL_LINK_DIRECTORIES_WITH_PREFIX)
116 STRING(REGEX REPLACE "[-][L]" "" GSL_LINK_DIRECTORIES ${GSL_LINK_DIRECTORIES_WITH_PREFIX} )
117 ENDIF (GSL_LINK_DIRECTORIES_WITH_PREFIX)
118 SET(GSL_EXE_LINKER_FLAGS "-Wl,-rpath,${GSL_LINK_DIRECTORIES}" CACHE STRING INTERNAL)
119 # MESSAGE("DBG GSL_LINK_DIRECTORIES=${GSL_LINK_DIRECTORIES}")
120 # MESSAGE("DBG GSL_EXE_LINKER_FLAGS=${GSL_EXE_LINKER_FLAGS}")
122 # ADD_DEFINITIONS("-DHAVE_GSL")
123 # SET(GSL_DEFINITIONS "-DHAVE_GSL")
131 MESSAGE(STATUS "Using GSL from ${GSL_PREFIX}")
135 INCLUDE(UsePkgConfig) #needed for PKGCONFIG(...)
137 MESSAGE(STATUS "GSL using pkgconfig")
138 # PKGCONFIG(gsl includedir libdir linkflags cflags)
139 PKGCONFIG(gsl GSL_INCLUDE_DIR GSL_LINK_DIRECTORIES GSL_LIBRARIES GSL_CXX_FLAGS)
147 ENDIF(GSL_INCLUDE_DIR)
155 IF(GSL_INCLUDE_DIR OR GSL_CXX_FLAGS)
159 ENDIF(GSL_INCLUDE_DIR OR GSL_CXX_FLAGS)
163 # ==========================================
165 # make FIND_PACKAGE friendly
166 IF(NOT GSL_FIND_QUIETLY)
167 IF(GSL_FIND_REQUIRED)
168 MESSAGE(FATAL_ERROR "GSL required, please specify it's location.")
169 ELSE(GSL_FIND_REQUIRED)
170 MESSAGE(STATUS "GSL was not found.")
171 ENDIF(GSL_FIND_REQUIRED)
172 ENDIF(NOT GSL_FIND_QUIETLY)