Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down
45 changes: 45 additions & 0 deletions cmake/FindFilesystem.cmake
Original file line number Diff line number Diff line change
@@ -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 <cstdlib>
#include <filesystem>

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()
1 change: 1 addition & 0 deletions src/Prestage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <XrdOuc/XrdOucEnv.hh>
#include <XrdSys/XrdSysError.hh>

#include <algorithm>
#include <string>
#include <thread>

Expand Down
Loading