Skip to content

Commit

Permalink
Guard boost::filesystem usage
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
simmplecoder committed Apr 12, 2024
1 parent 322c4e2 commit 248c412
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -105,13 +110,20 @@ target_compile_options(gil_compile_options
$<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-fstrict-aliasing>
$<$<AND:$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>,$<NOT:$<BOOL:${BOOST_GIL_BUILD_CI}>>>:-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
$<$<CXX_COMPILER_ID:MSVC>:_CRT_NONSTDC_NO_DEPRECATE>
$<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_DEPRECATE>
$<$<CXX_COMPILER_ID:MSVC>:_CRT_SECURE_NO_WARNINGS>
$<$<CXX_COMPILER_ID:MSVC>:NOMINMAX>
$<$<CXX_COMPILER_ID:MSVC>:BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE>)
$<$<CXX_COMPILER_ID:MSVC>:BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE>
${filesystem_definition})

#-----------------------------------------------------------------------------
# Dependency target
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 248c412

Please sign in to comment.