cmake 添加 boost
介绍两种方法,添加boost 依赖
CMakeLists.txt:
FIND_PACKAGE(Boost)
IF (Boost_FOUND)
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIR})
ADD_DEFINITIONS( "-DHAS_BOOST" )
ENDIF()
cmake 会自动设置 BOOST_INCLUDE_DIR, BOOST_LIBRARYDIR 和 BOOST_ROOT
如何boost 不是安装在默认位置,则需要添加路径, 类似path的做法。 且必须放在FIND_PACKAGE 前面
SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "C:/win32libs/boost")
SET(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "C:/win32libs/boost/lib")
或者
set(Boost_ADDITIONAL_VERSIONS "1.55.0" "1.63.0")
# set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
# set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.55.0 REQUIRED system filesystem)
if(Boost_FOUND)
message(STATUS "boost include path is : ${Boost_INCLUDE_DIRS}")
message(STATUS "boost library path is : ${Boost_LIBRARY_DIRS}")
message(STATUS "boost libraries is : ${Boost_LIBRARIES}")
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
else()
message(WARNING "boost not found.")
endif()