Created
November 4, 2021 14:34
-
-
Save pasrom/a16ca09911c837ea23114ed09313f453 to your computer and use it in GitHub Desktop.
cmake'ing code composer studio builds (ARM-CGT-CLANG)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/ti-cgt-clang-toolchain.cmake") | |
set(PROJECT_NAME clang-test.elf) | |
project(${PROJECT_NAME}) | |
set(SYS_CONFIG ${MCU_PLUS_SDK_PATH}/examples/empty/am64x-evm/r5fss0-0_freertos/example.syscfg) | |
set(LINKER_FILE ${MCU_PLUS_SDK_PATH}/examples/empty/am64x-evm/r5fss0-0_freertos/ti-arm-clang/linker.cmd) | |
cmake_minimum_required (VERSION 3.18) | |
function(sys_config_lib LIB_NAME SYS_CONFIG_FILE PDK_PATH) | |
set(SYS_CONFIG_GENERATED_PATH ${CMAKE_BINARY_DIR}/generated CACHE PATH "path to generated sys config files") | |
set(SYS_CONFIG_CMD ${SYS_CONFIG_PATH}/nodejs/node) | |
set(SYS_CONFIG_ARGS ${SYS_CONFIG_PATH}/dist/cli.js --product ${PDK_PATH}/.metadata/product.json --context r5fss0-0 --part Default --package ALV --output generated/ ${SYS_CONFIG_FILE}) | |
set(SYS_CONFIG_GENERATED_C_FILES | |
${SYS_CONFIG_GENERATED_PATH}/ti_board_config.c | |
${SYS_CONFIG_GENERATED_PATH}/ti_board_open_close.c | |
${SYS_CONFIG_GENERATED_PATH}/ti_dpl_config.c | |
${SYS_CONFIG_GENERATED_PATH}/ti_drivers_config.c | |
${SYS_CONFIG_GENERATED_PATH}/ti_drivers_open_close.c | |
${SYS_CONFIG_GENERATED_PATH}/ti_pinmux_config.c | |
${SYS_CONFIG_GENERATED_PATH}/ti_power_clock_config.c | |
) | |
set(SYS_CONFIG_GENERATED_H_FILES | |
${SYS_CONFIG_GENERATED_PATH}/ti_board_config.h | |
${SYS_CONFIG_GENERATED_PATH}/ti_board_open_close.h | |
${SYS_CONFIG_GENERATED_PATH}/ti_dpl_config.h | |
${SYS_CONFIG_GENERATED_PATH}/ti_drivers_config.h | |
${SYS_CONFIG_GENERATED_PATH}/ti_drivers_open_close.h | |
) | |
set(SYS_CONFIG_GENERATED_FILES ${SYS_CONFIG_GENERATED_C_FILES} ${SYS_CONFIG_GENERATED_H_FILES}) | |
add_custom_command(OUTPUT ${SYS_CONFIG_GENERATED_FILES} | |
COMMAND ${SYS_CONFIG_CMD} ${SYS_CONFIG_ARGS} | |
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | |
COMMENT "Generating sys config files" | |
VERBATIM | |
) | |
add_library(${LIB_NAME} | |
${SYS_CONFIG_GENERATED_C_FILES} | |
) | |
endfunction() | |
sys_config_lib(sys_config ${SYS_CONFIG} ${MCU_PLUS_SDK_PATH}) | |
add_executable(${PROJECT_NAME} | |
${MCU_PLUS_SDK_PATH}/examples/empty/am64x-evm/r5fss0-0_freertos/main.c | |
${MCU_PLUS_SDK_PATH}/examples/empty/empty.c | |
) | |
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_DEPENDS "${LINKER_FILE}") | |
include_directories(${PROJECT_NAME} | |
${SYS_CONFIG_GENERATED_PATH} | |
${MCU_PLUS_SDK_PATH}/source | |
${MCU_PLUS_SDK_PATH}/source/kernel/freertos/FreeRTOS-Kernel/include | |
${MCU_PLUS_SDK_PATH}/source/kernel/freertos/portable/TI_ARM_CLANG/ARM_CR5F | |
${MCU_PLUS_SDK_PATH}/source/kernel/freertos/config/am64x/r5f | |
) | |
target_link_directories(${PROJECT_NAME} | |
PRIVATE | |
${MCU_PLUS_SDK_PATH}/source/kernel/freertos/lib | |
${MCU_PLUS_SDK_PATH}/source/drivers/lib | |
${MCU_PLUS_SDK_PATH}/source/board/lib | |
) | |
target_link_libraries(${PROJECT_NAME} | |
freertos.am64x.r5f.ti-arm-clang.release.lib | |
drivers.am64x.r5f.ti-arm-clang.release.lib | |
board.am64x.r5f.ti-arm-clang.release.lib | |
sys_config | |
${TI_CGT_CLANG_ROOT}/lib/libc.a | |
${LINKER_FILE} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this one is important | |
set(CMAKE_SYSTEM_NAME "Generic") | |
include(CMakeForceCompiler) | |
set(TOOLCHAIN_COMPILER_IDENTIFIER "ti-cgt-clang" CACHE STRING "compiler identifier" FORCE) | |
set(CMAKE_C_COMPILER ${TI_CGT_CLANG_ROOT}/bin/tiarmclang) | |
set(CMAKE_CXX_COMPILER ${TI_CGT_CLANG_ROOT}/bin/tiarmclang) | |
set(CMAKE_ASM_COMPILER ${TI_CGT_CLANG_ROOT}/bin/tiarmasm) | |
# Add the default include and lib directories for tool chain | |
set(CMAKE_C_STANDARD_INCLUDE_DIRECTORIES ${TI_CGT_CLANG_ROOT}/include/c) | |
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${TI_CGT_CLANG_ROOT}/include/c++/v1) | |
# Get the ti-clang version | |
execute_process(COMMAND | |
"${CMAKE_C_COMPILER}" --version | |
OUTPUT_VARIABLE _COMPILER_VERSION | |
) | |
message(_COMPILER_VERSION ${_COMPILER_VERSION}) | |
string(REGEX MATCH "[0-9]+.[0-9]+.[0-9]+" | |
MATCHED_VERSION "${_COMPILER_VERSION}") | |
# Set the compiler ID and version | |
foreach (LANG C CXX ASM) | |
set(CMAKE_${LANG}_COMPILER_ID "ti-clang") | |
set(CMAKE_${LANG}_COMPILER_VERSION ${MATCHED_VERSION}) | |
set(CMAKE_${LANG}_COMPILER_ID_RUN TRUE) | |
set(CMAKE_${LANG}_COMPILER_FORCED TRUE) | |
endforeach() | |
# Add target system root to cmake find path | |
get_filename_component(ARM_CLANG_BIN "${TI_CGT_CLANG_ROOT}" DIRECTORY) | |
get_filename_component(CMAKE_FIND_ROOT_PATH "${TI_CGT_CLANG_ROOT}" DIRECTORY) | |
# specifiy target cpu flags | |
IF(PLATFORM_TYPE MATCHES Debug) | |
set (OPTIMIZATION_C_FLAGS "-g") | |
message ("Building for debug") | |
ELSE() | |
set (OPTIMIZATION_C_FLAGS "-O3 -g") | |
message ("Building for release") | |
ENDIF() | |
set(PLATFORM_CONFIG_C_FLAGS "-Wno-gnu-variable-sized-type-not-at-end -Wno-unused-function -c -mcpu=cortex-r5 -mfloat-abi=hard -mfpu=vfpv3-d16 -Wall ${OPTIMIZATION_C_FLAGS} -DSOC_AM64X -MMD") | |
set(PLATFORM_CONFIG_CXX_FLAGS "${PLATFORM_CONFIG_C_FLAGS}") | |
# combine flags to C and C++ flags | |
set(CMAKE_C_FLAGS_INIT "${PLATFORM_CONFIG_C_FLAGS} ${CMAKE_C_FLAGS}") | |
set(CMAKE_CXX_FLAGS_INIT "${PLATFORM_CONFIG_CXX_FLAGS} ${CMAKE_CXX_FLAGS}") | |
set(CMAKE_EXE_LINKER_FLAGS "-Wl,--diag_suppress=10063 -Wl,--ram_model,--reread_libs") | |
set(CMAKE_LIBRARY_PATH_FLAG "-Wl,-i") | |
set(CMAKE_C_LINK_EXECUTABLE "<CMAKE_C_COMPILER> <CMAKE_C_LINK_FLAGS> -Wl,-m=<TARGET>.map <LINK_FLAGS> <OBJECTS> -o <TARGET> <LINK_LIBRARIES>") | |
# add include and libraries path | |
include_directories(${CMAKE_FIND_ROOT_PATH}/include) | |
link_directories(${CMAKE_FIND_ROOT_PATH}/lib) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Download and install to
$HOME/ti
Build instructions:
mkdir build && cd build
cmake .. -DTI_CGT_CLANG_ROOT=$HOME/ti/ti-cgt-armllvm_1.3.0.LTS -DMCU_PLUS_SDK_PATH=$HOME/ti/mcu_plus_sdk_am64x_08_00_00_21 -DSYS_CONFIG_PATH=$HOME/ti/sysconfig_1.8.1
make