# ADD_DEFINITIONS("-DHAVE_GSL")
# SET(GSL_DEFINITIONS "-DHAVE_GSL")
MARK_AS_ADVANCED(
GSL_CXX_FLAGS
GSL_INCLUDE_DIR
GSL_LIBRARIES
GSL_LINK_DIRECTORIES
GSL_DEFINITIONS
)
MESSAGE(STATUS "Using GSL from ${GSL_PREFIX}")
ELSE(GSL_CONFIG)
INCLUDE(UsePkgConfig) #needed for PKGCONFIG(...)
MESSAGE(STATUS "GSL using pkgconfig")
# PKGCONFIG(gsl includedir libdir linkflags cflags)
PKGCONFIG(gsl GSL_INCLUDE_DIR GSL_LINK_DIRECTORIES GSL_LIBRARIES GSL_CXX_FLAGS)
IF(GSL_INCLUDE_DIR)
MARK_AS_ADVANCED(
GSL_CXX_FLAGS
GSL_INCLUDE_DIR
GSL_LIBRARIES
GSL_LINK_DIRECTORIES
)
ELSE(GSL_INCLUDE_DIR)
MESSAGE("FindGSL.cmake: gsl-config/pkg-config gsl not found. Please set it manually. GSL_CONFIG=${GSL_CONFIG}")
ENDIF(GSL_INCLUDE_DIR)
ENDIF(GSL_CONFIG)
ENDIF(UNIX)
ENDIF(WIN32)
IF(GSL_LIBRARIES)
IF(GSL_INCLUDE_DIR OR GSL_CXX_FLAGS)
SET(GSL_FOUND 1)
ENDIF(GSL_INCLUDE_DIR OR GSL_CXX_FLAGS)
ENDIF(GSL_LIBRARIES)
# ==========================================
IF(NOT GSL_FOUND)
# make FIND_PACKAGE friendly
IF(NOT GSL_FIND_QUIETLY)
IF(GSL_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "GSL required, please specify it's location.")
ELSE(GSL_FIND_REQUIRED)
MESSAGE(STATUS "ERROR: GSL was not found.")
ENDIF(GSL_FIND_REQUIRED)
ENDIF(NOT GSL_FIND_QUIETLY)
ENDIF(NOT GSL_FOUND)
-----------------------------------------------------------------------------------------
3. 准备工作做完,下面开始创建我们自己的程序。
创建hello.c
-----------------------------------------------
#include
#include
int main (void)
{
double x = 5.0;
double y = gsl_sf_bessel_J0 (x);
printf ("J0(%g) = %.18e\n", x, y);
return 0;
}
-----------------------------------------------
创建CMakeLists.txt
-----------------------------------------------------
cmake_minimum_required (VERSION 2.8)
project(hello)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}")
find_package(GSL REQUIRED)
include_directories(${GSL_INCLUDE_DIRES} ${GSLCBLAS_INCLUDE_DIRS})
link_libraries(${GSL_LIBRARIES} ${GSLBLAS_LIBRARIES})
target_link_libraries (${GSL_LIBRARIES} ${GSLBLAS_LIBRARIES})
add_executable(hello hello.c)
-----------------------------------------------------
cmake . && make
就会产生可执行文件 “hello”