{"id":233,"date":"2010-06-21T22:27:19","date_gmt":"2010-06-21T21:27:19","guid":{"rendered":"http:\/\/www.miscdebris.net\/blog\/?p=233"},"modified":"2010-06-21T22:28:40","modified_gmt":"2010-06-21T21:28:40","slug":"cmake-module-to-find-gnu-scientific-library-findgsl-cmake","status":"publish","type":"post","link":"https:\/\/www.miscdebris.net\/blog\/2010\/06\/21\/cmake-module-to-find-gnu-scientific-library-findgsl-cmake\/","title":{"rendered":"cmake module to find Gnu Scientific Library, FindGSL.cmake"},"content":{"rendered":"<p>There is no official FindGSL.cmake module in the cmake distribution to &#8220;automagically&#8221; find the Gnu Scientific Library on Windows, Linux and Mac OS X. I have written such a module which works for my configurations, but might not cover all GSL installation on all OS. But you can modify it to fit your needs.<\/p>\n<p><!--more--><\/p>\n<p>Anyway, below you&#8217;ll find the source code of my FindGSL.cmake module.<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n# Try to find gnu scientific library GSL\r\n# See \r\n# http:\/\/www.gnu.org\/software\/gsl\/  and \r\n# http:\/\/gnuwin32.sourceforge.net\/packages\/gsl.htm\r\n#\r\n# Based on a script of Felix Woelk and Jan Woetzel\r\n# (www.mip.informatik.uni-kiel.de)\r\n# \r\n# It defines the following variables:\r\n#  GSL_FOUND - system has GSL lib\r\n#  GSL_INCLUDE_DIRS - where to find headers \r\n#  GSL_LIBRARIES - full path to the libraries\r\n#  GSL_LIBRARY_DIRS, the directory where the PLplot library is found.\r\n\r\n#  CMAKE_GSL_CXX_FLAGS  = Unix compiler flags for GSL, essentially &quot;`gsl-config --cxxflags`&quot;\r\n#  GSL_LINK_DIRECTORIES = link directories, useful for rpath on Unix\r\n#  GSL_EXE_LINKER_FLAGS = rpath on Unix\r\n\r\nset( GSL_FOUND OFF )\r\nset( GSL_CBLAS_FOUND OFF )\r\n\r\n# Windows, but not for Cygwin and MSys where gsl-config is available\r\nif( WIN32 AND NOT CYGWIN AND NOT MSYS )\r\n\t# look for headers\r\n  find_path( GSL_INCLUDE_DIR\r\n    NAMES gsl\/gsl_cdf.h gsl\/gsl_randist.h\r\n    )\r\n  if( GSL_INCLUDE_DIR )\r\n  \t# look for gsl library\r\n    find_library( GSL_LIBRARY\r\n      NAMES gsl \r\n    )  \r\n    if( GSL_LIBRARY )\r\n      set( GSL_INCLUDE_DIRS ${GSL_INCLUDE_DIR} )\r\n      get_filename_component( GSL_LIBRARY_DIRS ${GSL_LIBRARY} PATH )\r\n      set( GSL_FOUND ON )\r\n    endif( GSL_LIBRARY )\r\n\r\n\t\t# look for gsl cblas library\r\n    find_library( GSL_CBLAS_LIBRARY\r\n        NAMES gslcblas \r\n      )\r\n    if( GSL_CBLAS_LIBRARY )\r\n      set( GSL_CBLAS_FOUND ON )\r\n    endif( GSL_CBLAS_LIBRARY )\r\n      \r\n    set( GSL_LIBRARIES ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY} )\r\n  endif( GSL_INCLUDE_DIR )\r\n  \r\n  mark_as_advanced(\r\n    GSL_INCLUDE_DIR\r\n    GSL_LIBRARY\r\n    GSL_CBLAS_LIBRARY\r\n  )\r\nelse( WIN32 AND NOT CYGWIN AND NOT MSYS )\r\n  if( UNIX OR MSYS )\r\n\t\tfind_program( GSL_CONFIG_EXECUTABLE gsl-config\r\n\t\t\t\/usr\/bin\/\r\n\t\t\t\/usr\/local\/bin\r\n\t\t)\r\n\t\t\r\n\t\tif( GSL_CONFIG_EXECUTABLE ) \r\n\t\t\tset( GSL_FOUND ON )\r\n\t\t\t\r\n      # run the gsl-config program to get cxxflags\r\n      execute_process(\r\n        COMMAND sh &quot;${GSL_CONFIG_EXECUTABLE}&quot; --cflags\r\n        OUTPUT_VARIABLE GSL_CFLAGS\r\n        RESULT_VARIABLE RET\r\n        ERROR_QUIET\r\n        )\r\n      if( RET EQUAL 0 )\r\n        string( STRIP &quot;${GSL_CFLAGS}&quot; GSL_CFLAGS )\r\n        separate_arguments( GSL_CFLAGS )\r\n\r\n        # parse definitions from cflags; drop -D* from CFLAGS\r\n        string( REGEX MATCHALL &quot;-D&#x5B;^;]+&quot;\r\n          GSL_DEFINITIONS  &quot;${GSL_CFLAGS}&quot; )\r\n        string( REGEX REPLACE &quot;-D&#x5B;^;]+;&quot; &quot;&quot;\r\n          GSL_CFLAGS &quot;${GSL_CFLAGS}&quot; )\r\n\r\n        # parse include dirs from cflags; drop -I prefix\r\n        string( REGEX MATCHALL &quot;-I&#x5B;^;]+&quot;\r\n          GSL_INCLUDE_DIRS &quot;${GSL_CFLAGS}&quot; )\r\n        string( REPLACE &quot;-I&quot; &quot;&quot;\r\n          GSL_INCLUDE_DIRS &quot;${GSL_INCLUDE_DIRS}&quot;)\r\n        string( REGEX REPLACE &quot;-I&#x5B;^;]+;&quot; &quot;&quot;\r\n          GSL_CFLAGS &quot;${GSL_CFLAGS}&quot;)\r\n\r\n        message(&quot;GSL_DEFINITIONS=${GSL_DEFINITIONS}&quot;)\r\n        message(&quot;GSL_INCLUDE_DIRS=${GSL_INCLUDE_DIRS}&quot;)\r\n        message(&quot;GSL_CFLAGS=${GSL_CFLAGS}&quot;)\r\n      else( RET EQUAL 0 )\r\n        set( GSL_FOUND FALSE )\r\n      endif( RET EQUAL 0 )\r\n\r\n      # run the gsl-config program to get the libs\r\n      execute_process(\r\n        COMMAND sh &quot;${GSL_CONFIG_EXECUTABLE}&quot; --libs\r\n        OUTPUT_VARIABLE GSL_LIBRARIES\r\n        RESULT_VARIABLE RET\r\n        ERROR_QUIET\r\n        )\r\n      if( RET EQUAL 0 )\r\n        string(STRIP &quot;${GSL_LIBRARIES}&quot; GSL_LIBRARIES )\r\n        separate_arguments( GSL_LIBRARIES )\r\n\r\n        # extract linkdirs (-L) for rpath (i.e., LINK_DIRECTORIES)\r\n        string( REGEX MATCHALL &quot;-L&#x5B;^;]+&quot;\r\n          GSL_LIBRARY_DIRS &quot;${GSL_LIBRARIES}&quot; )\r\n        string( REPLACE &quot;-L&quot; &quot;&quot;\r\n          GSL_LIBRARY_DIRS &quot;${GSL_LIBRARY_DIRS}&quot; )\r\n      else( RET EQUAL 0 )\r\n        set( GSL_FOUND FALSE )\r\n      endif( RET EQUAL 0 )\r\n\t\t\t\r\n\t\t\tMARK_AS_ADVANCED(\r\n\t\t\t\tGSL_CFLAGS\r\n\t\t\t)\r\n\t\t\tmessage( STATUS &quot;Using GSL from ${GSL_PREFIX}&quot; )\r\n\t\telse( GSL_CONFIG_EXECUTABLE )\r\n\t\t\tmessage( STATUS &quot;FindGSL: gsl-config not found.&quot;)\r\n\t\tendif( GSL_CONFIG_EXECUTABLE )\r\n\tendif( UNIX OR MSYS )\r\nendif( WIN32 AND NOT CYGWIN AND NOT MSYS )\r\n\r\nif( GSL_FOUND )\r\n  if( NOT GSL_FIND_QUIETLY )\r\n    message( STATUS &quot;FindGSL: Found both GSL headers and library&quot; )\r\n  endif( NOT GSL_FIND_QUIETLY )\r\nelse( GSL_FOUND )\r\n  if( GSL_FIND_REQUIRED )\r\n    message( FATAL_ERROR &quot;FindGSL: Could not find GSL headers or library&quot; )\r\n  endif( GSL_FIND_REQUIRED )\r\nendif( GSL_FOUND )\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>There is no official FindGSL.cmake module in the cmake distribution to &#8220;automagically&#8221; find the Gnu Scientific Library on Windows, Linux and Mac OS X. I have written such a module which works for my configurations, but might not cover all GSL installation on all OS. But you can modify it to fit your needs.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[30,9,10,24],"tags":[33,25],"class_list":["post-233","post","type-post","status-publish","format-standard","hentry","category-development","category-linux","category-macosx","category-windows","tag-cmake","tag-gsl"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p6pnj-3L","_links":{"self":[{"href":"https:\/\/www.miscdebris.net\/blog\/wp-json\/wp\/v2\/posts\/233"}],"collection":[{"href":"https:\/\/www.miscdebris.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.miscdebris.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.miscdebris.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.miscdebris.net\/blog\/wp-json\/wp\/v2\/comments?post=233"}],"version-history":[{"count":6,"href":"https:\/\/www.miscdebris.net\/blog\/wp-json\/wp\/v2\/posts\/233\/revisions"}],"predecessor-version":[{"id":250,"href":"https:\/\/www.miscdebris.net\/blog\/wp-json\/wp\/v2\/posts\/233\/revisions\/250"}],"wp:attachment":[{"href":"https:\/\/www.miscdebris.net\/blog\/wp-json\/wp\/v2\/media?parent=233"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.miscdebris.net\/blog\/wp-json\/wp\/v2\/categories?post=233"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.miscdebris.net\/blog\/wp-json\/wp\/v2\/tags?post=233"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}