blob: ed06760f25d6e6f7be0666e3a6956ac96124cd82 [file] [log] [blame]
James E. King IIIc9ac8d22019-01-07 16:46:45 -05001#
2# Licensed to the Apache Software Foundation (ASF) under one
3# or more contributor license agreements. See the NOTICE file
4# distributed with this work for additional information
5# regarding copyright ownership. The ASF licenses this file
6# to you under the Apache License, Version 2.0 (the
7# "License"); you may not use this file except in compliance
8# with the License. You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing,
13# software distributed under the License is distributed on an
14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15# KIND, either express or implied. See the License for the
16# specific language governing permissions and limitations
17# under the License.
18#
19
Dmytro Shteflyuk6d04f122025-11-30 10:14:54 -050020# CMake 4.0+ removed the FindBoost module (CMP0167). Use OLD behavior to
21# preserve compatibility with existing ${Boost_LIBRARIES} usage.
22if(POLICY CMP0167)
23 cmake_policy(SET CMP0167 OLD)
24endif()
25
Gregg Donovan62ec9292026-01-29 16:51:37 -050026# CMake 3.27+ warns and ignores upper-case <PACKAGENAME>_ROOT variables unless
27# CMP0144 is set. We pass BOOST_ROOT on Windows builds, so enable NEW behavior.
28if(POLICY CMP0144)
29 cmake_policy(SET CMP0144 NEW)
30endif()
31
Dmytro Shteflyuk6d04f122025-11-30 10:14:54 -050032# Force using FindBoost instead of Boost's own BoostConfig.cmake.
33# BoostConfig.cmake does not populate ${Boost_LIBRARIES} the same way,
34# which causes linking failures on Windows.
35set(Boost_NO_BOOST_CMAKE ON)
36
James E. King IIIee8caca2019-05-04 08:20:59 -040037set(BOOST_MINREV 1.56)
James E. King IIIc9ac8d22019-01-07 16:46:45 -050038
39macro(REQUIRE_BOOST_HEADERS)
40 find_package(Boost ${BOOST_MINREV} QUIET REQUIRED)
41 if (NOT Boost_FOUND)
Mario Emmenlauer464339d2021-08-02 21:55:57 +020042 message(FATAL_ERROR "Boost ${BOOST_MINREV} or later is required to build sources in ${CMAKE_CURRENT_SOURCE_DIR}")
James E. King IIIc9ac8d22019-01-07 16:46:45 -050043 endif()
James E. King III9ecdce32019-05-03 11:24:55 -040044 if (DEFINED Boost_INCLUDE_DIRS)
45 # pre-boost 1.70.0 aware cmake, otherwise it is using targets
46 include_directories(SYSTEM "${Boost_INCLUDE_DIRS}")
47 endif()
James E. King IIIc9ac8d22019-01-07 16:46:45 -050048endmacro()
49
50macro(REQUIRE_BOOST_LIBRARIES libs)
51 message(STATUS "Locating boost libraries required by sources in ${CMAKE_CURRENT_SOURCE_DIR}")
52 find_package(Boost ${BOOST_MINREV} REQUIRED COMPONENTS ${${libs}})
53 if (NOT Boost_FOUND)
Mario Emmenlauer464339d2021-08-02 21:55:57 +020054 message(FATAL_ERROR "Boost ${BOOST_MINREV} or later is required to build sources in ${CMAKE_CURRENT_SOURCE_DIR}, or use -DBUILD_TESTING=OFF")
James E. King IIIc9ac8d22019-01-07 16:46:45 -050055 endif()
56endmacro()