pound-emu_pound/CMakeLists.txt
Ronald Caesar 8b483849f4 arm64/mem: Refactor guest memory access and made it endian aware
Refactors the core guest memory access subsystem (guest.h) to be safer
and portable accross host systems with different endianness. The
previous implementation used direct pointer casting, which is not endian
safe.

1. All read and write functions have been converted from unsafe pointer
   casts to memcpy(). This resolves alignment warning -Wcast-align.

2. The access functions no longer rely on asserts for error checking.
   They now perform explicit boundary and alignment checking and returns
   a guest_mem_access_result_t status code.

3. A new header (endian.h) provides cross platform byte swapping macros.
   The memory access functions use these macros to ensure that the guest
   always sees memory in the correct endian format, regardless of the
   host's native byte order. The host endianness is now automatically
   detected via CMake.

3. Asserts are now explicitly enabled in release builds to catch
   critical errors.

Signed-off-by: Ronald Caesar <github43132@proton.me>
2025-09-13 23:14:26 -04:00

103 lines
2.4 KiB
CMake

# Copyright 2025 Xenon Emulator Project. All rights reserved.
cmake_minimum_required(VERSION 3.22)
set(CMAKE_C_STANDARD 17)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_C_STANDARD_REQUIRED TRUE)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(IMGUI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/3rd_Party/imgui)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
# Enable asserts in release mode.
string( REPLACE "/DNDEBUG" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
# Optimizations
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ON)
if (WIN32)
add_compile_options($<$<CONFIG:Release>:/Oi>)
add_compile_options($<$<CONFIG:Release>:/Ot>)
endif()
project(Pound)
find_package(fmt 10.2.1 CONFIG)
find_package(SDL3 3.2.10 CONFIG)
add_subdirectory(3rd_Party)
add_executable(Pound
src/main.cpp
)
add_subdirectory(src/kvm)
add_subdirectory(src/common)
add_subdirectory(src/frontend)
add_subdirectory(src/host)
add_subdirectory(src/targets/switch1/hardware)
# Detect Host System Endianness.
include(TestBigEndian)
TEST_BIG_ENDIAN(WORDS_BIGENDIAN)
if(WORDS_BIGENDIAN)
message(STATUS "Host Endianness: Big Endian")
else()
message(STATUS "Host Endianness: Little Endian")
endif()
# Configure Preprocessor Definitions based on Endianness.
if(WORDS_BIGENDIAN)
target_compile_definitions(Pound PRIVATE HOST_IS_BIG_ENDIAN=1)
target_compile_definitions(Pound PRIVATE HOST_IS_LITTLE_ENDIAN=0)
else()
target_compile_definitions(Pound PRIVATE HOST_IS_BIG_ENDIAN=0)
target_compile_definitions(Pound PRIVATE HOST_IS_LITTLE_ENDIAN=1)
endif()
target_compile_options(Pound PRIVATE -Wall -Wpedantic
-Wshadow
-Wpointer-arith
-Wcast-qual
-Wcast-align
-Wconversion
)
# Link libraries
target_link_libraries(Pound PRIVATE fmt::fmt SDL3::SDL3)
if (WIN32)
add_compile_definitions(NOMINMAX WIN32_LEAN_AND_MEAN)
# Disables Warnings
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
endif()
# ImGui
set(IMGUI_SRC
${IMGUI_DIR}/imgui.cpp
${IMGUI_DIR}/imgui_demo.cpp
${IMGUI_DIR}/imgui_draw.cpp
${IMGUI_DIR}/imgui_tables.cpp
${IMGUI_DIR}/imgui_widgets.cpp
${IMGUI_DIR}/backends/imgui_impl_sdl3.cpp
${IMGUI_DIR}/backends/imgui_impl_opengl3.cpp
)
target_sources(Pound PRIVATE ${IMGUI_SRC})
target_include_directories(Pound PRIVATE
${IMGUI_DIR}
${IMGUI_DIR}/backends
)
find_package(OpenGL REQUIRED)
target_link_libraries(Pound PRIVATE OpenGL::GL)
# add ./gui directory