From 39f6fa32c4801abac4e7180c198645e590af4a38 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sat, 29 Aug 2026 08:28:57 +0000 Subject: [PATCH] =?UTF-8?q?refactor(cmake):=20=E2=99=BB=EF=B8=8F=20query?= =?UTF-8?q?=20machine=20flags=20from=20ARCH=5FFLAG=20itself?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit _monoprop_query_machine_flags took a -march *name* plus a "default" sentinel and rebuilt the flag from it, which meant the query could only ever ask about the one architecture selection the function knew how to spell. It now takes the ARCH_FLAGS list the build actually passes, so what is queried is what is compiled, and an empty list is the no-arch-flag build rather than a special case. Inert by construction and checked as such: configured with monoprop_ENABLE_ARCH_FLAGS both ON and OFF, monoprop_DEFAULT_VARIANT_FLAGS, monoprop_VARIANTS, monoprop_VARIANT_FLAGS and ARCH_FLAG all come out identical to the previous implementation. Assisted-by: ClaudeCode:claude-opus-5 --- cmake/compiler_flags/CXXFlags.cmake | 44 ++++++++++++----------------- 1 file changed, 18 insertions(+), 26 deletions(-) diff --git a/cmake/compiler_flags/CXXFlags.cmake b/cmake/compiler_flags/CXXFlags.cmake index 5d12b9e1..a6805df6 100644 --- a/cmake/compiler_flags/CXXFlags.cmake +++ b/cmake/compiler_flags/CXXFlags.cmake @@ -81,19 +81,13 @@ if(monoprop_ENABLE_ARCH_FLAGS) endif() endif() -# Query the machine-dependent flags for a given -march value and store the -# cleaned, space-separated string in the variable named by OUTPUT_VARIABLE. A -# MARCH of "default" queries the default target (no -march flag). +# Query the machine-dependent flags the compiler applies under a given architecture selection and +# store the cleaned, space-separated string in the variable named by OUTPUT_VARIABLE. # # Usage: -# _monoprop_query_machine_flags(MARCH OUTPUT_VARIABLE ) +# _monoprop_query_machine_flags(ARCH_FLAGS OUTPUT_VARIABLE ) function(_monoprop_query_machine_flags) - set( - _one_value_args - MARCH - OUTPUT_VARIABLE - ) - cmake_parse_arguments(PARSE_ARGV 0 _arg "" "${_one_value_args}" "") + cmake_parse_arguments(PARSE_ARGV 0 _arg "" "OUTPUT_VARIABLE" "ARCH_FLAGS") if(NOT _arg_OUTPUT_VARIABLE) message( @@ -101,21 +95,19 @@ function(_monoprop_query_machine_flags) "_monoprop_query_machine_flags: OUTPUT_VARIABLE is required" ) endif() - if(NOT _arg_MARCH) - message(FATAL_ERROR "_monoprop_query_machine_flags: MARCH is required") - endif() - if(_arg_MARCH STREQUAL "default") - set(_march_args "") + set(_arch_args ${_arg_ARCH_FLAGS}) + if(_arch_args) + string(JOIN " " _arch_label ${_arch_args}) else() - set(_march_args "-march=${_arg_MARCH}") + set(_arch_label "the default target") endif() if(CMAKE_CXX_COMPILER_ID MATCHES Clang) execute_process( COMMAND # gersemi: off - ${CMAKE_CXX_COMPILER} ${_march_args} -\#\#\# -x c++ -c /dev/null + ${CMAKE_CXX_COMPILER} ${_arch_args} -\#\#\# -x c++ -c /dev/null # gersemi: on ERROR_VARIABLE _query_output ERROR_STRIP_TRAILING_WHITESPACE @@ -124,7 +116,7 @@ function(_monoprop_query_machine_flags) if(NOT _query_result EQUAL 0) message( WARNING - "Failed to query machine-dependent flags for '${_arg_MARCH}' with AppleClang (exit code ${_query_result}). Continuing with empty machine flags." + "Failed to query machine-dependent flags for ${_arch_label} with AppleClang (exit code ${_query_result}). Continuing with empty machine flags." ) set(_flags "") else() @@ -141,7 +133,7 @@ function(_monoprop_query_machine_flags) if(NOT _parse_result EQUAL 0) message( WARNING - "Failed to parse AppleClang machine-dependent flags for '${_arg_MARCH}' (exit code ${_parse_result}). Continuing with empty machine flags." + "Failed to parse AppleClang machine-dependent flags for ${_arch_label} (exit code ${_parse_result}). Continuing with empty machine flags." ) set(_flags "") endif() @@ -149,7 +141,7 @@ function(_monoprop_query_machine_flags) else() execute_process( COMMAND - ${CMAKE_CXX_COMPILER} ${_march_args} -Q --help=target + ${CMAKE_CXX_COMPILER} ${_arch_args} -Q --help=target COMMAND ${Python_EXECUTABLE} "${PROJECT_SOURCE_DIR}/tools/target-help-clean.py" --mode gcc @@ -160,19 +152,19 @@ function(_monoprop_query_machine_flags) if(NOT _result EQUAL 0) message( FATAL_ERROR - "Failed to query machine-dependent flags for '${_arg_MARCH}' (exit code ${_result})" + "Failed to query machine-dependent flags for ${_arch_label} (exit code ${_result})" ) endif() endif() set(${_arg_OUTPUT_VARIABLE} "${_flags}" PARENT_SCOPE) endfunction() +# Empty is the no-arch-flag build and queries the default target. set(monoprop_DEFAULT_VARIANT_FLAGS "") -if(monoprop_ENABLE_ARCH_FLAGS) - _monoprop_query_machine_flags(MARCH native OUTPUT_VARIABLE monoprop_DEFAULT_VARIANT_FLAGS) -else() - _monoprop_query_machine_flags(MARCH default OUTPUT_VARIABLE monoprop_DEFAULT_VARIANT_FLAGS) -endif() +_monoprop_query_machine_flags( + ARCH_FLAGS ${ARCH_FLAG} + OUTPUT_VARIABLE monoprop_DEFAULT_VARIANT_FLAGS +) set(monoprop_VARIANTS "") set(monoprop_VARIANT_FLAGS "")