Skip to content

Commit 7c345e0

Browse files
committed
[ur] Fix linking against libstdc++fs
This patch replaces changes the logic used to specify linking against `libstdc++fs.a` required to use early iterations of `std::filesystem`. Previously CMake checked for the existence of the `<filesystem>` header to enable linking the static library, however in GCC 8 this header exists while still requiring manual linking against the static library. Now we check if we are compiling with `libstdc++` and always manually link against the static library. Fixes oneapi-src#451.
1 parent 2ffa659 commit 7c345e0

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

Diff for: CMakeLists.txt

+14-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.14.0 FATAL_ERROR)
55
project(unified-runtime VERSION 0.6.0)
66

77
include(GNUInstallDirs)
8-
include(CheckIncludeFileCXX)
8+
include(CheckCXXSourceCompiles)
99
include(CMakePackageConfigHelpers)
1010
include(CTest)
1111

@@ -54,11 +54,19 @@ if(NOT MSVC)
5454
if(UR_DEVELOPER_MODE)
5555
add_compile_options(-Werror -fno-omit-frame-pointer)
5656
endif()
57-
# If <filesystem> is not found, e.g. with the libstdc++ from GCC 7.5,
58-
# <experimental/filesystem> will be used instead which requires linking
59-
# libstdc++fs.a to resolve the filesystem symbols.
60-
check_include_file_cxx("filesystem" HAS_INCLUDE_FILESYSTEM)
61-
if(NOT HAS_INCLUDE_FILESYSTEM)
57+
# Determine if libstdc++ is being used.
58+
check_cxx_source_compiles("
59+
#include <array>
60+
#ifndef __GLIBCXX__
61+
#error not using libstdc++
62+
#endif
63+
int main() {}"
64+
USING_LIBSTDCXX)
65+
if(USING_LIBSTDCXX)
66+
# Support older versions of GCC where the <filesystem> header is not
67+
# available and <experimental/filesystem> must be used instead. This
68+
# requires linking against libstdc++fs.a, on systems where <filesystem>
69+
# is available we still need to link this library.
6270
link_libraries(stdc++fs)
6371
endif()
6472
elseif(MSVC)

0 commit comments

Comments
 (0)