diff --git a/CMakeLists.txt b/CMakeLists.txt index d34d755..f1376fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required( VERSION 3.16 ) project( xrdhttp-pelican ) +set( CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ) + find_package( XRootD REQUIRED ) set (CMAKE_CXX_STANDARD 20) @@ -20,6 +22,8 @@ if(NOT APPLE) SET( CMAKE_MODULE_LINKER_FLAGS "-Wl,--no-undefined") endif() +find_package( Filesystem REQUIRED ) + option(ENABLE_TESTS "Enable unit tests" FALSE) if (ENABLE_TESTS) find_package(GTest REQUIRED) @@ -33,7 +37,7 @@ add_subdirectory(tests) include_directories(${XRootD_INCLUDE_DIR}) add_library(XrdHttpPelicanObj OBJECT src/XrdHttpPelican.cc src/Prestage.cc) -target_link_libraries(XrdHttpPelicanObj ${XRootD_HTTP_LIBRARIES} ${XRootD_UTILS_LIBRARIES} Threads::Threads) +target_link_libraries(XrdHttpPelicanObj ${XRootD_HTTP_LIBRARIES} ${XRootD_UTILS_LIBRARIES} Threads::Threads std::filesystem) set_target_properties(XrdHttpPelicanObj PROPERTIES POSITION_INDEPENDENT_CODE ON) # The test executables cannot link against the normal library on Linux as we hide the exported symbols diff --git a/cmake/FindFilesystem.cmake b/cmake/FindFilesystem.cmake new file mode 100644 index 0000000..f759f1e --- /dev/null +++ b/cmake/FindFilesystem.cmake @@ -0,0 +1,45 @@ + +# Ideas come from +# +# https://gitlab.kitware.com/cmake/cmake/-/issues/17834 +# +# Basically, upstream CMake claims the fact that a separate library is +# needed for std::filesystem support is a short-lived fact (of all the +# platforms we use, only RHEL 8 uses a compiler where this is needed), +# hence they don't want a standardized way to detect std::filesystem + +include(CheckSourceCompiles) + +set( CMAKE_REQUIRED_INCLUDES "${XRootD_INCLUDE_DIR}" ) +set( SAMPLE_FILESYSTEM "#include + #include + + int main() { + auto cwd = std::filesystem::current_path(); + return cwd.empty(); + }") + + +CHECK_SOURCE_COMPILES( CXX "${SAMPLE_FILESYSTEM}" CXX_FILESYSTEM_NO_LINK_NEEDED ) + +set( _found FALSE ) +if( CXX_FILESYSTEM_NO_LINK_NEEDED ) + set( _found TRUE ) +else() + # Add the libstdc++ flag + set( CMAKE_REQUIRED_LIBRARIES "-lstdc++fs" ) + CHECK_SOURCE_COMPILES( CXX "${SAMPLE_FILESYSTEM}" CXX_FILESYSTEM_STDCPPFS_NEEDED ) + set( _found TRUE ) +endif() + +add_library( std::filesystem INTERFACE IMPORTED ) +#set_property( TARGET std::filesystem APPEND PROPERTY INTERFACE_COMPILE_FEATURES cxx_std_17 ) + +if( CXX_FILESYSTEM_STDCPPFS_NEEDED ) + set_property( TARGET std::filesystem APPEND PROPERTY INTERFACE_LINK_LIBRARIES -lstdc++fs ) +endif() + +set( Filesystem_FOUND ${_found} CACHE BOOL "TRUE if we can run a program using std::filesystem" FORCE ) +if( Filesystem_FIND_REQUIRED AND NOT Filesystem_FOUND ) + message( FATAL_ERROR "Cannot run simple program using std::filesystem" ) +endif() diff --git a/src/Prestage.cc b/src/Prestage.cc index 9744543..409a54a 100644 --- a/src/Prestage.cc +++ b/src/Prestage.cc @@ -22,6 +22,7 @@ #include #include +#include #include #include