Remove stdc++fs requirement by using an external library
This commit is contained in:
parent
7f0fa0b90d
commit
a7a80571ea
3 changed files with 55 additions and 34 deletions
|
@ -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)
|
||||
|
||||
# Link ghc to HarmonyLinkLib
|
||||
target_link_libraries(HarmonyLinkLibStatic PRIVATE ghc_filesystem)
|
||||
target_link_libraries(HarmonyLinkLibShared PRIVATE ghc_filesystem)
|
||||
|
||||
# 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()
|
||||
#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()
|
||||
|
|
|
@ -18,12 +18,14 @@
|
|||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <unordered_map>
|
||||
#include <filesystem>
|
||||
#include <ghc/filesystem.hpp>
|
||||
|
||||
#ifdef BUILD_WINDOWS
|
||||
#include <windows.h>
|
||||
#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");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue