我正在尝试使用CheckIncludeFileCXX
模块来验证系统中存在<gsl/gsl>
。GSL存在于/usr/local/include/gsl/gsl
,但生成失败在"GSL not found"
project(cpp-binaries)
cmake_minimum_required(VERSION 3.2)
include(CheckIncludeFileCXX)
CHECK_INCLUDE_FILE_CXX("gsl/gsl" GSL_LIBRARY)
if(NOT GSL_LIBRARY)
message(FATAL_ERROR "GSL not found")
endif(NOT GSL_LIBRARY)
add_executable(
cpp-binaries
"main.cpp"
)
好吧,我更多地研究了CheckIncludeFileCXX
,您基本上必须用CMAKE_REQUIRED_INCLUDES
指定一些内容,否则它不知道在哪里搜索。为了给它一些东西,它会悄悄地搜索包含find_path
的包含,但如果什么也找不到。
project(gsl_t)
cmake_minimum_required(VERSION 3.2)
find_path(
gsl_location
gsl
HINTS ENV GSLDIR
)
if(gsl_location)
get_filename_component(gsl_include_dir ${gsl_location} DIRECTORY)
list(APPEND CMAKE_INCLUDE_PATH ${gsl_include_dir})
endif(gsl_location)
include(CheckIncludeFileCXX)
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_INCLUDE_PATH})
CHECK_INCLUDE_FILE_CXX("gsl/gsl" gsl_found)
if(NOT gsl_found)
message(FATAL_ERROR "GSL not found.
Try setting the GSLDIR environment variable")
endif(NOT gsl_found)
add_executable(
gsl_t
"main.cpp"
)