@@ -56,6 +56,7 @@ option(VAL_USE_LIBBACKTRACE_BACKTRACE "enable libbacktrace validation backtrace
56
56
option (UR_ENABLE_ASSERTIONS "Enable assertions for all build types" OFF )
57
57
option (UR_BUILD_XPTI_LIBS "Build the XPTI libraries when tracing is enabled" ON )
58
58
option (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 )
59
60
set (UR_DPCXX "" CACHE FILEPATH "Path of the DPC++ compiler executable" )
60
61
set (UR_DPCXX_BUILD_FLAGS "" CACHE STRING "Build flags to pass to DPC++ when compiling device programs" )
61
62
set (UR_SYCL_LIBRARY_DIR "" CACHE PATH
@@ -94,6 +95,21 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows AND NOT CMAKE_GENERATOR STREQUAL Ninja)
94
95
set (CUSTOM_COMMAND_BINARY_DIR ${CUSTOM_COMMAND_BINARY_DIR} /$<CONFIG> )
95
96
endif ()
96
97
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
+
97
113
if (NOT MSVC )
98
114
# Determine if libstdc++ is being used.
99
115
check_cxx_source_compiles ("
@@ -103,7 +119,7 @@ if(NOT MSVC)
103
119
#endif
104
120
int main() {}"
105
121
USING_LIBSTDCXX )
106
- if (USING_LIBSTDCXX )
122
+ if (UR_FORCE_LIBSTDCXX OR USING_LIBSTDCXX )
107
123
# Support older versions of GCC where the <filesystem> header is not
108
124
# available and <experimental/filesystem> must be used instead. This
109
125
# requires linking against libstdc++fs.a, on systems where <filesystem>
0 commit comments