Replace our fftpack version with Numpy's version
[gromacs.git] / cmake / Findgsl.cmake
blobc2a75f233d00eec536357269588be1c9282d770f
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
6 # Once run this will define: 
7
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"
12
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
20 # Felix Woelk 07/2004
21 # Jan Woetzel
23 # www.mip.informatik.uni-kiel.de
24 # --------------------------------
26 IF(WIN32)
27   # JW tested with gsl-1.8, Windows XP, MSVS 7.1, MSVS 8.0
28   SET(GSL_POSSIBLE_ROOT_DIRS
29     ${GSL_ROOT_DIR}
30     $ENV{GSL_ROOT_DIR}
31     ${GSL_DIR}
32     ${GSL_HOME}    
33     $ENV{GSL_DIR}
34     $ENV{GSL_HOME}
35     $ENV{EXTERN_LIBS_DIR}/gsl
36     $ENV{EXTRA}
37     )
38   FIND_PATH(GSL_INCLUDE_DIR
39     NAMES gsl/gsl_cdf.h gsl/gsl_randist.h
40     PATHS ${GSL_POSSIBLE_ROOT_DIRS}
41     PATH_SUFFIXES include
42     DOC "GSL header include dir"
43     )
44   
45   FIND_LIBRARY(GSL_GSL_LIBRARY
46     NAMES gsl libgsl
47     PATHS  ${GSL_POSSIBLE_ROOT_DIRS}
48     PATH_SUFFIXES lib
49     DOC "GSL library dir" )  
50   
51   FIND_LIBRARY(GSL_GSLCBLAS_LIBRARY
52     NAMES gslcblas libgslcblas
53     PATHS  ${GSL_POSSIBLE_ROOT_DIRS}
54     PATH_SUFFIXES lib
55     DOC "GSL cblas library dir" )
56   
57   SET(GSL_LIBRARIES ${GSL_GSL_LIBRARY})
59   #MESSAGE("DBG\n"
60     #  "GSL_GSL_LIBRARY=${GSL_GSL_LIBRARY}\n"
61     #  "GSL_GSLCBLAS_LIBRARY=${GSL_GSLCBLAS_LIBRARY}\n"
62     #  "GSL_LIBRARIES=${GSL_LIBRARIES}")
65 ELSE(WIN32)
66   
67   IF(UNIX) 
68     SET(GSL_CONFIG_PREFER_PATH 
69       "$ENV{GSL_DIR}/bin"
70       "$ENV{GSL_DIR}"
71       "$ENV{GSL_HOME}/bin" 
72       "$ENV{GSL_HOME}" 
73       CACHE STRING "preferred path to GSL (gsl-config)")
74     FIND_PROGRAM(GSL_CONFIG gsl-config
75       ${GSL_CONFIG_PREFER_PATH}
76       /usr/bin/
77       )
78     # MESSAGE("DBG GSL_CONFIG ${GSL_CONFIG}")
79     
80     IF (GSL_CONFIG) 
81       
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}
85         ARGS --cflags
86         OUTPUT_VARIABLE  GSL_CXX_FLAGS )
87       #SET(GSL_CXX_FLAGS "`${GSL_CONFIG} --cflags`")
88       
89       # set INCLUDE_DIRS to prefix+include
90       EXEC_PROGRAM(${GSL_CONFIG}
91         ARGS --prefix
92         OUTPUT_VARIABLE GSL_PREFIX)
93       SET(GSL_INCLUDE_DIR ${GSL_PREFIX}/include CACHE STRING INTERNAL)
95       # set link libraries and link flags
96       
97       #SET(GSL_LIBRARIES "`${GSL_CONFIG} --libs`")
98       
99       # extract link dirs for rpath  
100       EXEC_PROGRAM(${GSL_CONFIG}
101         ARGS --libs
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
114       
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")
124       MARK_AS_ADVANCED(
125         GSL_CXX_FLAGS
126         GSL_INCLUDE_DIR
127         GSL_LIBRARIES
128         GSL_LINK_DIRECTORIES
129         GSL_DEFINITIONS
130         )
131       MESSAGE(STATUS "Using GSL from ${GSL_PREFIX}")
132       
133     ELSE(GSL_CONFIG)
134       
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)
140       IF(GSL_INCLUDE_DIR)
141         MARK_AS_ADVANCED(
142           GSL_CXX_FLAGS
143           GSL_INCLUDE_DIR
144           GSL_LIBRARIES
145           GSL_LINK_DIRECTORIES
146           )
147       ENDIF(GSL_INCLUDE_DIR)
148     ENDIF(GSL_CONFIG)
150   ENDIF(UNIX)
151 ENDIF(WIN32)
154 IF(GSL_LIBRARIES)
155   IF(GSL_INCLUDE_DIR OR GSL_CXX_FLAGS)
157     SET(GSL_FOUND 1)
158     
159   ENDIF(GSL_INCLUDE_DIR OR GSL_CXX_FLAGS)
160 ENDIF(GSL_LIBRARIES)
163 # ==========================================
164 IF(NOT GSL_FOUND)
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)
173 ENDIF(NOT GSL_FOUND)