]> git.treefish.org Git - phys/heatbath.git/commitdiff
Included cmake FindGSL script.
authorAlexander Schmidt <alex@treefish.org>
Thu, 28 Nov 2013 20:26:56 +0000 (21:26 +0100)
committerAlexander Schmidt <alex@treefish.org>
Thu, 28 Nov 2013 20:26:56 +0000 (21:26 +0100)
CMakeLists.txt
FindGSL.cmake [new file with mode: 0644]

index c07148c14309253ff7d05f802e5220f960987d50..b1bddcb0580376bdfa952db3cdd07357380b2cb5 100644 (file)
@@ -7,6 +7,11 @@ project(heatbath)
 # set(CMAKE_EXE_LINKER_FLAGS -pg)
 # set(CMAKE_SHARED_LINKER_FLAGS -pg)
 
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "./")
+
+FIND_PACKAGE(GSL REQUIRED)
+include_directories(${GSL_INCLUDE_DIRS})
+
 find_package(MPI REQUIRED)
 #set(CMAKE_CXX_COMPILE_FLAGS ${CMAKE_CXX_COMPILE_FLAGS} ${MPI_COMPILE_FLAGS})
 #set(CMAKE_CXX_LINK_FLAGS ${CMAKE_CXX_LINK_FLAGS} ${MPI_LINK_FLAGS})
@@ -18,36 +23,36 @@ add_subdirectory(latlib)
 
 add_executable(heatbath-metro heatbath.cpp)
 set_target_properties(heatbath-metro PROPERTIES COMPILE_DEFINITIONS "ALGORITHM_METRO")
-target_link_libraries(heatbath-metro o815 gsl gslcblas lat_neigh)
+target_link_libraries(heatbath-metro o815 ${GSL_LIBRARIES} lat_neigh)
 
 add_executable(heatbath-AhbMhb heatbath.cpp)
 set_target_properties(heatbath-AhbMhb PROPERTIES COMPILE_DEFINITIONS "ALGORITHM_AHBMHB")
-target_link_libraries(heatbath-AhbMhb o815 gsl gslcblas lat_neigh)
+target_link_libraries(heatbath-AhbMhb o815 ${GSL_LIBRARIES} lat_neigh)
 
 add_executable(heatbath-AhbMor heatbath.cpp)
 set_target_properties(heatbath-AhbMor PROPERTIES COMPILE_DEFINITIONS "ALGORITHM_AHBMOR")
-target_link_libraries(heatbath-AhbMor o815 gsl gslcblas lat_neigh)
+target_link_libraries(heatbath-AhbMor o815 ${GSL_LIBRARIES} lat_neigh)
 
 add_executable(heatbath-AorMhb heatbath.cpp)
 set_target_properties(heatbath-AorMhb PROPERTIES COMPILE_DEFINITIONS "ALGORITHM_AORMHB")
-target_link_libraries(heatbath-AorMhb o815 gsl gslcblas lat_neigh)
+target_link_libraries(heatbath-AorMhb o815 ${GSL_LIBRARIES} lat_neigh)
 
 add_executable(heatbath-AorMor heatbath.cpp)
 set_target_properties(heatbath-AorMor PROPERTIES COMPILE_DEFINITIONS "ALGORITHM_AORMOR")
-target_link_libraries(heatbath-AorMor o815 gsl gslcblas lat_neigh)
+target_link_libraries(heatbath-AorMor o815 ${GSL_LIBRARIES} lat_neigh)
 
 add_executable(heatbath-AorM0 heatbath.cpp)
 set_target_properties(heatbath-AorM0 PROPERTIES COMPILE_DEFINITIONS "ALGORITHM_AORM0")
-target_link_libraries(heatbath-AorM0 o815 gsl gslcblas lat_neigh)
+target_link_libraries(heatbath-AorM0 o815 ${GSL_LIBRARIES} lat_neigh)
 
 add_executable(heatbath-AhbM0 heatbath.cpp)
 set_target_properties(heatbath-AhbM0 PROPERTIES COMPILE_DEFINITIONS "ALGORITHM_AHBM0")
-target_link_libraries(heatbath-AhbM0 o815 gsl gslcblas lat_neigh)
+target_link_libraries(heatbath-AhbM0 o815 ${GSL_LIBRARIES} lat_neigh)
 
 add_executable(heatbath-A0Mor heatbath.cpp)
 set_target_properties(heatbath-A0Mor PROPERTIES COMPILE_DEFINITIONS "ALGORITHM_A0MOR")
-target_link_libraries(heatbath-A0Mor o815 gsl gslcblas lat_neigh)
+target_link_libraries(heatbath-A0Mor o815 ${GSL_LIBRARIES} lat_neigh)
 
 add_executable(heatbath-A0Mhb heatbath.cpp)
 set_target_properties(heatbath-A0Mhb PROPERTIES COMPILE_DEFINITIONS "ALGORITHM_A0MHB")
-target_link_libraries(heatbath-A0Mhb o815 gsl gslcblas lat_neigh)
+target_link_libraries(heatbath-A0Mhb o815 ${GSL_LIBRARIES} lat_neigh)
diff --git a/FindGSL.cmake b/FindGSL.cmake
new file mode 100644 (file)
index 0000000..486be73
--- /dev/null
@@ -0,0 +1,135 @@
+# 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_DIRS - where to find headers
+#  GSL_LIBRARIES - full path to the libraries
+#  GSL_LIBRARY_DIRS, the directory where the PLplot library is found.
+#  CMAKE_GSL_CXX_FLAGS  = Unix compiler flags for GSL, essentially "`gsl-config --cxxflags`"
+#  GSL_LINK_DIRECTORIES = link directories, useful for rpath on Unix
+#  GSL_EXE_LINKER_FLAGS = rpath on Unix
+set( GSL_FOUND OFF )
+set( GSL_CBLAS_FOUND OFF )
+# 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
+    )
+  if( GSL_INCLUDE_DIR )
+    # look for gsl library
+    find_library( GSL_LIBRARY
+      NAMES gsl
+    ) 
+    if( GSL_LIBRARY )
+      set( GSL_INCLUDE_DIRS ${GSL_INCLUDE_DIR} )
+      get_filename_component( GSL_LIBRARY_DIRS ${GSL_LIBRARY} PATH )
+      set( GSL_FOUND ON )
+    endif( GSL_LIBRARY )
+    # look for gsl cblas library
+    find_library( GSL_CBLAS_LIBRARY
+        NAMES gslcblas
+      )
+    if( GSL_CBLAS_LIBRARY )
+      set( GSL_CBLAS_FOUND ON )
+    endif( GSL_CBLAS_LIBRARY )
+       
+    set( GSL_LIBRARIES ${GSL_LIBRARY} ${GSL_CBLAS_LIBRARY} )
+  endif( GSL_INCLUDE_DIR )
+   
+  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
+      /usr/bin/
+      /usr/local/bin
+    )
+     
+    if( GSL_CONFIG_EXECUTABLE )
+      set( GSL_FOUND ON )
+       
+      # 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 MATCHALL "-I[^;]+"
+          GSL_INCLUDE_DIRS "${GSL_CFLAGS}" )
+        string( REPLACE "-I" ""
+          GSL_INCLUDE_DIRS "${GSL_INCLUDE_DIRS}")
+        string( REGEX REPLACE "-I[^;]+;" ""
+          GSL_CFLAGS "${GSL_CFLAGS}")
+        message("GSL_DEFINITIONS=${GSL_DEFINITIONS}")
+        message("GSL_INCLUDE_DIRS=${GSL_INCLUDE_DIRS}")
+        message("GSL_CFLAGS=${GSL_CFLAGS}")
+      else( RET EQUAL 0 )
+        set( GSL_FOUND FALSE )
+      endif( RET EQUAL 0 )
+      # 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 MATCHALL "-L[^;]+"
+          GSL_LIBRARY_DIRS "${GSL_LIBRARIES}" )
+        string( REPLACE "-L" ""
+          GSL_LIBRARY_DIRS "${GSL_LIBRARY_DIRS}" )
+      else( RET EQUAL 0 )
+        set( GSL_FOUND FALSE )
+      endif( RET EQUAL 0 )
+       
+      MARK_AS_ADVANCED(
+        GSL_CFLAGS
+      )
+      message( STATUS "Using GSL from ${GSL_PREFIX}" )
+    else( GSL_CONFIG_EXECUTABLE )
+      message( STATUS "FindGSL: gsl-config not found.")
+    endif( GSL_CONFIG_EXECUTABLE )
+  endif( UNIX OR MSYS )
+endif( WIN32 AND NOT CYGWIN AND NOT MSYS )
+if( GSL_FOUND )
+  if( NOT GSL_FIND_QUIETLY )
+    message( STATUS "FindGSL: Found both GSL headers and library" )
+  endif( NOT GSL_FIND_QUIETLY )
+else( GSL_FOUND )
+  if( GSL_FIND_REQUIRED )
+    message( FATAL_ERROR "FindGSL: Could not find GSL headers or library" )
+  endif( GSL_FIND_REQUIRED )
+endif( GSL_FOUND )