feat:修正boost高版本问题,不再使用system包

release/4.3a0
邱棚 2025-10-04 12:04:44 +08:00
parent af5d85ae5f
commit f64ebfd4d8
1 changed files with 66 additions and 29 deletions

View File

@ -6,51 +6,88 @@
# Boost_NO_SYSTEM_PATHS: set to true to keep the find script from ignoring BOOST_ROOT
if(MSVC)
# By default, boost only builds static libraries on windows
set(Boost_USE_STATIC_LIBS ON) # only find static libs
# If we ever reset above on windows and, ...
# If we use Boost shared libs, disable auto linking.
# Some libraries, at least Boost Program Options, rely on this to export DLL symbols.
set(Boost_USE_STATIC_LIBS ON)
if(NOT Boost_USE_STATIC_LIBS)
list_append_cache(GTSAM_COMPILE_DEFINITIONS_PUBLIC BOOST_ALL_NO_LIB BOOST_ALL_DYN_LINK)
endif()
# Virtual memory range for PCH exceeded on VS2015
if(MSVC_VERSION LESS 1910) # older than VS2017
if(MSVC_VERSION LESS 1910)
list_append_cache(GTSAM_COMPILE_OPTIONS_PRIVATE -Zm295)
endif()
endif()
# ---- 使 FindBoost CONFIG ----
set(Boost_NO_BOOST_CMAKE ON CACHE BOOL "Use FindBoost module mode" FORCE)
# Store these in variables so they are automatically replicated in GTSAMConfig.cmake and such.
# 线
set(Boost_USE_MULTITHREADED ON)
#
set(BOOST_FIND_MINIMUM_VERSION 1.65)
set(BOOST_FIND_MINIMUM_COMPONENTS serialization system filesystem thread program_options date_time timer chrono regex)
find_package(Boost ${BOOST_FIND_MINIMUM_VERSION} COMPONENTS ${BOOST_FIND_MINIMUM_COMPONENTS} REQUIRED)
# ---- system ----
set(BOOST_FIND_MINIMUM_COMPONENTS
serialization filesystem thread program_options date_time timer chrono regex
)
# Required components
if(NOT Boost_SERIALIZATION_LIBRARY OR NOT Boost_SYSTEM_LIBRARY OR NOT Boost_FILESYSTEM_LIBRARY OR
NOT Boost_THREAD_LIBRARY OR NOT Boost_DATE_TIME_LIBRARY)
message(FATAL_ERROR "Missing required Boost components >= v1.65, please install/upgrade Boost or configure your search paths.")
# Boost (< 1.69) system>=1.69 header-only
# Boost_VERSION find_package
# system system
# Boost_VERSION
# system Boost>=1.69
message(STATUS "Trying Boost without 'system' component first (>=1.69 header-only)...")
set(_boost_try_components ${BOOST_FIND_MINIMUM_COMPONENTS})
set(_boost_found FALSE)
find_package(Boost ${BOOST_FIND_MINIMUM_VERSION} COMPONENTS ${_boost_try_components} QUIET)
if(Boost_FOUND)
set(_boost_found TRUE)
else()
# system Boost<1.69
message(STATUS "Retrying Boost with 'system' component for older Boost (<1.69)...")
list(APPEND _boost_try_components system)
find_package(Boost ${BOOST_FIND_MINIMUM_VERSION} COMPONENTS ${_boost_try_components} REQUIRED)
endif()
#
set(BOOST_FIND_MINIMUM_COMPONENTS ${_boost_try_components})
# ---- Boost_SYSTEM_LIBRARY ----
set(_missing_required FALSE)
foreach(_comp IN LISTS BOOST_FIND_MINIMUM_COMPONENTS)
string(TOUPPER "${_comp}" _COMP_UP)
if(NOT DEFINED "Boost_${_COMP_UP}_LIBRARY" AND NOT TARGET "Boost::${_comp}")
# header-only *_LIBRARY
# header-only system>=1.69
message(STATUS "Note: Boost component '${_comp}' has no explicit *_LIBRARY var; relying on imported target or headers.")
endif()
endforeach()
# ---- ----
option(GTSAM_DISABLE_NEW_TIMERS "Disables using Boost.chrono for timing" OFF)
# Allow for not using the timer libraries on boost < 1.48 (GTSAM timing code falls back to old timer library)
# ---- Boost::system----
set(GTSAM_BOOST_LIBRARIES
Boost::serialization
Boost::system
Boost::filesystem
Boost::thread
Boost::date_time
Boost::regex
)
# chrono/timer
if(TARGET Boost::chrono)
list(APPEND GTSAM_BOOST_LIBRARIES Boost::chrono)
endif()
if(TARGET Boost::timer)
list(APPEND GTSAM_BOOST_LIBRARIES Boost::timer)
endif()
# system Boost Boost::system
if("system" IN_LIST BOOST_FIND_MINIMUM_COMPONENTS AND TARGET Boost::system)
list(APPEND GTSAM_BOOST_LIBRARIES Boost::system)
endif()
if (GTSAM_DISABLE_NEW_TIMERS)
message("WARNING: GTSAM timing instrumentation manually disabled")
list_append_cache(GTSAM_COMPILE_DEFINITIONS_PUBLIC DGTSAM_DISABLE_NEW_TIMERS)
else()
if(Boost_TIMER_LIBRARY)
list(APPEND GTSAM_BOOST_LIBRARIES Boost::timer Boost::chrono)
else()
list(APPEND GTSAM_BOOST_LIBRARIES rt) # When using the header-only boost timer library, need -lrt
message("WARNING: GTSAM timing instrumentation will use the older, less accurate, Boost timer library because boost older than 1.48 was found.")
endif()
endif()