summaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorhathach <[email protected]>2023-06-01 12:36:08 +0700
committerhathach <[email protected]>2023-06-01 12:36:08 +0700
commit19a597bcae11077c3011d78f1a85dc2f1bfcd00f (patch)
treed3bd96b4e1d6078021365a0b1e12193db194712f /hw
parentddc029ce54913fa898c5225a2e87f136a6b81060 (diff)
add lto for cmake
Diffstat (limited to 'hw')
-rw-r--r--hw/bsp/family_support.cmake304
-rw-r--r--hw/bsp/imxrt/family.cmake5
-rw-r--r--hw/bsp/lpc18/family.cmake5
-rw-r--r--hw/bsp/lpc55/family.cmake2
-rw-r--r--hw/bsp/mcx/boards/mcxn947brk/board.cmake2
-rw-r--r--hw/bsp/mcx/family.cmake17
-rw-r--r--hw/bsp/nrf/family.cmake5
7 files changed, 178 insertions, 162 deletions
diff --git a/hw/bsp/family_support.cmake b/hw/bsp/family_support.cmake
index 68a21bc7d..e3f2f45ff 100644
--- a/hw/bsp/family_support.cmake
+++ b/hw/bsp/family_support.cmake
@@ -7,141 +7,145 @@ set(TOP "${CMAKE_CURRENT_LIST_DIR}/../..")
# Default to gcc
if (NOT DEFINED TOOLCHAIN)
- set(TOOLCHAIN gcc)
+ set(TOOLCHAIN gcc)
endif ()
if (NOT FAMILY)
- message(FATAL_ERROR "You must set a FAMILY variable for the build (e.g. rp2040, eps32s2, esp32s3). You can do this via -DFAMILY=xxx on the cmake command line")
+ message(FATAL_ERROR "You must set a FAMILY variable for the build (e.g. rp2040, eps32s2, esp32s3). You can do this via -DFAMILY=xxx on the cmake command line")
endif ()
if (NOT EXISTS ${CMAKE_CURRENT_LIST_DIR}/${FAMILY}/family.cmake)
- message(FATAL_ERROR "Family '${FAMILY}' is not known/supported")
+ message(FATAL_ERROR "Family '${FAMILY}' is not known/supported")
endif()
+
function(family_filter RESULT DIR)
- get_filename_component(DIR ${DIR} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
+ get_filename_component(DIR ${DIR} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
- if (EXISTS "${DIR}/only.txt")
- file(READ "${DIR}/only.txt" ONLYS)
- # Replace newlines with semicolon so that it is treated as a list by CMake
- string(REPLACE "\n" ";" ONLYS_LINES ${ONLYS})
- # For each mcu
- foreach(MCU IN LISTS FAMILY_MCUS)
- # For each line in only.txt
- foreach(_line ${ONLYS_LINES})
- # If mcu:xxx exists for this mcu or board:xxx then include
- if (${_line} STREQUAL "mcu:${MCU}" OR ${_line} STREQUAL "board:${BOARD}")
- set(${RESULT} 1 PARENT_SCOPE)
- return()
- endif()
- endforeach()
- endforeach()
+ if (EXISTS "${DIR}/only.txt")
+ file(READ "${DIR}/only.txt" ONLYS)
+ # Replace newlines with semicolon so that it is treated as a list by CMake
+ string(REPLACE "\n" ";" ONLYS_LINES ${ONLYS})
- # Didn't find it in only file so don't build
- set(${RESULT} 0 PARENT_SCOPE)
+ # For each mcu
+ foreach(MCU IN LISTS FAMILY_MCUS)
+ # For each line in only.txt
+ foreach(_line ${ONLYS_LINES})
+ # If mcu:xxx exists for this mcu or board:xxx then include
+ if (${_line} STREQUAL "mcu:${MCU}" OR ${_line} STREQUAL "board:${BOARD}")
+ set(${RESULT} 1 PARENT_SCOPE)
+ return()
+ endif()
+ endforeach()
+ endforeach()
- elseif (EXISTS "${DIR}/skip.txt")
- file(READ "${DIR}/skip.txt" SKIPS)
- # Replace newlines with semicolon so that it is treated as a list by CMake
- string(REPLACE "\n" ";" SKIPS_LINES ${SKIPS})
- # For each mcu
- foreach(MCU IN LISTS FAMILY_MCUS)
- # For each line in only.txt
- foreach(_line ${SKIPS_LINES})
- # If mcu:xxx exists for this mcu then skip
- if (${_line} STREQUAL "mcu:${MCU}")
- set(${RESULT} 0 PARENT_SCOPE)
- return()
- endif()
- endforeach()
- endforeach()
+ # Didn't find it in only file so don't build
+ set(${RESULT} 0 PARENT_SCOPE)
- # Didn't find in skip file so build
- set(${RESULT} 1 PARENT_SCOPE)
+ elseif (EXISTS "${DIR}/skip.txt")
+ file(READ "${DIR}/skip.txt" SKIPS)
+ # Replace newlines with semicolon so that it is treated as a list by CMake
+ string(REPLACE "\n" ";" SKIPS_LINES ${SKIPS})
- else()
+ # For each mcu
+ foreach(MCU IN LISTS FAMILY_MCUS)
+ # For each line in only.txt
+ foreach(_line ${SKIPS_LINES})
+ # If mcu:xxx exists for this mcu then skip
+ if (${_line} STREQUAL "mcu:${MCU}")
+ set(${RESULT} 0 PARENT_SCOPE)
+ return()
+ endif()
+ endforeach()
+ endforeach()
- # Didn't find skip or only file so build
- set(${RESULT} 1 PARENT_SCOPE)
-
- endif()
+ # Didn't find in skip file so build
+ set(${RESULT} 1 PARENT_SCOPE)
+ else()
+ # Didn't find skip or only file so build
+ set(${RESULT} 1 PARENT_SCOPE)
+ endif()
endfunction()
+
function(family_add_subdirectory DIR)
- family_filter(SHOULD_ADD "${DIR}")
- if (SHOULD_ADD)
- add_subdirectory(${DIR})
- endif()
+ family_filter(SHOULD_ADD "${DIR}")
+ if (SHOULD_ADD)
+ add_subdirectory(${DIR})
+ endif()
endfunction()
+
function(family_get_project_name OUTPUT_NAME DIR)
- get_filename_component(SHORT_NAME ${DIR} NAME)
- set(${OUTPUT_NAME} ${TINYUSB_FAMILY_PROJECT_NAME_PREFIX}${SHORT_NAME} PARENT_SCOPE)
+ get_filename_component(SHORT_NAME ${DIR} NAME)
+ set(${OUTPUT_NAME} ${TINYUSB_FAMILY_PROJECT_NAME_PREFIX}${SHORT_NAME} PARENT_SCOPE)
endfunction()
+
function(family_initialize_project PROJECT DIR)
- family_filter(ALLOWED "${DIR}")
- if (NOT ALLOWED)
- get_filename_component(SHORT_NAME ${DIR} NAME)
- message(FATAL_ERROR "${SHORT_NAME} is not supported on FAMILY=${FAMILY}")
- endif()
+ # set output suffix to .elf
+ set(CMAKE_EXECUTABLE_SUFFIX .elf PARENT_SCOPE)
+
+ family_filter(ALLOWED "${DIR}")
+ if (NOT ALLOWED)
+ get_filename_component(SHORT_NAME ${DIR} NAME)
+ message(FATAL_ERROR "${SHORT_NAME} is not supported on FAMILY=${FAMILY}")
+ endif()
endfunction()
+
function(family_add_default_example_warnings TARGET)
- target_compile_options(${TARGET} PUBLIC
- -Wall
- -Wextra
- -Werror
- -Wfatal-errors
- -Wdouble-promotion
- -Wfloat-equal
- -Wshadow
- -Wwrite-strings
- -Wsign-compare
- -Wmissing-format-attribute
- -Wunreachable-code
- -Wcast-align
- -Wcast-qual
- -Wnull-dereference
- -Wuninitialized
- -Wunused
- -Wredundant-decls
- #-Wstrict-prototypes
- #-Werror-implicit-function-declaration
- #-Wundef
- )
+ target_compile_options(${TARGET} PUBLIC
+ -Wall
+ -Wextra
+ -Werror
+ -Wfatal-errors
+ -Wdouble-promotion
+ -Wfloat-equal
+ -Wshadow
+ -Wwrite-strings
+ -Wsign-compare
+ -Wmissing-format-attribute
+ -Wunreachable-code
+ -Wcast-align
+ -Wcast-qual
+ -Wnull-dereference
+ -Wuninitialized
+ -Wunused
+ -Wredundant-decls
+ #-Wstrict-prototypes
+ #-Werror-implicit-function-declaration
+ #-Wundef
+ )
- if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
- if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0)
- target_link_options(${TARGET} PUBLIC "LINKER:--no-warn-rwx-segments")
- endif()
+ if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
+ if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 12.0)
+ target_link_options(${TARGET} PUBLIC "LINKER:--no-warn-rwx-segments")
+ endif()
- # GCC 10
- if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0)
- target_compile_options(${TARGET} PUBLIC -Wconversion)
- endif()
+ # GCC 10
+ if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0)
+ target_compile_options(${TARGET} PUBLIC -Wconversion)
+ endif()
- # GCC 8
- if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0)
- target_compile_options(${TARGET} PUBLIC -Wcast-function-type -Wstrict-overflow)
- endif()
+ # GCC 8
+ if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0)
+ target_compile_options(${TARGET} PUBLIC -Wcast-function-type -Wstrict-overflow)
+ endif()
- # GCC 6
- if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0)
- target_compile_options(${TARGET} PUBLIC -Wno-strict-aliasing)
- endif()
+ # GCC 6
+ if (CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 6.0)
+ target_compile_options(${TARGET} PUBLIC -Wno-strict-aliasing)
endif()
+ endif()
endfunction()
-function(family_support_configure_common TARGET)
- # set output name to .elf
- set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME ${TARGET}.elf)
-
+function(family_configure_common TARGET)
# run size after build
add_custom_command(TARGET ${TARGET} POST_BUILD
- COMMAND ${TOOLCHAIN_SIZE} $<TARGET_FILE:${TARGET}>
+ COMMAND ${CMAKE_SIZE} $<TARGET_FILE:${TARGET}>
)
# Generate map file
@@ -151,11 +155,15 @@ function(family_support_configure_common TARGET)
)
endfunction()
-# add_custom_command(TARGET ${TARGET} POST_BUILD
-# COMMAND ${CMAKE_OBJCOPY} -O ihex $<TARGET_FILE:${TARGET}> ${TARGET}.hex
-# COMMAND ${CMAKE_OBJCOPY} -O binary $<TARGET_FILE:${TARGET}> ${TARGET}.bin
-# COMMENT "Creating ${TARGET}.hex and ${TARGET}.bin"
-# )
+
+# Add bin/hex output
+function(family_add_bin_hex TARGET)
+ add_custom_command(TARGET ${TARGET} POST_BUILD
+ COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${TARGET}> $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.bin
+ COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${TARGET}> $<TARGET_FILE_DIR:${TARGET}>/${TARGET}.hex
+ VERBATIM)
+endfunction()
+
# Add flash jlink target
function(family_flash_jlink TARGET)
@@ -178,78 +186,84 @@ exit"
)
endfunction()
+
# Add flash pycod target
function(family_flash_pyocd TARGET)
- if (NOT DEFINED PYOC)
- set(PYOCD pyocd)
- endif ()
+ if (NOT DEFINED PYOC)
+ set(PYOCD pyocd)
+ endif ()
- add_custom_target(${TARGET}-pyocd
- DEPENDS ${TARGET}
- COMMAND ${PYOCD} flash -t ${PYOCD_TARGET} $<TARGET_FILE:${TARGET}>
- )
+ add_custom_target(${TARGET}-pyocd
+ DEPENDS ${TARGET}
+ COMMAND ${PYOCD} flash -t ${PYOCD_TARGET} $<TARGET_FILE:${TARGET}>
+ )
endfunction()
+
# Add flash using NXP's LinkServer (redserver)
# https://www.nxp.com/design/software/development-software/mcuxpresso-software-and-tools-/linkserver-for-microcontrollers:LINKERSERVER
function(family_flash_nxplink TARGET)
- if (NOT DEFINED LINKSERVER)
- set(LINKSERVER LinkServer)
- endif ()
+ if (NOT DEFINED LINKSERVER)
+ set(LINKSERVER LinkServer)
+ endif ()
- # LinkServer has a bug that can only execute with full path otherwise it throws:
- # realpath error: No such file or directory
- execute_process(COMMAND which ${LINKSERVER} OUTPUT_VARIABLE LINKSERVER_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
+ # LinkServer has a bug that can only execute with full path otherwise it throws:
+ # realpath error: No such file or directory
+ execute_process(COMMAND which ${LINKSERVER} OUTPUT_VARIABLE LINKSERVER_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
- add_custom_target(${TARGET}-nxplink
- DEPENDS ${TARGET}
- COMMAND ${LINKSERVER_PATH} flash ${NXPLINK_DEVICE} load $<TARGET_FILE:${TARGET}>
- )
+ add_custom_target(${TARGET}-nxplink
+ DEPENDS ${TARGET}
+ COMMAND ${LINKSERVER_PATH} flash ${NXPLINK_DEVICE} load $<TARGET_FILE:${TARGET}>
+ )
endfunction()
+
# configure an executable target to link to tinyusb in device mode, and add the board implementation
function(family_configure_device_example TARGET)
- # default implementation is empty, the function should be redefined in the FAMILY/family.cmake
+ # default implementation is empty, the function should be redefined in the FAMILY/family.cmake
endfunction()
+
# configure an executable target to link to tinyusb in host mode, and add the board implementation
function(family_configure_host_example TARGET)
- # default implementation is empty, the function should be redefined in the FAMILY/family.cmake
+ # default implementation is empty, the function should be redefined in the FAMILY/family.cmake
endfunction()
+
# Add freeRTOS support to example, can be overridden by FAMILY/family.cmake
function(family_add_freertos TARGET)
- # freeros config
- if (NOT TARGET freertos_config)
- add_library(freertos_config INTERFACE)
- target_include_directories(freertos_config SYSTEM INTERFACE
- ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/${FAMILY}/FreeRTOSConfig
- )
- endif()
+ # freeros config
+ if (NOT TARGET freertos_config)
+ add_library(freertos_config INTERFACE)
+ target_include_directories(freertos_config SYSTEM INTERFACE
+ ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/${FAMILY}/FreeRTOSConfig
+ )
+ endif()
- # freertos kernel should be generic as freertos_config however, CMAKE complains with missing variable
- # such as CMAKE_C_COMPILE_OBJECT
- if (NOT TARGET freertos_kernel)
- add_subdirectory(${TOP}/lib/FreeRTOS-Kernel ${CMAKE_BINARY_DIR}/lib/freertos_kernel)
- endif ()
+ # freertos kernel should be generic as freertos_config however, CMAKE complains with missing variable
+ # such as CMAKE_C_COMPILE_OBJECT
+ if (NOT TARGET freertos_kernel)
+ add_subdirectory(${TOP}/lib/FreeRTOS-Kernel ${CMAKE_BINARY_DIR}/lib/freertos_kernel)
+ endif ()
- # Add FreeRTOS option to tinyusb_config
- target_compile_definitions(${TARGET}-tinyusb_config INTERFACE
- CFG_TUSB_OS=OPT_OS_FREERTOS
- )
- # link tinyusb with freeRTOS kernel
- target_link_libraries(${TARGET}-tinyusb PUBLIC
- freertos_kernel
- )
- target_link_libraries(${TARGET} PUBLIC
- freertos_kernel
- )
+ # Add FreeRTOS option to tinyusb_config
+ target_compile_definitions(${TARGET}-tinyusb_config INTERFACE
+ CFG_TUSB_OS=OPT_OS_FREERTOS
+ )
+ # link tinyusb with freeRTOS kernel
+ target_link_libraries(${TARGET}-tinyusb PUBLIC
+ freertos_kernel
+ )
+ target_link_libraries(${TARGET} PUBLIC
+ freertos_kernel
+ )
endfunction()
+
include(${CMAKE_CURRENT_LIST_DIR}/${FAMILY}/family.cmake)
if (NOT FAMILY_MCUS)
- set(FAMILY_MCUS ${FAMILY})
+ set(FAMILY_MCUS ${FAMILY})
endif()
# save it in case of re-inclusion
diff --git a/hw/bsp/imxrt/family.cmake b/hw/bsp/imxrt/family.cmake
index a681b0419..49a4a9281 100644
--- a/hw/bsp/imxrt/family.cmake
+++ b/hw/bsp/imxrt/family.cmake
@@ -4,6 +4,9 @@ if (NOT BOARD)
message(FATAL_ERROR "BOARD not specified")
endif ()
+# enable LTO
+set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
+
# toolchain set up
set(CMAKE_SYSTEM_PROCESSOR cortex-m7 CACHE INTERNAL "System Processor")
set(CMAKE_TOOLCHAIN_FILE ${TOP}/tools/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
@@ -77,7 +80,7 @@ endif () # BOARD_TARGET
# Functions
#------------------------------------
function(family_configure_example TARGET)
- family_support_configure_common(${TARGET})
+ family_configure_common(${TARGET})
#---------- Port Specific ----------
# These files are built for each example since it depends on example's tusb_config.h
diff --git a/hw/bsp/lpc18/family.cmake b/hw/bsp/lpc18/family.cmake
index 698120077..1bfc63d21 100644
--- a/hw/bsp/lpc18/family.cmake
+++ b/hw/bsp/lpc18/family.cmake
@@ -6,6 +6,9 @@ endif ()
set(SDK_DIR ${TOP}/hw/mcu/nxp/lpcopen/lpc18xx/lpc_chip_18xx)
+# enable LTO
+set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
+
# toolchain set up
set(CMAKE_SYSTEM_PROCESSOR cortex-m3 CACHE INTERNAL "System Processor")
set(CMAKE_TOOLCHAIN_FILE ${TOP}/tools/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
@@ -65,7 +68,7 @@ endif () # BOARD_TARGET
# Functions
#------------------------------------
function(family_configure_example TARGET)
- family_support_configure_common(${TARGET})
+ family_configure_common(${TARGET})
#---------- Port Specific ----------
# These files are built for each example since it depends on example's tusb_config.h
diff --git a/hw/bsp/lpc55/family.cmake b/hw/bsp/lpc55/family.cmake
index 77a2b821e..eb163bde7 100644
--- a/hw/bsp/lpc55/family.cmake
+++ b/hw/bsp/lpc55/family.cmake
@@ -89,7 +89,7 @@ endif () # BOARD_TARGET
# Functions
#------------------------------------
function(family_configure_example TARGET)
- family_support_configure_common(${TARGET})
+ family_configure_common(${TARGET})
#---------- Port Specific ----------
# These files are built for each example since it depends on example's tusb_config.h
diff --git a/hw/bsp/mcx/boards/mcxn947brk/board.cmake b/hw/bsp/mcx/boards/mcxn947brk/board.cmake
index b9acf04d9..7a210628f 100644
--- a/hw/bsp/mcx/boards/mcxn947brk/board.cmake
+++ b/hw/bsp/mcx/boards/mcxn947brk/board.cmake
@@ -1,7 +1,7 @@
set(MCU_VARIANT MCXN947)
set(MCU_CORE MCXN947_cm33_core0)
-set(JLINK_DEVICE MCXN947)
+set(JLINK_DEVICE MCXN947_M33_0)
set(PYOCD_TARGET MCXN947)
set(NXPLINK_DEVICE MCXN947:MCXN947)
diff --git a/hw/bsp/mcx/family.cmake b/hw/bsp/mcx/family.cmake
index 1719320e6..d5a17f584 100644
--- a/hw/bsp/mcx/family.cmake
+++ b/hw/bsp/mcx/family.cmake
@@ -7,6 +7,9 @@ endif ()
set(SDK_DIR ${TOP}/hw/mcu/nxp/mcux-sdk)
set(CMSIS_DIR ${TOP}/lib/CMSIS_5)
+# enable LTO
+set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
+
# toolchain set up
set(CMAKE_SYSTEM_PROCESSOR cortex-m33 CACHE INTERNAL "System Processor")
set(CMAKE_TOOLCHAIN_FILE ${TOP}/tools/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
@@ -70,7 +73,7 @@ endif () # BOARD_TARGET
# Functions
#------------------------------------
function(family_configure_example TARGET)
- family_support_configure_common(${TARGET})
+ family_configure_common(${TARGET})
#---------- Port Specific ----------
# These files are built for each example since it depends on example's tusb_config.h
@@ -112,17 +115,7 @@ function(family_configure_example TARGET)
)
#---------- Flash ----------
- # use MCUXpresso GUI Flash Tool to flash the elf
-
-# set(REDLINK_EXE /usr/local/LinkServer/binaries/crt_emu_cm_redlink)
-# add_custom_target(${TARGET}-redlink
-# DEPENDS ${TARGET}
-# COMMAND ${REDLINK_EXE} --flash-load-exec $<TARGET_FILE:${TARGET}> --vendor NXP -p MCXN947 --bootromstall
-# 0x50000040 -CoreIndex=0 --flash-driver= -x ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/flash --flash-dir
-# ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/flash --flash-hashing
-# )
-
- #family_flash_jlink(${TARGET})
+ family_flash_jlink(${TARGET})
#family_flash_nxplink(${TARGET})
#family_flash_pyocd(${TARGET})
endfunction()
diff --git a/hw/bsp/nrf/family.cmake b/hw/bsp/nrf/family.cmake
index 68b19b33b..71067c8ae 100644
--- a/hw/bsp/nrf/family.cmake
+++ b/hw/bsp/nrf/family.cmake
@@ -10,6 +10,9 @@ set(CMSIS_DIR ${TOP}/lib/CMSIS_5)
# include board specific
include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake)
+# enable LTO
+set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
+
# toolchain set up
if (MCU_VARIANT STREQUAL "nrf5340_application")
set(CMAKE_SYSTEM_PROCESSOR cortex-m33 CACHE INTERNAL "System Processor")
@@ -77,7 +80,7 @@ endif () # BOARD_TARGET
# Functions
#------------------------------------
function(family_configure_example TARGET)
- family_support_configure_common(${TARGET})
+ family_configure_common(${TARGET})
#---------- Port Specific ----------
# These files are built for each example since it depends on example's tusb_config.h