Skip to content

cmake fails to find Boost::system when cmake_minimum_required(VERSION 3.16) is used

This script fails to find boost-libs-1.88.0:

cmake_minimum_required(VERSION 3.16)

find_package(Boost REQUIRED COMPONENTS system program_options iostreams)


if(TARGET Boost::system)
    message(STATUS "Target 'Boost::system' exists.")
else()
    message(STATUS "Target 'Boost::system' does not exist.")
endif()

It prints:

-- Found Boost: /usr/local/include (found version "1.88.0") found components: program_options iostreams regex
-- Target 'Boost::system' does not exist.

The script with a newer cmake version requirement succeeds:

cmake_minimum_required(VERSION 3.31)

find_package(Boost REQUIRED COMPONENTS system program_options iostreams)


if(TARGET Boost::system)
    message(STATUS "Target 'Boost::system' exists.")
else()
    message(STATUS "Target 'Boost::system' does not exist.")
endif()

It only prints:

-- Target 'Boost::system' exists.

Please note that he first script prints that it found the boost's "regex" module when this module wasn't requested.

Version: cmake-core-3.31.7_1 FreeBSD 14.3

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information