From a7a80571ea304f1fa9baeb89f5a17194593b9853 Mon Sep 17 00:00:00 2001 From: Jordon Brooks Date: Thu, 6 Jun 2024 19:20:29 +0100 Subject: [PATCH] Remove stdc++fs requirement by using an external library --- .gitattributes | 5 +- HarmonyLinkLib/CMakeLists.txt | 78 +++++++++++-------- HarmonyLinkLib/src/Platform/WineUtilities.cpp | 6 +- 3 files changed, 55 insertions(+), 34 deletions(-) diff --git a/.gitattributes b/.gitattributes index 970e13f..92bbb8f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -36,4 +36,7 @@ # Executables *.exe binary *.out binary -*.app binary \ No newline at end of file +*.app binary + +# Linux shell files must always be LF +*.sh text eol=lf \ No newline at end of file diff --git a/HarmonyLinkLib/CMakeLists.txt b/HarmonyLinkLib/CMakeLists.txt index 2e2ed12..311eed3 100644 --- a/HarmonyLinkLib/CMakeLists.txt +++ b/HarmonyLinkLib/CMakeLists.txt @@ -28,6 +28,18 @@ FetchContent_MakeAvailable(fmt) set_target_properties(fmt PROPERTIES FOLDER External) set_target_properties(fmt PROPERTIES POSITION_INDEPENDENT_CODE TRUE) +# Fetch ghc library +FetchContent_Declare( + ghc_filesystem + GIT_REPOSITORY https://github.com/gulrak/filesystem.git + GIT_TAG v1.5.14 # Specify the desired version of ghc +) + +FetchContent_MakeAvailable(ghc_filesystem) + +set_target_properties(ghc_filesystem PROPERTIES FOLDER External) +set_target_properties(ghc_filesystem PROPERTIES POSITION_INDEPENDENT_CODE TRUE) + # Find the current Git branch and the last commit timestamp find_package(Git QUIET) if(GIT_FOUND) @@ -199,35 +211,39 @@ set_target_properties(HarmonyLinkLibStatic PROPERTIES OUTPUT_NAME "HarmonyLinkLi target_link_libraries(HarmonyLinkLibStatic PRIVATE fmt::fmt-header-only) target_link_libraries(HarmonyLinkLibShared PRIVATE fmt::fmt-header-only) -# Determine the compiler and set appropriate flags for libc++ -if (UNIX AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") - # Use libc++ instead of libstdc++ with Clang - target_compile_options(HarmonyLinkLibStatic PRIVATE -stdlib=libc++) - target_compile_options(HarmonyLinkLibShared PRIVATE -stdlib=libc++) - target_link_options(HarmonyLinkLibStatic PRIVATE -stdlib=libc++) - target_link_options(HarmonyLinkLibShared PRIVATE -stdlib=libc++) - - # Ensure the proper include paths for libc++ - target_include_directories(HarmonyLinkLibStatic SYSTEM PRIVATE - /usr/include/c++/v1 - /usr/local/include/c++/v1 - /usr/include - ) - target_include_directories(HarmonyLinkLibShared SYSTEM PRIVATE - /usr/include/c++/v1 - /usr/local/include/c++/v1 - /usr/include - ) +# Link ghc to HarmonyLinkLib +target_link_libraries(HarmonyLinkLibStatic PRIVATE ghc_filesystem) +target_link_libraries(HarmonyLinkLibShared PRIVATE ghc_filesystem) - # Link against the libc++ library and the filesystem library - target_link_libraries(HarmonyLinkLibStatic PRIVATE c++ c++abi c++experimental) - target_link_libraries(HarmonyLinkLibShared PRIVATE c++ c++abi c++experimental) -elseif (UNIX AND CMAKE_CXX_COMPILER_ID MATCHES "GNU") - # Use libstdc++ with GCC - target_link_options(HarmonyLinkLibStatic PRIVATE -static-libgcc -static-libstdc++) - target_link_options(HarmonyLinkLibShared PRIVATE -static-libgcc -static-libstdc++) - - # Link against the libstdc++ filesystem library if necessary - target_link_libraries(HarmonyLinkLibStatic PRIVATE stdc++fs) - target_link_libraries(HarmonyLinkLibShared PRIVATE stdc++fs) -endif() +# Determine the compiler and set appropriate flags for libc++ +#if (UNIX AND CMAKE_CXX_COMPILER_ID MATCHES "Clang") +# # Use libc++ instead of libstdc++ with Clang +# target_compile_options(HarmonyLinkLibStatic PRIVATE -stdlib=libc++) +# target_compile_options(HarmonyLinkLibShared PRIVATE -stdlib=libc++) +# target_link_options(HarmonyLinkLibStatic PRIVATE -stdlib=libc++) +# target_link_options(HarmonyLinkLibShared PRIVATE -stdlib=libc++) +# +# # Ensure the proper include paths for libc++ +# target_include_directories(HarmonyLinkLibStatic SYSTEM PRIVATE +# /usr/include/c++/v1 +# /usr/local/include/c++/v1 +# /usr/include +# ) +# target_include_directories(HarmonyLinkLibShared SYSTEM PRIVATE +# /usr/include/c++/v1 +# /usr/local/include/c++/v1 +# /usr/include +# ) +# +# # Link against the libc++ library and the filesystem library +# target_link_libraries(HarmonyLinkLibStatic PRIVATE c++ c++abi c++experimental) +# target_link_libraries(HarmonyLinkLibShared PRIVATE c++ c++abi c++experimental) +#elseif (UNIX AND CMAKE_CXX_COMPILER_ID MATCHES "GNU") +# # Use libstdc++ with GCC +# target_link_options(HarmonyLinkLibStatic PRIVATE -static-libgcc -static-libstdc++) +# target_link_options(HarmonyLinkLibShared PRIVATE -static-libgcc -static-libstdc++) +# +# # Link against the libstdc++ filesystem library if necessary +# target_link_libraries(HarmonyLinkLibStatic PRIVATE stdc++fs) +# target_link_libraries(HarmonyLinkLibShared PRIVATE stdc++fs) +#endif() diff --git a/HarmonyLinkLib/src/Platform/WineUtilities.cpp b/HarmonyLinkLib/src/Platform/WineUtilities.cpp index efe48a3..fca7352 100644 --- a/HarmonyLinkLib/src/Platform/WineUtilities.cpp +++ b/HarmonyLinkLib/src/Platform/WineUtilities.cpp @@ -18,12 +18,14 @@ #include #include #include -#include +#include #ifdef BUILD_WINDOWS #include #endif +namespace fs = ghc::filesystem; + namespace HarmonyLinkLib { bool force_detect_wine = false; @@ -38,7 +40,7 @@ namespace HarmonyLinkLib FBattery result = {}; for (int i = 0; i <= 9; ++i) { - if (std::string bat_path = append + "/sys/class/power_supply/BAT" + std::to_string(i); std::filesystem::exists(bat_path)) { + if (std::string bat_path = append + "/sys/class/power_supply/BAT" + std::to_string(i); fs::exists(bat_path)) { result.has_battery = true; std::ifstream status_file(bat_path + "/status");