我有以下cmake文件:
cmake_minimum_required(VERSION 3.1)
if(UNIX)
set(CMAKE_C_COMPILER "/usr/local/gcc-9.1/bin/gcc-9.1")
set(CMAKE_CXX_COMPILER "/usr/local/gcc-9.1/bin/g++-9.1")
elseif(WIN32)
endif()
project(grab VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
## asio
add_definitions(-DASIO_STANDALONE)
include_directories("../../thirdparty/asio/asio/include")
## fx
include_directories("../")
## json
include_directories("../../thirdparty/json/single_include")
## locates all source files
file(GLOB_RECURSE Sources "src/*.cpp" "src/*.h")
FIND_PACKAGE( Boost 1.70 COMPONENTS program_options system filesystem REQUIRED )
INCLUDE_DIRECTORIES( ${Boost_INCLUDE_DIR} )
message( "Boost_FOUND: ${Boost_FOUND}" )
message( "Boost_INCLUDE_DIR: ${Boost_INCLUDE_DIR}" )
message( "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}" )
message( "Boost_LIBRARIES: ${Boost_LIBRARIES}" )
## creates our executable
add_executable(${PROJECT_NAME} ${Sources})
## linking external libraries
target_link_libraries(${PROJECT_NAME} "-lstdc++fs" ${Boost_LIBRARIES})
结果...
$ cmake ..
-- The CXX compiler identification is GNU 9.1.0
-- Checking whether CXX compiler has -isysroot
-- Checking whether CXX compiler has -isysroot - yes
-- Checking whether CXX compiler supports OSX deployment target flag
-- Checking whether CXX compiler supports OSX deployment target flag - yes
-- Check for working CXX compiler: /usr/local/gcc-9.1/bin/g++-9.1
-- Check for working CXX compiler: /usr/local/gcc-9.1/bin/g++-9.1 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found Boost 1.70.0 at /usr/local/boost-1.70.0/lib/cmake/Boost-1.70.0
-- Requested configuration: QUIET REQUIRED COMPONENTS program_options;system;filesystem
-- Found boost_headers 1.70.0 at /usr/local/boost-1.70.0/lib/cmake/boost_headers-1.70.0
-- Found boost_program_options 1.70.0 at /usr/local/boost-1.70.0/lib/cmake/boost_program_options-1.70.0
-- libboost_program_options.a
-- Adding boost_program_options dependencies: headers
-- Found boost_system 1.70.0 at /usr/local/boost-1.70.0/lib/cmake/boost_system-1.70.0
-- libboost_system.a
-- Adding boost_system dependencies: headers
-- Found boost_filesystem 1.70.0 at /usr/local/boost-1.70.0/lib/cmake/boost_filesystem-1.70.0
-- libboost_filesystem.a
-- Adding boost_filesystem dependencies: headers
-- Boost 1.70 found.
-- Found Boost components:
program_options;system;filesystem
Boost_FOUND: 1
Boost_INCLUDE_DIR:
Boost_INCLUDE_DIRS:
Boost_LIBRARIES:
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/username/Desktop/projects/grab/build
如您所见,cmake能够找到boost,但是并未设置与boost相关的所有变量! Boost_INCLUDE_DIR,Boost_INCLUDE_DIRS,Boost_LIBRARIES都是空的!
我正在使用mac mojave,最新的cmake和Boost 1.7.0