@@ -56,6 +56,7 @@ option(VAL_USE_LIBBACKTRACE_BACKTRACE "enable libbacktrace validation backtrace
5656option (UR_ENABLE_ASSERTIONS "Enable assertions for all build types" OFF )
5757option (UR_BUILD_XPTI_LIBS "Build the XPTI libraries when tracing is enabled" ON )
5858option (UR_STATIC_LOADER "Build loader as a static library" OFF )
59+ option (UR_FORCE_LIBSTDCXX "Force use of libstdc++ in a build using libc++ on Linux" OFF )
5960set (UR_DPCXX "" CACHE FILEPATH "Path of the DPC++ compiler executable" )
6061set (UR_DPCXX_BUILD_FLAGS "" CACHE STRING "Build flags to pass to DPC++ when compiling device programs" )
6162set (UR_SYCL_LIBRARY_DIR "" CACHE PATH
@@ -94,6 +95,21 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_GENERATOR STREQUAL Ninja)
9495 set (CUSTOM_COMMAND_BINARY_DIR ${CUSTOM_COMMAND_BINARY_DIR} /$<CONFIG>)
9596endif ()
9697
98+ if (UR_FORCE_LIBSTDCXX AND CMAKE_SYSTEM_NAME STREQUAL Linux)
99+ # Remove flags to specify using libc++ or static libstdc++ in order to
100+ # support sitatuions where the libstdc++ ABI is required.
101+ foreach (flags CMAKE_CXX_FLAGS CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS)
102+ string (REPLACE "-stdlib=libc++" "" ${flags} "${${flags} }" )
103+ string (REPLACE "-static-libstdc++" "" ${flags} "${${flags} }" )
104+ endforeach ()
105+ # Globally link against pthread, this is necessary when forcing use of
106+ # libstdc++ in a libc++ build as the FindThreads module may have already
107+ # been invoked and detected that pthread symbols are provided by libc++
108+ # which is not the case for libstdc++.
109+ add_compile_options (-pthread)
110+ link_libraries (pthread)
111+ endif ()
112+
97113if (NOT MSVC )
98114 # Determine if libstdc++ is being used.
99115 check_cxx_source_compiles("
@@ -103,7 +119,7 @@ if(NOT MSVC)
103119 #endif
104120 int main() {}"
105121 USING_LIBSTDCXX)
106- if (USING_LIBSTDCXX)
122+ if (UR_FORCE_LIBSTDCXX OR USING_LIBSTDCXX)
107123 # Support older versions of GCC where the <filesystem> header is not
108124 # available and <experimental/filesystem> must be used instead. This
109125 # requires linking against libstdc++fs.a, on systems where <filesystem>
0 commit comments