Skip to content

Commit

Permalink
Remove stdc++fs requirement by using an external library
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordonbc committed Jun 6, 2024
1 parent 7f0fa0b commit a7a8057
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 34 deletions.
5 changes: 4 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,7 @@
# Executables
*.exe binary
*.out binary
*.app binary
*.app binary

# Linux shell files must always be LF
*.sh text eol=lf
78 changes: 47 additions & 31 deletions HarmonyLinkLib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
6 changes: 4 additions & 2 deletions HarmonyLinkLib/src/Platform/WineUtilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down

0 comments on commit a7a8057

Please sign in to comment.