Set minimum version of boost in cmake

2019-06-14 23:30发布

I want to define a minimum boost version to be available on the system. I tried the following approach. Unfortunately this did not work, as it tries to compile also with only boost 1.40.0 available on the system.

SET(Boost_USE_STATIC_LIBS OFF)
SET(Boost_USE_MULTITHREAD OFF)
SET(BOOST_MIN_VERSION "1.47.0")

FIND_PACKAGE(Boost REQUIRED)

FIND_PACKAGE(Boost REQUIRED)
if (NOT Boost_FOUND)
      message(FATAL_ERROR "Fatal error: Boost (version >= 1.47.0) required.\n")
endif (NOT Boost_FOUND)

INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})

How did I get cmake to control the correct boost version, before compiling?

标签: c++ boost cmake
1条回答
我想做一个坏孩纸
2楼-- · 2019-06-14 23:52

Based on this it seems that FIND_PACKAGE ignores SET(BOOST_MIN_VERSION "1.47.0") instead you could use FIND_PACKAGE(Boost 1.47.0 REQUIRED) or slightly nicer FIND_PACKAGE(Boost ${BOOST_MIN_VERSION} REQUIRED)

查看更多
登录 后发表回答