From 4fec872feb14897c41c95583c595ac0836d1ba51 Mon Sep 17 00:00:00 2001 From: Olzhas Zhumabek Date: Fri, 10 May 2024 09:36:48 +0200 Subject: [PATCH] feat: Guard boost::filesystem usage (#743) CMake was unopinionated about what filesystem is used and required excessive flag setting. Now it clarifies that boost::filesystem is default and std::filesystem is used in case BOOST_GIL_USE_BOOST_FILESYSTEM is off and CMAKE_CXX_STANDARD>=17. --- CMakeLists.txt | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fd94577e8..dae5c5823 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,8 +60,13 @@ option(BOOST_GIL_ENABLE_EXT_RASTERIZATION "Enable Rasterization extension and te option(BOOST_GIL_ENABLE_EXT_IMAGE_PROCESSING "Enable Image Processing extension (!) and tests" ON) option(BOOST_GIL_USE_CONAN "Use Conan to install dependencies" OFF) option(BOOST_GIL_USE_CLANG_TIDY "Set CMAKE_CXX_CLANG_TIDY property on targets to enable clang-tidy linting" OFF) +option(BOOST_GIL_USE_BOOST_FILESYSTEM "Use boost::filesystem, disabling requires CMAKE_CXX_STANDARD >= 17" ON) set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard version to use (default is 14)") +if (NOT BOOST_GIL_USE_BOOST_FILESYSTEM AND CMAKE_CXX_STANDARD LESS 17) + message(FATAL_ERROR "Using std::filesystem requires CMAKE_CXX_STANDARD >= 17") +endif() + #----------------------------------------------------------------------------- # Project #----------------------------------------------------------------------------- @@ -105,13 +110,20 @@ target_compile_options(gil_compile_options $<$,$>:-fstrict-aliasing> $<$,$>,$>>:-Wall -Wconversion -Wextra -Wfloat-equal -Wshadow -Wsign-promo -Wstrict-aliasing -Wunused-parameter -pedantic>) + +if (BOOST_GIL_USE_BOOST_FILESYSTEM) + set(filesystem_definition "BOOST_GIL_USE_BOOST_FILESYSTEM") +else() + set(filesystem_definition "BOOST_GIL_IO_USE_STD_FILESYSTEM") +endif() target_compile_definitions(gil_compile_options INTERFACE $<$:_CRT_NONSTDC_NO_DEPRECATE> $<$:_SCL_SECURE_NO_DEPRECATE> $<$:_CRT_SECURE_NO_WARNINGS> $<$:NOMINMAX> - $<$:BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE>) + $<$:BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE> + ${filesystem_definition}) #----------------------------------------------------------------------------- # Dependency target @@ -140,12 +152,18 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") set(Boost_USE_STATIC_RUNTIME OFF) endif() -find_package(Boost 1.80.0 REQUIRED COMPONENTS filesystem) +set(Boost_required_components headers) +if (BOOST_GIL_USE_BOOST_FILESYSTEM) + list(APPEND Boost_required_components filesystem) +endif() +find_package(Boost 1.80.0 REQUIRED COMPONENTS ${Boost_required_components}) message(STATUS "Boost.GIL: Using Boost_INCLUDE_DIRS=${Boost_INCLUDE_DIRS}") message(STATUS "Boost.GIL: Using Boost_LIBRARY_DIRS=${Boost_LIBRARY_DIRS}") -target_link_libraries(gil_dependencies INTERFACE Boost::filesystem) - +target_link_libraries(gil_dependencies INTERFACE Boost::headers) +if (BOOST_GIL_USE_BOOST_FILESYSTEM) + target_link_libraries(gil_dependencies INTERFACE Boost::filesystem) +endif() if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") target_link_libraries(gil_dependencies INTERFACE Boost::disable_autolinking) endif()