Update copyright statements and change license to LGPL
[alexxy/gromacs.git] / cmake / Findgsl.cmake
1 #
2 # This file is part of the GROMACS molecular simulation package.
3 #
4 # Copyright (c) 2012, by the GROMACS development team, led by
5 # David van der Spoel, Berk Hess, Erik Lindahl, and including many
6 # others, as listed in the AUTHORS file in the top-level source
7 # directory and at http://www.gromacs.org.
8 #
9 # GROMACS is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public License
11 # as published by the Free Software Foundation; either version 2.1
12 # of the License, or (at your option) any later version.
13 #
14 # GROMACS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # Lesser General Public License for more details.
18 #
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with GROMACS; if not, see
21 # http://www.gnu.org/licenses, or write to the Free Software Foundation,
22 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23 #
24 # If you want to redistribute modifications to GROMACS, please
25 # consider that scientific software is very special. Version
26 # control is crucial - bugs must be traceable. We will be happy to
27 # consider code for inclusion in the official distribution, but
28 # derived work must not be called official GROMACS. Details are found
29 # in the README & COPYING files - if they are missing, get the
30 # official version at http://www.gromacs.org.
31 #
32 # To help us fund GROMACS development, we humbly ask that you cite
33 # the research papers on the package. Check out http://www.gromacs.org.
34 #
35 # Try to find gnu scientific library GSL
36 # See 
37 # http://www.gnu.org/software/gsl/  and 
38 # http://gnuwin32.sourceforge.net/packages/gsl.htm
39 #
40 # Once run this will define: 
41
42 # GSL_FOUND       = system has GSL lib
43 #
44 # GSL_LIBRARIES   = full path to the libraries
45 #    on Unix/Linux with additional linker flags from "gsl-config --libs"
46
47 # CMAKE_GSL_CXX_FLAGS  = Unix compiler flags for GSL, essentially "`gsl-config --cxxflags`"
48 #
49 # GSL_INCLUDE_DIR      = where to find headers 
50 #
51 # GSL_LINK_DIRECTORIES = link directories, useful for rpath on Unix
52 # GSL_EXE_LINKER_FLAGS = rpath on Unix
53 #
54 # Felix Woelk 07/2004
55 # Jan Woetzel
56 #
57 # www.mip.informatik.uni-kiel.de
58 # --------------------------------
59
60 IF(WIN32)
61   # JW tested with gsl-1.8, Windows XP, MSVS 7.1, MSVS 8.0
62   SET(GSL_POSSIBLE_ROOT_DIRS
63     ${GSL_ROOT_DIR}
64     $ENV{GSL_ROOT_DIR}
65     ${GSL_DIR}
66     ${GSL_HOME}    
67     $ENV{GSL_DIR}
68     $ENV{GSL_HOME}
69     $ENV{EXTERN_LIBS_DIR}/gsl
70     $ENV{EXTRA}
71     )
72   FIND_PATH(GSL_INCLUDE_DIR
73     NAMES gsl/gsl_cdf.h gsl/gsl_randist.h
74     PATHS ${GSL_POSSIBLE_ROOT_DIRS}
75     PATH_SUFFIXES include
76     DOC "GSL header include dir"
77     )
78   
79   FIND_LIBRARY(GSL_GSL_LIBRARY
80     NAMES gsl libgsl
81     PATHS  ${GSL_POSSIBLE_ROOT_DIRS}
82     PATH_SUFFIXES lib
83     DOC "GSL library dir" )  
84   
85   FIND_LIBRARY(GSL_GSLCBLAS_LIBRARY
86     NAMES gslcblas libgslcblas
87     PATHS  ${GSL_POSSIBLE_ROOT_DIRS}
88     PATH_SUFFIXES lib
89     DOC "GSL cblas library dir" )
90   
91   SET(GSL_LIBRARIES ${GSL_GSL_LIBRARY})
92
93   #MESSAGE("DBG\n"
94     #  "GSL_GSL_LIBRARY=${GSL_GSL_LIBRARY}\n"
95     #  "GSL_GSLCBLAS_LIBRARY=${GSL_GSLCBLAS_LIBRARY}\n"
96     #  "GSL_LIBRARIES=${GSL_LIBRARIES}")
97
98
99 ELSE(WIN32)
100   
101   IF(UNIX) 
102     SET(GSL_CONFIG_PREFER_PATH 
103       "$ENV{GSL_DIR}/bin"
104       "$ENV{GSL_DIR}"
105       "$ENV{GSL_HOME}/bin" 
106       "$ENV{GSL_HOME}" 
107       CACHE STRING "preferred path to GSL (gsl-config)")
108     FIND_PROGRAM(GSL_CONFIG gsl-config
109       ${GSL_CONFIG_PREFER_PATH}
110       /usr/bin/
111       )
112     # MESSAGE("DBG GSL_CONFIG ${GSL_CONFIG}")
113     
114     IF (GSL_CONFIG) 
115       
116       MESSAGE(STATUS "GSL using gsl-config ${GSL_CONFIG}")
117       # set CXXFLAGS to be fed into CXX_FLAGS by the user:
118       EXEC_PROGRAM(${GSL_CONFIG}
119         ARGS --cflags
120         OUTPUT_VARIABLE  GSL_CXX_FLAGS )
121       #SET(GSL_CXX_FLAGS "`${GSL_CONFIG} --cflags`")
122       
123       # set INCLUDE_DIRS to prefix+include
124       EXEC_PROGRAM(${GSL_CONFIG}
125         ARGS --prefix
126         OUTPUT_VARIABLE GSL_PREFIX)
127       SET(GSL_INCLUDE_DIR ${GSL_PREFIX}/include CACHE STRING INTERNAL)
128
129       # set link libraries and link flags
130       
131       #SET(GSL_LIBRARIES "`${GSL_CONFIG} --libs`")
132       
133       # extract link dirs for rpath  
134       EXEC_PROGRAM(${GSL_CONFIG}
135         ARGS --libs
136         OUTPUT_VARIABLE  GSL_CONFIG_LIBS )
137       SET(GSL_LIBRARIES "${GSL_CONFIG_LIBS}")
138
139       # split off the link dirs (for rpath)
140       # use regular expression to match wildcard equivalent "-L*<endchar>"
141       # with <endchar> is a space or a semicolon
142       STRING(REGEX MATCHALL "[-][L]([^ ;])+" 
143         GSL_LINK_DIRECTORIES_WITH_PREFIX 
144         "${GSL_CONFIG_LIBS}" )
145       #      MESSAGE("DBG  GSL_LINK_DIRECTORIES_WITH_PREFIX=${GSL_LINK_DIRECTORIES_WITH_PREFIX}")
146
147       # remove prefix -L because we need the pure directory for LINK_DIRECTORIES
148       
149       IF (GSL_LINK_DIRECTORIES_WITH_PREFIX)
150         STRING(REGEX REPLACE "[-][L]" "" GSL_LINK_DIRECTORIES ${GSL_LINK_DIRECTORIES_WITH_PREFIX} )
151       ENDIF (GSL_LINK_DIRECTORIES_WITH_PREFIX)
152       SET(GSL_EXE_LINKER_FLAGS "-Wl,-rpath,${GSL_LINK_DIRECTORIES}" CACHE STRING INTERNAL)
153       #      MESSAGE("DBG  GSL_LINK_DIRECTORIES=${GSL_LINK_DIRECTORIES}")
154       #      MESSAGE("DBG  GSL_EXE_LINKER_FLAGS=${GSL_EXE_LINKER_FLAGS}")
155
156       #      ADD_DEFINITIONS("-DHAVE_GSL")
157       #      SET(GSL_DEFINITIONS "-DHAVE_GSL")
158       MARK_AS_ADVANCED(
159         GSL_CXX_FLAGS
160         GSL_INCLUDE_DIR
161         GSL_LIBRARIES
162         GSL_LINK_DIRECTORIES
163         GSL_DEFINITIONS
164         )
165       MESSAGE(STATUS "Using GSL from ${GSL_PREFIX}")
166       
167     ELSE(GSL_CONFIG)
168       
169       INCLUDE(UsePkgConfig) #needed for PKGCONFIG(...)
170
171       MESSAGE(STATUS "GSL using pkgconfig")
172       #      PKGCONFIG(gsl includedir libdir linkflags cflags)
173       PKGCONFIG(gsl GSL_INCLUDE_DIR GSL_LINK_DIRECTORIES GSL_LIBRARIES GSL_CXX_FLAGS)
174       IF(GSL_INCLUDE_DIR)
175         MARK_AS_ADVANCED(
176           GSL_CXX_FLAGS
177           GSL_INCLUDE_DIR
178           GSL_LIBRARIES
179           GSL_LINK_DIRECTORIES
180           )
181       ENDIF(GSL_INCLUDE_DIR)
182     ENDIF(GSL_CONFIG)
183
184   ENDIF(UNIX)
185 ENDIF(WIN32)
186
187
188 IF(GSL_LIBRARIES)
189   IF(GSL_INCLUDE_DIR OR GSL_CXX_FLAGS)
190
191     SET(GSL_FOUND 1)
192     
193   ENDIF(GSL_INCLUDE_DIR OR GSL_CXX_FLAGS)
194 ENDIF(GSL_LIBRARIES)
195
196
197 # ==========================================
198 IF(NOT GSL_FOUND)
199   # make FIND_PACKAGE friendly
200   IF(NOT GSL_FIND_QUIETLY)
201     IF(GSL_FIND_REQUIRED)
202       MESSAGE(FATAL_ERROR "GSL required, please specify it's location.")
203     ELSE(GSL_FIND_REQUIRED)
204       MESSAGE(STATUS       "GSL was not found.")
205     ENDIF(GSL_FIND_REQUIRED)
206   ENDIF(NOT GSL_FIND_QUIETLY)
207 ENDIF(NOT GSL_FOUND)