CMake: Determine host page size at build time

Needed for running on Asahi Linux.
This commit is contained in:
Stenzek
2024-02-24 21:40:56 +10:00
parent ab83247de3
commit 4a70164dac
5 changed files with 70 additions and 16 deletions

View File

@ -105,7 +105,12 @@ if(ANDROID)
target_link_libraries(common PRIVATE log)
endif()
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
if(LINUX)
# We need -lrt for shm_unlink
target_link_libraries(common PRIVATE rt)
endif()
# If the host size was detected, we need to set it as a macro.
if(HOST_PAGE_SIZE)
target_compile_definitions(common PUBLIC "-DOVERRIDE_HOST_PAGE_SIZE=${HOST_PAGE_SIZE}")
endif()

View File

@ -1,7 +1,8 @@
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <stenzek@gmail.com>
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
#pragma once
#include <bit>
#include <cstdint>
#include <cstring>
#include <limits>
@ -170,7 +171,11 @@ struct dependent_int_false : std::false_type
#endif
// Host page sizes.
#if defined(__APPLE__) && defined(__aarch64__)
#if defined(OVERRIDE_HOST_PAGE_SIZE)
static constexpr u32 HOST_PAGE_SIZE = OVERRIDE_HOST_PAGE_SIZE;
static constexpr u32 HOST_PAGE_MASK = HOST_PAGE_SIZE - 1;
static constexpr u32 HOST_PAGE_SHIFT = std::bit_width(HOST_PAGE_MASK);
#elif defined(__APPLE__) && defined(__aarch64__)
static constexpr u32 HOST_PAGE_SIZE = 0x4000;
static constexpr u32 HOST_PAGE_MASK = HOST_PAGE_SIZE - 1;
static constexpr u32 HOST_PAGE_SHIFT = 14;