Skip to content

Commit 0fc2b9d

Browse files
committed
Allow disabling of std::filesystem in CMake.
In particular, disable its usage on MinGW running on not-Windows because the version in Debian Buster has a bug.
1 parent 2a0c991 commit 0fc2b9d

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ option(
5151
"Enable exception handling in the loader. Leave this on unless your standard library is built to not throw."
5252
ON
5353
)
54+
55+
set(BUILD_WITHOUT_STD_FILESYSTEM_DEFAULT OFF)
56+
if(MINGW AND NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Windows")
57+
# Debian 10's MinGW has a bug in the experimental filesystem support
58+
set(BUILD_WITHOUT_STD_FILESYSTEM_DEFAULT ON)
59+
endif()
60+
option(BUILD_WITHOUT_STD_FILESYSTEM "Force building without std::[experimental::]filesystem."
61+
${BUILD_WITHOUT_STD_FILESYSTEM_DEFAULT})
62+
5463
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
5564
option(DYNAMIC_LOADER "Build the loader as a .dll library" OFF)
5665
else()

src/loader/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,18 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
223223
-ffunction-sections
224224
-fdata-sections
225225
)
226+
if(NOT BUILD_WITHOUT_STD_FILESYSTEM)
227+
target_link_libraries(openxr_loader PRIVATE stdc++fs)
228+
endif()
226229
# For GCC version 7.1 or greater, we need to disable the implicit fallthrough warning since
227230
# there's no consistent way to satisfy all compilers until they all accept the C++17 standard
228231
if(CMAKE_COMPILER_IS_GNUCC AND NOT (CMAKE_CXX_COMPILER_VERSION LESS 7.1))
229232
target_compile_options(openxr_loader PRIVATE -Wimplicit-fallthrough=0)
230233
endif()
231234
endif()
235+
if(BUILD_WITHOUT_STD_FILESYSTEM)
236+
target_compile_definitions(openxr_loader PRIVATE DISABLE_STD_FILESYSTEM)
237+
endif()
232238

233239
install(
234240
TARGETS openxr_loader

0 commit comments

Comments
 (0)