From 628fefa7a797636c1dce9ba058549f2191507e1c Mon Sep 17 00:00:00 2001 From: Joshua Goldstein Date: Mon, 6 Jan 2025 14:38:56 -0800 Subject: [PATCH] pw_toolchain: Clang can specify path to gcc toolchain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add new functions in clang_flags.cmake with named arguments instead of positional ones - Add ability to specify path of gcc toolchain to be used Change-Id: I0aa585be6ba7b2f45fa52d985dc87d90fc36b15f Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/257312 Lint: Lint 🤖 Commit-Queue: Joshua Goldstein Reviewed-by: Ewout van Bekkum Pigweed-Auto-Submit: Joshua Goldstein Docs-Not-Needed: Joshua Goldstein Reviewed-by: Wyatt Hepler Presubmit-Verified: CQ Bot Account --- pw_toolchain/arm_clang/clang_flags.cmake | 99 ++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/pw_toolchain/arm_clang/clang_flags.cmake b/pw_toolchain/arm_clang/clang_flags.cmake index a66045ccc6..9c7c81c69d 100644 --- a/pw_toolchain/arm_clang/clang_flags.cmake +++ b/pw_toolchain/arm_clang/clang_flags.cmake @@ -11,6 +11,9 @@ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations under # the License. +include_guard(GLOBAL) + +include("$ENV{PW_ROOT}/pw_build/pigweed.cmake") # Clang isn't a plug-and-play experience for Cortex-M baremetal targets; it's # missing C runtime libraries, C/C++ standard libraries, and a few other @@ -33,7 +36,38 @@ function(_pw_get_clang_flags OUTPUT_VARIABLE TYPE) set(${OUTPUT_VARIABLE} ${_result} PARENT_SCOPE) endfunction() +# This function is meant to replace _pw_get_clang_flags and now uses named +# variables. +function(_pw_get_clang_runtime_env_flags OUTPUT_VARIABLE TYPE) + pw_parse_arguments( + NUM_POSITIONAL_ARGS + 2 + ONE_VALUE_ARGS + GCC_TOOLCHAIN_PATH + MULTI_VALUE_ARGS + ARCH_FLAGS + ) + + set(GCC_PATH_ARG "") + if (NOT "${arg_GCC_TOOLCHAIN_PATH}" STREQUAL "") + set(GCC_PATH_ARG "--gcc-exe-path;${arg_GCC_TOOLCHAIN_PATH}") + endif() + + execute_process( + COMMAND python + $ENV{PW_ROOT}/pw_toolchain/py/pw_toolchain/clang_arm_toolchain.py + ${GCC_PATH_ARG} + ${TYPE} -- ${arg_ARCH_FLAGS} + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + OUTPUT_VARIABLE _result + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + set(${OUTPUT_VARIABLE} ${_result} PARENT_SCOPE) +endfunction() + + # This returns the compile flags needed for compiling with clang as a string. +# This function is deprecated. Use pw_get_clang_runtime_env_compile_flags. # # Usage: # @@ -45,11 +79,44 @@ endfunction() # pw_get_clang_compile_flags(result -mcpu=cortex-m33 -mthumb -mfloat-abi=hard) # function(pw_get_clang_compile_flags OUTPUT_VARIABLE) + message(DEPRECATION "Use pw_get_clang_runtime_env_compile_flags") _pw_get_clang_flags(_result --cflags ${ARGN}) set(${OUTPUT_VARIABLE} ${_result} PARENT_SCOPE) endfunction() +# This returns the compile flags needed for compiling with clang as a string. +# +# Usage: +# +# pw_get_clang_runtime_env_compile_flags(OUTPUT_VARIABLE +# [GCC_TOOLCHAIN_PATH ] +# [ARCH_FLAGS ...]) +# +# Example: +# +# # Retrieve the compile flags needed for this arch and store them in "result". +# pw_get_clang_runtime_env_compile_flags(result ARCH_FLAGS -mcpu=cortex-m33 -mthumb -mfloat-abi=hard) +# +function(pw_get_clang_runtime_env_compile_flags OUTPUT_VARIABLE) + pw_parse_arguments( + NUM_POSITIONAL_ARGS + 1 + ONE_VALUE_ARGS + GCC_TOOLCHAIN_PATH + MULTI_VALUE_ARGS + ARCH_FLAGS + ) + + _pw_get_clang_runtime_env_flags(_result --cflags + GCC_TOOLCHAIN_PATH + ${arg_GCC_TOOLCHAIN_PATH} + ARCH_FLAGS + ${arg_ARCH_FLAGS}) + set(${OUTPUT_VARIABLE} ${_result} PARENT_SCOPE) +endfunction() + # This returns the link flags needed for compiling with clang as a string. +# This function is deprecated. Use pw_get_clang_runtime_env_link_flags. # # Usage: # @@ -61,6 +128,38 @@ endfunction() # pw_get_clang_link_flags(result -mcpu=cortex-m33 -mthumb -mfloat-abi=hard) # function(pw_get_clang_link_flags OUTPUT_VARIABLE) + message(DEPRECATION "Use pw_get_clang_runtime_env_link_flags") _pw_get_clang_flags(_result --ldflags ${ARGN}) set(${OUTPUT_VARIABLE} ${_result} PARENT_SCOPE) endfunction() + +# This returns the compile flags needed for compiling with clang as a string. +# +# Usage: +# +# pw_get_clang_runtime_env_link_flags(OUTPUT_VARIABLE +# [GCC_TOOLCHAIN_PATH ] +# [ARCH_FLAGS ...]) +# +# Example: +# +# # Retrieve the compile flags needed for this arch and store them in "result". +# pw_get_clang_runtime_env_link_flags(result ARCH_FLAGS -mcpu=cortex-m33 -mthumb -mfloat-abi=hard) +# +function(pw_get_clang_runtime_env_link_flags OUTPUT_VARIABLE) + pw_parse_arguments( + NUM_POSITIONAL_ARGS + 1 + ONE_VALUE_ARGS + GCC_TOOLCHAIN_PATH + MULTI_VALUE_ARGS + ARCH_FLAGS + ) + + _pw_get_clang_runtime_env_flags(_result --ldflags + GCC_TOOLCHAIN_PATH + ${arg_GCC_TOOLCHAIN_PATH} + ARCH_FLAGS + ${arg_ARCH_FLAGS}) + set(${OUTPUT_VARIABLE} ${_result} PARENT_SCOPE) +endfunction()