Skip to content

Commit a25fc21

Browse files
authored
Merge pull request #1926 from oneapi-src/benie/force-libstdc++
Add option to force use of libstdc++ on Linux
2 parents 65b4922 + ae594ba commit a25fc21

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

CMakeLists.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ option(VAL_USE_LIBBACKTRACE_BACKTRACE "enable libbacktrace validation backtrace
5656
option(UR_ENABLE_ASSERTIONS "Enable assertions for all build types" OFF)
5757
option(UR_BUILD_XPTI_LIBS "Build the XPTI libraries when tracing is enabled" ON)
5858
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)
5960
set(UR_DPCXX "" CACHE FILEPATH "Path of the DPC++ compiler executable")
6061
set(UR_DPCXX_BUILD_FLAGS "" CACHE STRING "Build flags to pass to DPC++ when compiling device programs")
6162
set(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>)
9596
endif()
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+
97113
if(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

Comments
 (0)