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 ++++++++++++++++++++++ .../cmake/modules/RCCBackendDeveloperTools.cmake | 50 ++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 backend/cmake/modules/RCCBackendBuild.cmake create mode 100644 backend/cmake/modules/RCCBackendDeveloperTools.cmake (limited to 'backend/cmake/modules') 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() diff --git a/backend/cmake/modules/RCCBackendDeveloperTools.cmake b/backend/cmake/modules/RCCBackendDeveloperTools.cmake new file mode 100644 index 0000000..d3693cd --- /dev/null +++ b/backend/cmake/modules/RCCBackendDeveloperTools.cmake @@ -0,0 +1,50 @@ +# SPDX-License-Identifier: GPL-3.0-or-later + +function(rcc_backend_add_developer_targets) + get_property(FormatFiles GLOBAL PROPERTY RCC_BACKEND_FORMAT_FILES) + get_property(TidyFiles GLOBAL PROPERTY RCC_BACKEND_TIDY_FILES) + + if(FormatFiles) + list(REMOVE_DUPLICATES FormatFiles) + + add_custom_target( + rcc-backend-format + COMMAND "${RCC_BACKEND_CLANG_FORMAT}" -i ${FormatFiles} + COMMAND_EXPAND_LISTS + COMMENT "Formatting RCC Backend C++ sources" + VERBATIM + ) + + add_custom_target( + rcc-backend-format-check + COMMAND "${RCC_BACKEND_CLANG_FORMAT}" --dry-run --Werror ${FormatFiles} + COMMAND_EXPAND_LISTS + COMMENT "Checking RCC Backend C++ formatting" + VERBATIM + ) + endif() + + if(TidyFiles) + list(REMOVE_DUPLICATES TidyFiles) + + add_custom_target( + rcc-backend-tidy + COMMAND + "${RCC_BACKEND_CLANG_TIDY}" --warnings-as-errors=* + "-p=${CMAKE_BINARY_DIR}" ${TidyFiles} + COMMAND_EXPAND_LISTS + COMMENT "Running clang-tidy on RCC Backend" + VERBATIM + ) + + add_custom_target( + rcc-backend-analyze + COMMAND + "${RCC_BACKEND_CLANG_TIDY}" "--checks=-*,clang-analyzer-*" + --warnings-as-errors=* "-p=${CMAKE_BINARY_DIR}" ${TidyFiles} + COMMAND_EXPAND_LISTS + COMMENT "Running Clang Static Analyzer checks on RCC Backend" + VERBATIM + ) + endif() +endfunction() -- cgit v1.2.3