You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

170 lines
4.9 KiB

  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. # Once run this will define:
  7. #
  8. # GSL_FOUND = system has GSL lib
  9. #
  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`"
  14. #
  15. # GSL_INCLUDE_DIR = where to find headers
  16. #
  17. # GSL_LINK_DIRECTORIES = link directories, useful for rpath on Unix
  18. # GSL_EXE_LINKER_FLAGS = rpath on Unix
  19. #
  20. # Felix Woelk 07/2004
  21. # Jan Woetzel
  22. #
  23. # www.mip.informatik.uni-kiel.de
  24. # --------------------------------
  25. IF(WIN32)
  26. # JW tested with gsl-1.8, Windows XP, MSVS 7.1
  27. SET(GSL_POSSIBLE_ROOT_DIRS
  28. ${GSL_ROOT_DIR}
  29. $ENV{GSL_ROOT_DIR}
  30. ${GSL_DIR}
  31. ${GSL_HOME}
  32. $ENV{GSL_DIR}
  33. $ENV{GSL_HOME}
  34. $ENV{EXTRA}
  35. "C:/Program Files/GnuWin32"
  36. )
  37. FIND_PATH(GSL_INCLUDE_DIR
  38. NAMES gsl/gsl_cdf.h gsl/gsl_randist.h
  39. PATHS ${GSL_POSSIBLE_ROOT_DIRS}
  40. PATH_SUFFIXES include
  41. DOC "GSL header include dir"
  42. )
  43. FIND_LIBRARY(GSL_GSL_LIBRARY
  44. NAMES libgsl.dll.a gsl libgsl
  45. PATHS ${GSL_POSSIBLE_ROOT_DIRS}
  46. PATH_SUFFIXES lib
  47. DOC "GSL library" )
  48. if(NOT GSL_GSL_LIBRARY)
  49. FIND_FILE(GSL_GSL_LIBRARY
  50. NAMES libgsl.dll.a
  51. PATHS ${GSL_POSSIBLE_ROOT_DIRS}
  52. PATH_SUFFIXES lib
  53. DOC "GSL library")
  54. endif(NOT GSL_GSL_LIBRARY)
  55. FIND_LIBRARY(GSL_GSLCBLAS_LIBRARY
  56. NAMES libgslcblas.dll.a gslcblas libgslcblas
  57. PATHS ${GSL_POSSIBLE_ROOT_DIRS}
  58. PATH_SUFFIXES lib
  59. DOC "GSL cblas library dir" )
  60. if(NOT GSL_GSLCBLAS_LIBRARY)
  61. FIND_FILE(GSL_GSLCBLAS_LIBRARY
  62. NAMES libgslcblas.dll.a
  63. PATHS ${GSL_POSSIBLE_ROOT_DIRS}
  64. PATH_SUFFIXES lib
  65. DOC "GSL library")
  66. endif(NOT GSL_GSLCBLAS_LIBRARY)
  67. SET(GSL_LIBRARIES ${GSL_GSL_LIBRARY})
  68. #MESSAGE("DBG\n"
  69. # "GSL_GSL_LIBRARY=${GSL_GSL_LIBRARY}\n"
  70. # "GSL_GSLCBLAS_LIBRARY=${GSL_GSLCBLAS_LIBRARY}\n"
  71. # "GSL_LIBRARIES=${GSL_LIBRARIES}")
  72. ELSE(WIN32)
  73. IF(UNIX)
  74. SET(GSL_CONFIG_PREFER_PATH
  75. "$ENV{GSL_DIR}/bin"
  76. "$ENV{GSL_DIR}"
  77. "$ENV{GSL_HOME}/bin"
  78. "$ENV{GSL_HOME}"
  79. CACHE STRING "preferred path to GSL (gsl-config)")
  80. FIND_PROGRAM(GSL_CONFIG gsl-config
  81. ${GSL_CONFIG_PREFER_PATH}
  82. /usr/bin/
  83. )
  84. # MESSAGE("DBG GSL_CONFIG ${GSL_CONFIG}")
  85. IF (GSL_CONFIG)
  86. # set CXXFLAGS to be fed into CXX_FLAGS by the user:
  87. SET(GSL_CXX_FLAGS "`${GSL_CONFIG} --cflags`")
  88. # set INCLUDE_DIRS to prefix+include
  89. EXEC_PROGRAM(${GSL_CONFIG}
  90. ARGS --prefix
  91. OUTPUT_VARIABLE GSL_PREFIX)
  92. SET(GSL_INCLUDE_DIR ${GSL_PREFIX}/include CACHE STRING INTERNAL)
  93. # set link libraries and link flags
  94. #SET(GSL_LIBRARIES "`${GSL_CONFIG} --libs`")
  95. EXEC_PROGRAM(${GSL_CONFIG}
  96. ARGS --libs
  97. OUTPUT_VARIABLE GSL_LIBRARIES )
  98. # extract link dirs for rpath
  99. EXEC_PROGRAM(${GSL_CONFIG}
  100. ARGS --libs
  101. OUTPUT_VARIABLE GSL_CONFIG_LIBS )
  102. # extract version
  103. EXEC_PROGRAM(${GSL_CONFIG}
  104. ARGS --version
  105. OUTPUT_VARIABLE GSL_FULL_VERSION )
  106. # split version as major/minor
  107. STRING(REGEX MATCH "(.)\\..*" GSL_VERSION_MAJOR_ "${GSL_FULL_VERSION}")
  108. SET(GSL_VERSION_MAJOR ${CMAKE_MATCH_1})
  109. STRING(REGEX MATCH ".\\.(.*)" GSL_VERSION_MINOR_ "${GSL_FULL_VERSION}")
  110. SET(GSL_VERSION_MINOR ${CMAKE_MATCH_1})
  111. # split off the link dirs (for rpath)
  112. # use regular expression to match wildcard equivalent "-L*<endchar>"
  113. # with <endchar> is a space or a semicolon
  114. STRING(REGEX MATCHALL "[-][L]([^ ;])+"
  115. GSL_LINK_DIRECTORIES_WITH_PREFIX
  116. "${GSL_CONFIG_LIBS}" )
  117. # MESSAGE("DBG GSL_LINK_DIRECTORIES_WITH_PREFIX=${GSL_LINK_DIRECTORIES_WITH_PREFIX}")
  118. # remove prefix -L because we need the pure directory for LINK_DIRECTORIES
  119. IF (GSL_LINK_DIRECTORIES_WITH_PREFIX)
  120. STRING(REGEX REPLACE "[-][L]" "" GSL_LINK_DIRECTORIES ${GSL_LINK_DIRECTORIES_WITH_PREFIX} )
  121. ENDIF (GSL_LINK_DIRECTORIES_WITH_PREFIX)
  122. SET(GSL_EXE_LINKER_FLAGS "-Wl,-rpath,${GSL_LINK_DIRECTORIES}" CACHE STRING INTERNAL)
  123. # MESSAGE("DBG GSL_LINK_DIRECTORIES=${GSL_LINK_DIRECTORIES}")
  124. # MESSAGE("DBG GSL_EXE_LINKER_FLAGS=${GSL_EXE_LINKER_FLAGS}")
  125. # ADD_DEFINITIONS("-DHAVE_GSL")
  126. # SET(GSL_DEFINITIONS "-DHAVE_GSL")
  127. MARK_AS_ADVANCED(
  128. GSL_CXX_FLAGS
  129. GSL_INCLUDE_DIR
  130. GSL_LIBRARIES
  131. GSL_LINK_DIRECTORIES
  132. GSL_DEFINITIONS
  133. )
  134. MESSAGE(STATUS "Using GSL from ${GSL_PREFIX}")
  135. ELSE(GSL_CONFIG)
  136. MESSAGE("FindGSL.cmake: gsl-config not found. Please set it manually. GSL_CONFIG=${GSL_CONFIG}")
  137. ENDIF(GSL_CONFIG)
  138. ENDIF(UNIX)
  139. ENDIF(WIN32)
  140. IF(GSL_LIBRARIES)
  141. IF(GSL_INCLUDE_DIR OR GSL_CXX_FLAGS)
  142. SET(GSL_FOUND 1)
  143. ENDIF(GSL_INCLUDE_DIR OR GSL_CXX_FLAGS)
  144. ENDIF(GSL_LIBRARIES)