Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
628f64328This file is pinned to the selected release. Download the original to open it in your design tool.
# Build using clang cross-platform with include files generated by CubeMX
cmake_minimum_required(VERSION 3.10)
project(INCLUDE_WHAT_YOU_USE)
# Add a macro definition to specify the exact device (STM32F103xB)
add_compile_definitions(STM32F103xB) # Defining the device macro
# Set sysroot to point to ARM toolchain libraries and headers
# for cross-compiling with the arm-none-eabi toolchain
# root@a602654ae0a9:/workspace/build# find /usr -name stdint.h | grep arm-none-eabi
# /usr/lib/gcc/arm-none-eabi/9.2.1/include/stdint.h
set(CMAKE_SYSROOT "/usr/lib/gcc/arm-none-eabi/9.2.1")
# Add newlib C++ standard library headers to the include directories
# root@a602654ae0a9:/workspace/build# find /usr -name cstdint
# /usr/include/newlib/c++/9.2.1/tr1/cstdint
# /usr/include/newlib/c++/9.2.1/cstdint
# /usr/include/c++/9/tr1/cstdint
# /usr/include/c++/9/cstdint
include_directories("/usr/include/newlib/c++/9.2.1")
# Add the path to the ARM-specific newlib C++ headers
# root@a602654ae0a9:/workspace/build# find /usr -name c++config.h
include_directories("/usr/include/newlib/c++/9.2.1/arm-none-eabi/thumb/v7-m/nofp")
# Include STM32 HAL headers
include_directories("${CMAKE_SOURCE_DIR}/STM32F103RBTx/Drivers/STM32F1xx_HAL_Driver/Inc/")
include_directories("${CMAKE_SOURCE_DIR}/STM32F103RBTx/Middlewares/Third_Party/FatFs/src/")
message(STATUS "${CMAKE_SOURCE_DIR}/STM32F103RBTx/Drivers/STM32F1xx_HAL_Driver/Inc/")
# Compiler flags for ARM Cortex-M3 with the arm-none-eabi toolchain
set(TARGET_FLAGS "--target=arm-none-eabi -mcpu=cortex-m3 -mthumb")
# Set the compiler and linker flags globally
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TARGET_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TARGET_FLAGS}")
# Check if include-what-you-use (IWYU) is available
find_program(IWYU_PATH NAMES include-what-you-use iwyu)
# If IWYU is found, set up IWYU to be used during the build
if(IWYU_PATH)
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "${IWYU_PATH}")
message(STATUS "include-what-you-use (IWYU) found at: ${IWYU_PATH}")
# Add the subdirectory for the application
add_subdirectory(STM32F103RBTx/Application)
else()
message(WARNING "include-what-you-use (IWYU) not found!")
endif()