aboutsummaryrefslogtreecommitdiff
path: root/backend/cmake/modules/RCCBackendBuild.cmake
diff options
context:
space:
mode:
authorRichard-Qin-X <richard.qin.001@gmail.com>2026-08-01 04:30:34 +0800
committerRichard-Qin-X <richard.qin.001@gmail.com>2026-08-01 04:30:34 +0800
commit81cf8b68eca2636574f3d0a9fa1cf0b428c163e9 (patch)
treef3a83496e71358123cc5f838269dc134d02b63f6 /backend/cmake/modules/RCCBackendBuild.cmake
parent72af0dedf9e18911da65b9a5c4906689e868d9fc (diff)
downloadrcc-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/modules/RCCBackendBuild.cmake')
-rw-r--r--backend/cmake/modules/RCCBackendBuild.cmake93
1 files changed, 93 insertions, 0 deletions
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()