Files
HexwellandClaude Fable 5 8db337607a refactor(build): extract shared CMake target helpers
All 17 module CMakeLists repeated the same prologue: language standards, the
PS5 SDK header paths, a clang check, the cross-compile triple, the output
directory layout and an objcopy strip step. The triple appeared 17 times and
the strip block 6 times, each needing manual sync.

Add source/cmake/OnionTarget.cmake with onion_module_prologue,
onion_output_dirs and onion_strip_debug. Language standards stay opt-in
arguments because the loader-side C modules are C17 while the rest are C11,
and a shared default would silently downgrade them. Per-module compiler flags
are left alone since the modules genuinely differ.

Drop IS_SUBPROJECT and IS_CLANG, which were assigned in 11 and 6 modules
respectively and never read anywhere.

Add CONFIGURE_DEPENDS to the seven source-listing globs that lacked it, so a
newly added source file triggers a re-configure instead of being silently
omitted from the build.

Hoist -DDEBUG onto the shared C flags in the five modules that only passed it
to C++, so both languages in a target see the same macros. No .c file keys
off DEBUG today, so this changes no behaviour.

Compile and link flags were captured from build.ninja before and after: all
132 compile edges and 17 link edges are unchanged except for the intended
-DDEBUG addition.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-26 19:50:30 +08:00

34 lines
1.3 KiB
CMake

###################################################################################################
# PS5SDK - Example: pipe pirate
# Uses the read/write primitive to read and write some kernel data.
# @authors ChendoChap, Specter, Znullptr
###################################################################################################
cmake_minimum_required (VERSION 3.20)
set(basename "NidResolver")
project(${basename} C)
set(D_CWD "${PROJECT_SOURCE_DIR}")
onion_module_prologue(C_STANDARD 17)
set(D_SRC ${D_CWD}/source)
file(GLOB SrcFiles CONFIGURE_DEPENDS ${D_SRC}/*.c ${D_SRC}/*.h)
add_library(${PROJECT_NAME} STATIC ${SrcFiles})
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "${PROJECT_NAME}")
# Finalize main target sources
target_compile_options(${PROJECT_NAME} PUBLIC
$<$<COMPILE_LANGUAGE:C>:${C_DEFS} ${C_FLAGS}>
)
set(CMAKE_C_FLAGS "${ONION_PS5_TARGET_FLAGS_MARCH} ")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_POSIX_SOURCE -D_POSIX_C_SOURCE=200112 -D__BSD_VISIBLE=1 -D__XSI_VISIBLE=500")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-builtin -nostdlib -Wall") # -nostartfiles
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -gfull -O3 -march=znver2 -Wall -Werror")
target_include_directories(${PROJECT_NAME} PRIVATE "${D_CWD}/../include")