Skip to content
Snippets Groups Projects
Unverified Commit 8740e5a3 authored by thorstenhater's avatar thorstenhater Committed by GitHub
Browse files

Use test programs to enable ``std::filesystem`` (#1392)

* Use CMake check_cxx_source_compiles and check_cxx_source_runs to detect how std::filesystem
is enabled. The probes are executed first, if none succeeds, we use link-only to cover the possibility that we
are cross-compiling.
parent dd432f7c
No related branches found
No related tags found
No related merge requests found
# Compiler-aware compiler options
include(CheckCXXSourceCompiles)
include(CheckCXXSourceRuns)
include(CMakePushCheckState)
# Compiler-aware compiler options
set(CXXOPT_DEBUG "-g")
set(CXXOPT_CXX11 "-std=c++11")
......@@ -18,20 +21,63 @@ if(${ARBDEV_COLOR})
endif()
# A library to collect compiler-specific linking adjustments.
add_library(arbor-compiler-compat INTERFACE)
# TODO Remove when upgrading GCC.
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.1)
target_link_libraries(arbor-compiler-compat INTERFACE stdc++fs)
endif()
endif()
# TODO Remove when upgrading Clang
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
target_link_libraries(arbor-compiler-compat INTERFACE stdc++fs)
cmake_push_check_state()
# Check how to use std::filesystem
string(CONFIGURE [[
#include <cstdio>
#include <filesystem>
int main() {
auto cwd = std::filesystem::current_path();
std::printf("%s %d", cwd.c_str(), std::filesystem::exists(cwd));
}
]] arb_cxx_fs_test @ONLY)
# Remember some state to avoid constant push/pop
set(arb_req_libs ${CMAKE_REQUIRED_LIBRARIES})
# Test whether we can run probes
set(STD_FS_LIB "")
set(CMAKE_REQUIRED_FLAGS -std=c++17 ${CMAKE_REQUIRED_FLAGS})
check_cxx_source_runs("${arb_cxx_fs_test}" STD_FS_PLAIN_RUN)
if(NOT STD_FS_PLAIN_RUN)
set(STD_FS_LIB -lstdc++fs)
set(CMAKE_REQUIRED_LIBRARIES ${arb_req_libs} ${STD_FS_LIB})
check_cxx_source_runs("${arb_cxx_fs_test}" STD_FS_STDCXX_RUN)
if(NOT STD_FS_STDCXX_RUN)
set(STD_FS_LIB -lc++fs)
set(CMAKE_REQUIRED_LIBRARIES ${arb_req_libs} ${STD_FS_LIB})
check_cxx_source_runs("${arb_cxx_fs_test}" STD_FS_CXX_RUN)
# If running is not ok, we are possibly cross-compiling, so check linking as a fallback
if(NOT STD_FS_CXX_RUN)
check_cxx_source_compiles("${arb_cxx_fs_test}" STD_FS_PLAIN_LNK)
if(NOT STD_FS_PLAIN_LNK)
set(STD_FS_LIB -lstdc++fs)
set(CMAKE_REQUIRED_LIBRARIES ${arb_req_libs} ${STD_FS_LIB})
check_cxx_source_compiles("${arb_cxx_fs_test}" STD_FS_STDCXX_LNK)
if(NOT STD_FS_STDCXX_LNK)
set(STD_FS_LIB -lc++fs)
set(CMAKE_REQUIRED_LIBRARIES ${arb_req_libs} ${STD_FS_LIB})
check_cxx_source_compiles("${arb_cxx_fs_test}" STD_FS_CXX_LNK)
if(NOT STD_FS_CXX_LNK)
message(FATAL_ERROR "Could not enable support for std::filesystem")
endif()
endif()
endif()
endif()
endif()
endif()
cmake_pop_check_state()
target_link_libraries(arbor-compiler-compat INTERFACE ${STD_FS_LIB})
install(TARGETS arbor-compiler-compat EXPORT arbor-targets)
# Warning options: disable specific spurious warnings as required.
......
......@@ -75,6 +75,8 @@ function("make_catalogue")
message("Arbor source tree: ${MK_CAT_ARBOR}")
message("Build as standalone: ${MK_CAT_STANDALONE}")
message("Arbor arch: ${ARB_CXXOPT_ARCH}")
message("Arbor cxx compiler: ${ARB_CXX}")
message("Current cxx compiler: ${CMAKE_CXX_COMPILER}")
endif()
file(MAKE_DIRECTORY "${MK_CAT_OUT_DIR}")
......
......@@ -214,7 +214,8 @@ if(${CMAKE_POSITION_INDEPENDENT_CODE})
OUTPUT "CAT_DUMMY_SOURCES"
MECHS dummy
ARBOR "${PROJECT_SOURCE_DIR}"
STANDALONE ON)
STANDALONE ON
VERBOSE ON)
target_compile_definitions(unit PRIVATE USE_DYNAMIC_CATALOGUES)
add_dependencies(unit dummy-catalogue)
endif()
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment