Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
48 changes: 48 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Checks: >
bugprone-*,
cppcoreguidelines-*,
modernize-*,
performance-*,
readability-*,
-bugprone-easily-swappable-parameters,
-bugprone-exception-escape,
-bugprone-unchecked-optional-access,
-bugprone-derived-method-shadowing-base-method,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-macro-usage,
-cppcoreguidelines-pro-type-vararg,
-cppcoreguidelines-pro-type-reinterpret-cast,
-cppcoreguidelines-pro-bounds-avoid-unchecked-container-access,
-cppcoreguidelines-avoid-do-while,
-cppcoreguidelines-pro-type-static-cast-downcast,
-cppcoreguidelines-avoid-const-or-ref-data-members,
-modernize-use-trailing-return-type,
-modernize-use-integer-sign-comparison,
-readability-magic-numbers,
-readability-uppercase-literal-suffix,
-readability-identifier-length,
-readability-braces-around-statements,
-readability-function-cognitive-complexity,
-readability-else-after-return,
-readability-avoid-nested-conditional-operator,
-readability-math-missing-parentheses,

-bugprone-macro-parentheses,
-cppcoreguidelines-pro-type-member-init,
-cppcoreguidelines-init-variables,
-cppcoreguidelines-non-private-member-variables-in-classes,
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-pro-type-union-access,
-cppcoreguidelines-prefer-member-initializer,
-modernize-use-nodiscard,
-readability-qualified-auto,
-readability-avoid-const-params-in-decls,
-readability-convert-member-functions-to-static,
-performance-enum-size,
-performance-no-int-to-ptr,
-clang-analyzer-optin.performance.Padding
WarningsAsErrors: ''
HeaderFilterRegex: '.*'
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,13 @@ jobs:
echo "Installing Intel Homebrew"
NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi

brew install boost fmt sdl3 dylibbundler
'
else
echo "Installing arm64 deps"
brew install boost fmt sdl3 dylibbundler
fi

brew install llvm boost fmt sdl3 dylibbundler

- name: Verify CMake Version
run: cmake --version

Expand All @@ -96,11 +95,12 @@ jobs:
- name: Build Hydra
run: |
cmake hydra -B build \
-DCMAKE_OSX_ARCHITECTURES=${{ env.ARCH }} \
-DCMAKE_BUILD_TYPE=${{ env.BUILD_MODE }} \
-DFRONTEND=${{ env.FRONTEND_MODE }} \
-DMACOS_BUNDLE=ON \
-GNinja
-DCMAKE_OSX_ARCHITECTURES=${{ env.ARCH }} \
-DCMAKE_BUILD_TYPE=${{ env.BUILD_MODE }} \
-DCLANG_TIDY_ENABLED=OFF \
-DMACOS_BUNDLE=ON \
-DFRONTEND=${{ env.FRONTEND_MODE }} \
-GNinja
ninja -C build
dylibbundler -of -cd -b -x build/bin/Hydra.app/Contents/MacOS/Hydra -d build/bin/Hydra.app/Contents/libs
while install_name_tool -delete_rpath @executable_path/../libs/ build/bin/Hydra.app/Contents/MacOS/Hydra 2>/dev/null; do :; done
Expand Down
69 changes: 58 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,35 @@ set(CMAKE_POLICY_VERSION_MINIMUM 3.15)

include(FetchContent)

# Use LLVM clang instead of the system default one on Apple
# TODO: test with Xcode
if (APPLE AND NOT CMAKE_GENERATOR STREQUAL "Xcode")
# Find LLVM
execute_process(
COMMAND brew --prefix llvm
OUTPUT_VARIABLE LLVM_ROOT
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)

if (LLVM_ROOT)
message(STATUS "Using Homebrew LLVM: ${LLVM_ROOT}")
set(CMAKE_C_COMPILER "${LLVM_ROOT}/bin/clang")
set(CMAKE_CXX_COMPILER "${LLVM_ROOT}/bin/clang++")

# Manually set sysroot
execute_process(
COMMAND xcrun --show-sdk-path
OUTPUT_VARIABLE SDK_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(CMAKE_OSX_SYSROOT "${SDK_PATH}" CACHE PATH "Sysroot")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isysroot ${SDK_PATH}" CACHE STRING "Flags")
else ()
message(WARNING "LLVM not found via brew. Falling back to default system compiler.")
endif ()
endif ()

project(hydra VERSION 0.4.2 LANGUAGES CXX)

set(IOS_DEPLOYMENT_TARGET 17.4.0)
Expand All @@ -13,6 +42,7 @@ else ()
set(TARGET_ARCHS "${CMAKE_HOST_SYSTEM_PROCESSOR}")
endif ()

option(CLANG_TIDY_ENABLED "Enable clang-tidy" ON)
option(CUBEB_ENABLED "Enable the cubeb audio backend" ON)
option(SDL_ENABLED "Enable building SDL files" ON)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
Expand Down Expand Up @@ -44,7 +74,9 @@ endif ()

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_SCAN_FOR_MODULES OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_COLOR_DIAGNOSTICS ON)

if (CMAKE_BUILD_TYPE STREQUAL "Release")
set(GIT_HASH_SHORT "")
Expand Down Expand Up @@ -102,38 +134,50 @@ endif ()

# Externals

# elf
include_directories(SYSTEM externals/elf/include)

# toml11
#add_subdirectory(externals/toml11) # Hatch already uses toml11
#add_subdirectory(externals/toml11 SYSTEM) # Hatch already uses toml11

# dynarmic
add_subdirectory(externals/dynarmic)
add_subdirectory(externals/dynarmic SYSTEM)

# cubeb
if (CUBEB_ENABLED)
set(BUILD_TESTS OFF)
set(BUILD_TOOLS OFF)
add_subdirectory(externals/cubeb)
add_subdirectory(externals/cubeb SYSTEM)
endif ()

# luft
#add_subdirectory(externals/luft)
#add_subdirectory(externals/luft SYSTEM)

# hatch
add_subdirectory(externals/hatch)
add_subdirectory(externals/hatch SYSTEM)

# libyaz0
add_subdirectory(externals/libyaz0)
add_subdirectory(externals/libyaz0 SYSTEM)

# nx2elf
add_subdirectory(externals/nx2elf)
add_subdirectory(externals/nx2elf SYSTEM)

# date
set(BUILD_TZ_LIB ON)
add_subdirectory(externals/date)
add_subdirectory(externals/date SYSTEM)

set(CMAKE_COMPILE_WARNING_AS_ERROR ON)
add_library(hydra_warnings INTERFACE)
target_compile_options(hydra_warnings INTERFACE
add_library(hydra_compile_options INTERFACE)
target_compile_options(hydra_compile_options INTERFACE
# TODO: uncomment
#-fno-exceptions
#-fno-asynchronous-unwind-tables
-fno-rtti
# TODO: uncomment
#-fno-threadsafe-statics
-fvisibility=hidden

# Warnings
-Wall
-Wextra
-Wpedantic
Expand All @@ -146,6 +190,9 @@ target_compile_options(hydra_warnings INTERFACE
-Wnon-virtual-dtor
-Wold-style-cast

# Disabled warnings
-Wno-missing-designated-field-initializers

# Extensions
-Wno-c99-extensions
-Wno-gnu-anonymous-struct
Expand All @@ -156,7 +203,7 @@ target_compile_options(hydra_warnings INTERFACE
-Wno-gnu-zero-variadic-macro-arguments
)

include_directories(externals/metal-cpp externals/dynarmic externals/stb)
include_directories(SYSTEM externals/metal-cpp externals/dynarmic externals/stb)

if (HYPERVISOR_ENABLED)
add_compile_definitions(HYDRA_HYPERVISOR_ENABLED)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ You can download the latest release from [here](https://github.com/SamoZ256/hydr
You can install Hydra dependencies with a package manager of your choice, like `brew`.

```sh
brew install cmake ninja sdl3 fmt
brew install cmake ninja llvm boost fmt sdl3
```

### Building
Expand Down
File renamed without changes.
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
include_directories(.)

if (CLANG_TIDY_ENABLED)
set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-use-color;-extra-arg-before=-Wno-unknown-warning-option")
endif ()

add_subdirectory(common)
add_subdirectory(core)
add_subdirectory(frontend)
5 changes: 1 addition & 4 deletions src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ add_library(hydra-common
functions.hpp
atomic.hpp
literals.hpp
optional_helper.hpp
string.hpp
time.hpp
hash.hpp
Expand All @@ -26,8 +25,6 @@ add_library(hydra-common
config.cpp
config.hpp
common.hpp
elf.h
stb.cpp
io/stream.hpp
io/continuous_stream.hpp
io/memory_stream.hpp
Expand All @@ -36,7 +33,7 @@ add_library(hydra-common
io/sparse_stream.hpp
)

target_link_libraries(hydra-common PRIVATE hydra_warnings)
target_link_libraries(hydra-common PRIVATE hydra_compile_options)
target_link_libraries(hydra-common PUBLIC fmt::fmt toml11::toml11)

target_precompile_headers(hydra-common PUBLIC common.hpp)
Expand Down
1 change: 0 additions & 1 deletion src/common/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "common/literals.hpp"
#include "common/log.hpp"
#include "common/objc.hpp"
#include "common/optional_helper.hpp"
#include "common/platform.hpp"
#include "common/range.hpp"
#include "common/small_cache.hpp"
Expand Down
6 changes: 3 additions & 3 deletions src/common/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ template <>
struct from<CustomResolution> {
template <typename TC>
static CustomResolution from_toml(const basic_value<TC>& v) {
const auto str = v.as_string();
const auto& str = v.as_string();
const auto x_pos = str.find('x');
if (x_pos == std::string::npos)
LOG_FATAL(Other, "Invalid custom display resolution {}", str);
Expand All @@ -45,7 +45,7 @@ struct from<CustomResolution> {
if (!str_to_num(std::string_view(str).substr(x_pos + 1), res.y()))
LOG_FATAL(Other, "Invalid custom display resolution {}", str);

return CustomResolution(res);
return {res};
}
};

Expand All @@ -72,7 +72,7 @@ Config::Config() {
} else {
LOG_FATAL(Other, "Failed to find HOME path");
}
#elif defined(PLATFORM_WINDOWS)
#elifdef PLATFORM_WINDOWS
if (const char* app_data = std::getenv("APPDATA")) {
app_data_path = fmt::format("{}/" APP_NAME, app_data);
logs_path = fmt::format("{}/logs", app_data_path); // TODO
Expand Down
6 changes: 3 additions & 3 deletions src/common/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ class Config {
void Log();

// Paths
const std::string_view GetAppDataPath() const { return app_data_path; }
const std::string_view GetLogsPath() const { return logs_path; }
const std::string_view GetPicturesPath() const { return pictures_path; }
std::string_view GetAppDataPath() const { return app_data_path; }
std::string_view GetLogsPath() const { return logs_path; }
std::string_view GetPicturesPath() const { return pictures_path; }

std::string GetConfigPath() const {
return fmt::format("{}/config.toml", app_data_path);
Expand Down
10 changes: 5 additions & 5 deletions src/common/dynamic_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace hydra {
template <typename T, bool allow_zero_handle = false>
class DynamicPool : public Pool<DynamicPool<T>, T, allow_zero_handle> {
public:
u32 _AllocateIndex() {
u32 AllocateIndex_() {
// TODO: look for a free index first

const auto index = static_cast<u32>(objects.size());
Expand All @@ -17,24 +17,24 @@ class DynamicPool : public Pool<DynamicPool<T>, T, allow_zero_handle> {
return index;
}

void _FreeByIndex(u32 index) {
void FreeByIndex_(u32 index) {
if (index == objects.size() - 1)
objects.pop_back();
else
free_slots.push_back(index);
}

bool _IsValidByIndex(u32 index) const {
bool IsValidByIndex_(u32 index) const {
if (index >= objects.size())
return false;

return std::find(free_slots.begin(), free_slots.end(), index) ==
free_slots.end();
}

T& _GetByIndex(u32 index) { return objects[index]; }
T& GetByIndex_(u32 index) { return objects[index]; }

const T& _GetByIndex(u32 index) const { return objects[index]; }
const T& GetByIndex_(u32 index) const { return objects[index]; }

usize GetCapacity() const { return objects.size(); }

Expand Down
19 changes: 10 additions & 9 deletions src/common/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,34 @@
namespace hydra {

#ifdef PLATFORM_APPLE
inline std::string get_bundle_resource_path(const std::string& filename) {
inline std::string GetBundleResourcePath(const std::string& filename) {
CFBundleRef main_bundle = CFBundleGetMainBundle();
if (!main_bundle) {
if (main_bundle == nullptr) {
LOG_FATAL(Common, APP_NAME " is not a bundle");
return "";
}

CFStringRef cf_filename = CFStringCreateWithCString(NULL, filename.c_str(),
kCFStringEncodingUTF8);
CFStringRef cf_filename = CFStringCreateWithCString(
nullptr, filename.c_str(), kCFStringEncodingUTF8);
CFURLRef resource_url =
CFBundleCopyResourceURL(main_bundle, cf_filename, NULL, NULL);
CFBundleCopyResourceURL(main_bundle, cf_filename, nullptr, nullptr);

if (resource_url == NULL) {
if (resource_url == nullptr) {
CFRelease(cf_filename);
return "";
}

CFStringRef resource_path =
CFURLCopyFileSystemPath(resource_url, kCFURLPOSIXPathStyle);
char path[PATH_MAX];
CFStringGetCString(resource_path, path, PATH_MAX, kCFStringEncodingUTF8);
std::array<char, PATH_MAX> path;
CFStringGetCString(resource_path, path.data(), PATH_MAX,
kCFStringEncodingUTF8);

CFRelease(cf_filename);
CFRelease(resource_url);
CFRelease(resource_path);

return std::string(path);
return {path.data(), path.size()};
}
#endif

Expand Down
Loading
Loading