diff options
| author | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-01 04:30:34 +0800 |
|---|---|---|
| committer | Richard-Qin-X <richard.qin.001@gmail.com> | 2026-08-01 04:30:34 +0800 |
| commit | 81cf8b68eca2636574f3d0a9fa1cf0b428c163e9 (patch) | |
| tree | f3a83496e71358123cc5f838269dc134d02b63f6 /backend/cmake | |
| parent | 72af0dedf9e18911da65b9a5c4906689e868d9fc (diff) | |
| download | rcc-project-81cf8b68eca2636574f3d0a9fa1cf0b428c163e9.tar.gz rcc-project-81cf8b68eca2636574f3d0a9fa1cf0b428c163e9.tar.xz | |
[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.
Diffstat (limited to 'backend/cmake')
| -rw-r--r-- | backend/cmake/RCCBackendConfig.cmake.in | 7 | ||||
| -rw-r--r-- | backend/cmake/modules/RCCBackendBuild.cmake | 93 | ||||
| -rw-r--r-- | backend/cmake/modules/RCCBackendDeveloperTools.cmake | 50 |
3 files changed, 150 insertions, 0 deletions
diff --git a/backend/cmake/RCCBackendConfig.cmake.in b/backend/cmake/RCCBackendConfig.cmake.in new file mode 100644 index 0000000..910572b --- /dev/null +++ b/backend/cmake/RCCBackendConfig.cmake.in @@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-3.0-or-later + +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/RCCBackendTargets.cmake") + +check_required_components(RCCBackend) 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() |
