forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindGSL.cmake
128 lines (107 loc) · 4.06 KB
/
FindGSL.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# Try to find gnu scientific library GSL
# See
# http://www.gnu.org/software/gsl/ and
# http://gnuwin32.sourceforge.net/packages/gsl.htm
#
# Based on a script of Felix Woelk and Jan Woetzel
# (www.mip.informatik.uni-kiel.de)
#
# It defines the following variables:
# GSL_FOUND - system has GSL lib
# GSL_INCLUDE_DIR - where to find headers
# GSL_LIBRARY - the gsl library
# GSL_CBLAS_LIBRARY - the gslcblas library
# GSL_LIBRARIES - full path to the libraries
# GSL_LIBRARY_DIR - the directory where the PLplot library is found.
# GSL_CFLAGS - additional c (c++) required
# Windows, but not for Cygwin and MSys where gsl-config is available
if(WIN32 AND NOT CYGWIN AND NOT MSYS)
# look for headers
find_path(GSL_INCLUDE_DIR
NAMES gsl/gsl_cdf.h gsl/gsl_randist.h
PATHS ${GSL_DIR}/include $ENV{GSL_DIR}/include
)
if(GSL_INCLUDE_DIR)
file(READ ${GSL_INCLUDE_DIR}/gsl/gsl_version.h versionstr)
string(REGEX REPLACE ".*GSL_VERSION[ \"]*([0-9]+[.][0-9]+).*" "\\1" GSL_VERSION "${versionstr}")
endif()
# look for gsl library
find_library(GSL_LIBRARY
NAMES gsl
PATHS ${GSL_DIR}/lib $ENV{GSL_DIR}/lib
)
if(GSL_LIBRARY)
get_filename_component(GSL_LIBRARY_DIR ${GSL_LIBRARY} PATH )
endif()
# look for gsl cblas library
find_library(GSL_CBLAS_LIBRARY
NAMES gslcblas
PATHS ${GSL_DIR}/lib $ENV{GSL_DIR}/lib
)
if(GSL_CBLAS_LIBRARY)
set(GSL_LIBRARIES ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY})
else()
set(GSL_LIBRARIES ${GSL_LIBRARY})
endif()
execute_process ( COMMAND lib /list ${GSL_LIBRARY} OUTPUT_VARIABLE content )
string(FIND ${content} ".dll" APOSITION )
if( NOT ("${APOSITION}" STREQUAL "-1") )
set( GSL_CFLAGS "-DGSL_DLL" )
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GSL REQUIRED_VARS GSL_INCLUDE_DIR GSL_LIBRARY VERSION_VAR GSL_VERSION)
mark_as_advanced(GSL_INCLUDE_DIR GSL_LIBRARY GSL_CBLAS_LIBRARY)
else( WIN32 AND NOT CYGWIN AND NOT MSYS )
if( UNIX OR MSYS )
find_program( GSL_CONFIG_EXECUTABLE gsl-config
${GSL_DIR}/bin
$ENV{GSL_DIR}/bin
/usr/bin/
/usr/local/bin
)
if( GSL_CONFIG_EXECUTABLE )
# run the gsl-config program to get cxxflags
execute_process(
COMMAND sh "${GSL_CONFIG_EXECUTABLE}" --cflags
OUTPUT_VARIABLE GSL_CFLAGS
RESULT_VARIABLE RET
ERROR_QUIET
)
if(RET EQUAL 0)
string(STRIP "${GSL_CFLAGS}" GSL_CFLAGS)
separate_arguments(GSL_CFLAGS)
# parse definitions from cflags; drop -D* from CFLAGS
string(REGEX MATCHALL "-D[^;]+" GSL_DEFINITIONS "${GSL_CFLAGS}")
string(REGEX REPLACE "-D[^;]+;" "" GSL_CFLAGS "${GSL_CFLAGS}")
# parse include dirs from cflags; drop -I prefix
string(REGEX MATCH "-I[^;]+" GSL_INCLUDE_DIR "${GSL_CFLAGS}")
string(REPLACE "-I" "" GSL_INCLUDE_DIR "${GSL_INCLUDE_DIR}")
string(REGEX REPLACE "-I[^;]+;" "" GSL_CFLAGS "${GSL_CFLAGS}")
endif()
# run the gsl-config program to get the libs
execute_process(
COMMAND sh "${GSL_CONFIG_EXECUTABLE}" --libs
OUTPUT_VARIABLE GSL_LIBRARIES
RESULT_VARIABLE RET
ERROR_QUIET
)
if(RET EQUAL 0)
string(STRIP "${GSL_LIBRARIES}" GSL_LIBRARIES)
separate_arguments(GSL_LIBRARIES)
# extract linkdirs (-L) for rpath (i.e., LINK_DIRECTORIES)
string(REGEX MATCH "-L[^;]+" GSL_LIBRARY_DIR "${GSL_LIBRARIES}")
string(REPLACE "-L" "" GSL_LIBRARY_DIR "${GSL_LIBRARY_DIR}")
endif()
execute_process(
COMMAND sh "${GSL_CONFIG_EXECUTABLE}" --version
OUTPUT_VARIABLE GSL_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(GSL REQUIRED_VARS GSL_INCLUDE_DIR GSL_LIBRARIES VERSION_VAR GSL_VERSION)
else( GSL_CONFIG_EXECUTABLE )
message( STATUS "FindGSL: gsl-config not found.")
endif( GSL_CONFIG_EXECUTABLE )
mark_as_advanced(GSL_CONFIG_EXECUTABLE)
endif( UNIX OR MSYS )
endif( WIN32 AND NOT CYGWIN AND NOT MSYS )