Skip to content

Commit

Permalink
Remove version checks for std::filesystem::path - instead, just check…
Browse files Browse the repository at this point in the history
… that it's actually usable

- rename to `HAS_STD_FILESYSTEM_PATH` for clarity
- centralize WIN32 check
- this was actually failing on windows due to the lack of `/Zc:__cplusplus` - it's not great that CMake only allows specifying flags for `check_cxx_source_compiles()` via CMAKE_CXX_FLAGS though

refs #9
  • Loading branch information
fredemmott committed Mar 25, 2023
1 parent c9474db commit 7b5121e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
16 changes: 11 additions & 5 deletions StreamDeckSDK/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,20 @@ target_link_libraries(
websocketpp
)

# ghc::filesystem only supports UTF-8 locales, which is not common on Windows.
# In lieu of all callers properly using UTF-8 locales, we just require
# std::filesystem.
if ((NOT WIN32) AND HAS_STD_FILESYSTEM)
target_compile_definitions(StreamDeckSDK PUBLIC ESD_HAS_STD_FILESYSTEM)
# Older MacOS SDKs (currently targeting v10.11) claim C++20 support, but do not
# have a usable `std::filesystem`; use a polyfill.
#
# Don't use it everywhere as ghc::filesystem only supports UTF-8 locales,
# which are not common on Windows.
#
# Don't require that callers explicitly convert from the actual locale to UTF-8;
# instead, use `std::filesystem` where available.
if (HAS_STD_FILESYSTEM_PATH)
target_compile_definitions(StreamDeckSDK PUBLIC ESD_HAS_STD_FILESYSTEM_PATH)
else()
target_link_libraries(StreamDeckSDK PUBLIC ghc_filesystem)
endif()

if (NOT MSVC)
target_link_libraries(StreamDeckSDK PUBLIC fmt)
endif()
Expand Down
2 changes: 1 addition & 1 deletion StreamDeckSDK/ESDFilesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
// This source code is licensed under the MIT-style license found in
// the LICENSE file.

#ifndef ESD_HAS_STD_FILESYSTEM
#ifndef ESD_HAS_STD_FILESYSTEM_PATH
#include <ghc/fs_impl.hpp>
#endif
2 changes: 1 addition & 1 deletion StreamDeckSDK/ESDFilesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

/* Use std::filesystem where available, ghc::filesystem otherwise. */

#ifdef ESD_HAS_STD_FILESYSTEM
#ifdef ESD_HAS_STD_FILESYSTEM_PATH
#include <filesystem>
namespace ESD {
namespace filesystem {
Expand Down
28 changes: 15 additions & 13 deletions Vendor/filesystem.cmake
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
include(FetchContent)
include(CheckCXXSourceCompiles)

if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /std:c++20 /Zc:__cplusplus")
endif()

check_cxx_source_compiles("
#ifdef __APPLE__
#include <Availability.h> // for deployment target to support pre-catalina targets without std::fs
#endif
#if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || (defined(__cplusplus) && __cplusplus >= 201703L)) && defined(__has_include)
#if __has_include(<filesystem>) && (!defined(__MAC_OS_X_VERSION_MIN_REQUIRED) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500)
#define GHC_USE_STD_FS
#endif
#endif
#ifndef GHC_USE_STD_FS
#error \"std::filesystem missing or unusable\"
#endif
" HAS_STD_FILESYSTEM)
#include <filesystem>
int main() {
std::filesystem::path path;
return 0;
}
" HAS_STD_FILESYSTEM_PATH)

if(NOT HAS_STD_FILESYSTEM)
if(NOT HAS_STD_FILESYSTEM_PATH)
if(WIN32)
message(FATAL_ERROR "Refusing to use `ghc::filesystem` on Windows due to differing locale behavior")
endif()
FetchContent_Declare(
filesystem
URL https://github.com/gulrak/filesystem/archive/refs/tags/v1.5.12.zip
Expand Down

0 comments on commit 7b5121e

Please sign in to comment.