Skip to content

Commit

Permalink
pw_toolchain: Clang can specify path to gcc toolchain
Browse files Browse the repository at this point in the history
- 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 🤖 <[email protected]>
Commit-Queue: Joshua Goldstein <[email protected]>
Reviewed-by: Ewout van Bekkum <[email protected]>
Pigweed-Auto-Submit: Joshua Goldstein <[email protected]>
Docs-Not-Needed: Joshua Goldstein <[email protected]>
Reviewed-by: Wyatt Hepler <[email protected]>
Presubmit-Verified: CQ Bot Account <[email protected]>
  • Loading branch information
jgoldstn authored and CQ Bot Account committed Jan 6, 2025
1 parent 48c5ba9 commit 628fefa
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions pw_toolchain/arm_clang/clang_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
#
Expand All @@ -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 <path>]
# [ARCH_FLAGS <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:
#
Expand All @@ -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 <path>]
# [ARCH_FLAGS <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()

0 comments on commit 628fefa

Please sign in to comment.