From 81cf8b68eca2636574f3d0a9fa1cf0b428c163e9 Mon Sep 17 00:00:00 2001 From: Richard-Qin-X Date: Sat, 1 Aug 2026 04:30:34 +0800 Subject: [Backend] Establish standalone build infrastructure Add the thin monorepo CMake entry point and an independently configurable backend project. Enforce the Clang/C++23 toolchain, expose Make/Ninja-neutral tests and developer checks, export an installable RCCBackend package, and introduce the first Support error abstraction. --- backend/cmake/modules/RCCBackendBuild.cmake | 93 +++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 backend/cmake/modules/RCCBackendBuild.cmake (limited to 'backend/cmake/modules/RCCBackendBuild.cmake') diff --git a/backend/cmake/modules/RCCBackendBuild.cmake b/backend/cmake/modules/RCCBackendBuild.cmake new file mode 100644 index 0000000..79e7bb1 --- /dev/null +++ b/backend/cmake/modules/RCCBackendBuild.cmake @@ -0,0 +1,93 @@ +# SPDX-License-Identifier: GPL-3.0-or-later + +function(rcc_backend_initialize_toolchain) + string(REGEX MATCH "^[0-9]+" RCCBackendClangMajor "${CMAKE_CXX_COMPILER_VERSION}") + + find_program( + RCC_BACKEND_CLANG_FORMAT + NAMES "clang-format-${RCCBackendClangMajor}" clang-format + REQUIRED + ) + find_program( + RCC_BACKEND_CLANG_TIDY + NAMES "clang-tidy-${RCCBackendClangMajor}" clang-tidy + REQUIRED + ) + + foreach(Tool IN ITEMS RCC_BACKEND_CLANG_FORMAT RCC_BACKEND_CLANG_TIDY) + execute_process( + COMMAND "${${Tool}}" --version + OUTPUT_VARIABLE ToolVersionOutput + ERROR_VARIABLE ToolVersionError + RESULT_VARIABLE ToolVersionResult + ) + if(NOT ToolVersionResult EQUAL 0) + message( + FATAL_ERROR + "Unable to query ${Tool}: ${ToolVersionOutput}${ToolVersionError}" + ) + endif() + + string(REGEX MATCH "version[ \t]+([0-9]+)" ToolVersionMatch "${ToolVersionOutput}") + if(NOT CMAKE_MATCH_1 STREQUAL RCCBackendClangMajor) + message( + FATAL_ERROR + "${Tool} must have Clang major version ${RCCBackendClangMajor}: " + "${ToolVersionOutput}" + ) + endif() + endforeach() + + set(RCC_BACKEND_CLANG_FORMAT "${RCC_BACKEND_CLANG_FORMAT}" PARENT_SCOPE) + set(RCC_BACKEND_CLANG_TIDY "${RCC_BACKEND_CLANG_TIDY}" PARENT_SCOPE) +endfunction() + +function(rcc_backend_configure_target Target) + target_compile_features("${Target}" PUBLIC cxx_std_23) + set_target_properties( + "${Target}" + PROPERTIES + CXX_EXTENSIONS OFF + CXX_STANDARD 23 + CXX_STANDARD_REQUIRED ON + ) + + target_compile_options( + "${Target}" + PRIVATE + -Wall + -Wextra + -Wpedantic + -Wconversion + -Wsign-conversion + -Wshadow + -Wnon-virtual-dtor + -Wold-style-cast + -Wcast-align + -Woverloaded-virtual + -Wnull-dereference + -Wdouble-promotion + -Wformat=2 + ) + + if(RCC_BACKEND_WARNINGS_AS_ERRORS) + target_compile_options("${Target}" PRIVATE -Werror) + endif() + + if(RCC_BACKEND_ENABLE_CLANG_TIDY) + set_target_properties( + "${Target}" + PROPERTIES + CXX_CLANG_TIDY + "${RCC_BACKEND_CLANG_TIDY};--warnings-as-errors=*" + ) + endif() +endfunction() + +function(rcc_backend_register_format_files) + set_property(GLOBAL APPEND PROPERTY RCC_BACKEND_FORMAT_FILES ${ARGN}) +endfunction() + +function(rcc_backend_register_tidy_files) + set_property(GLOBAL APPEND PROPERTY RCC_BACKEND_TIDY_FILES ${ARGN}) +endfunction() -- cgit v1.2.3