From b8d24365f69863e2afd8ba6ee1486a0257550403 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Wed, 31 Dec 2025 11:36:59 +0100 Subject: [PATCH] Modernize Boost module finding for CMake 3.30+ Add CMP0167 policy to suppress FindBoost deprecation warning on CMake 3.30+ Use modern Boost imported targets (Boost::iostreams, Boost::thread, Boost::unit_test_framework) when available (CMAKE_VERSION >= 3.30) Fallback to old-style variables for CMake 3.28. Split target_link_libraries calls: Boost libraries + non-Boost libraries. "include_directories" for Boost handled in root CMakeLists.txt. Fixes: CMake warning about deprecated FindBoost module on CMake 3.30+: ******************************************* CMake Warning (dev) at CMakeLists.txt:137 (find_package): Policy CMP0167 is not set: The FindBoost module is removed. Run "cmake --help-policy CMP0167" for policy details. Use the cmake_policy command to set the policy and suppress this warning. ******************************************* --- CMakeLists.txt | 15 +++++++++++++-- src/CMakeLists.txt | 13 +++++++------ test/CMakeLists.txt | 13 +++++++------ 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 308f85e..07f53fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,12 @@ cmake_minimum_required(VERSION 3.28 FATAL_ERROR) +# Modern Boost integration (CMake 3.30+) +# Use CMake's built-in Boost support instead of deprecated FindBoost module +# For CMake < 3.30, keep old behavior to avoid errors +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.30) + cmake_policy(SET CMP0167 NEW) +endif() + # Project project(libi2ncommon) @@ -134,8 +141,12 @@ endif(IMAP_UTF7_SUPPORT) include(FindPkgConfig) # Find Boost -find_package(Boost 1.44 COMPONENTS iostreams unit_test_framework thread REQUIRED) -include_directories(${Boost_INCLUDE_DIRS}) +find_package(Boost 1.44 REQUIRED COMPONENTS iostreams unit_test_framework thread) + +# CMake 3.28 compatibility: imported targets only available in CMake 3.30+ +if(CMAKE_VERSION VERSION_LESS 3.30) + include_directories(${Boost_INCLUDE_DIRS}) +endif() # Find pcrecpp pkg_check_modules(PCRECPP REQUIRED libpcrecpp) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 881dd88..43fa40a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -62,12 +62,13 @@ SET(cpp_headers add_library(i2ncommon SHARED ${cpp_sources} ${cpp_headers}) -target_link_libraries(i2ncommon - ${Boost_IOSTREAMS_LIBRARIES} - ${Boost_THREAD_LIBRARIES} - ${ICONV_LIBRARIES} - ${OPENSSL_LIBRARIES} - ${PCRECPP_LIBRARIES}) +# CMake 3.30+ provides modern imported targets, CMake 3.28 uses old-style variables +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.30) + target_link_libraries(i2ncommon Boost::iostreams Boost::thread) +else() + target_link_libraries(i2ncommon ${Boost_IOSTREAMS_LIBRARIES} ${Boost_THREAD_LIBRARIES}) +endif() +target_link_libraries(i2ncommon ${ICONV_LIBRARIES} ${OPENSSL_LIBRARIES} ${PCRECPP_LIBRARIES}) set_target_properties(i2ncommon PROPERTIES VERSION ${VERSION} SOVERSION 8) set_target_properties(i2ncommon PROPERTIES OUTPUT_NAME i2ncommon CLEAN_DIRECT_OUTPUT 1) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6694bff..673a4e3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -36,9 +36,10 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} DEPENDS test_i2ncommon) enable_testing() add_test(test_i2ncommon test_i2ncommon) -target_link_libraries(test_i2ncommon - i2ncommon - i2ncommon_utils - i2ncommon_config - ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES} -) +# CMake 3.30+ provides modern imported targets, CMake 3.28 uses old-style variables +if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.30) + target_link_libraries(test_i2ncommon Boost::unit_test_framework) +else() + target_link_libraries(test_i2ncommon ${Boost_UNIT_TEST_FRAMEWORK_LIBRARIES}) +endif() +target_link_libraries(test_i2ncommon i2ncommon i2ncommon_utils i2ncommon_config) -- 1.7.1