cmake_minimum_required(VERSION 3.5) #################################################################################################### #VARIABLES : CMAKE #################################################################################################### #An exhaustive list can be found : https://cmake.org/cmake/help/latest/manual/cmake-variables.7.html set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) # Why ? Because we are using our own Linker so this will prevent Cmake to veryfy cimpilation with his Linker option set(CMAKE_C_COMPILER "/usr/bin/arm-none-eabi-gcc") set(CMAKE_CXX_COMPILER "/usr/bin/arm-none-eabi-g++") set(CMAKE_ASM_COMPILER "/usr/bin/arm-none-eabi-gcc") set(CMAKE_ASM_FLAGS "-x assembler-with-cpp")#The reason that we use arm-none-eabi-gcc is that we will invoke c before the assemly Thus the flags. set(CMAKE_OBJCOPY "/usr/bin/arm-none-eabi-objcopy") #################################################################################################### #PRJECT & LIBRARIES : defined by user and important that it comes after the VARIABLES otherwise the Set varibale will not be used. #################################################################################################### project(refOvenTest ASM C CXX) # do this intead sf declaring languages in the beginning it will prevent loop errors. set(CMAKE_SYSTEM_NAME Generic) set(CMAKE_SYSTEM_PROCESSOR arm) set(CMAKE_CROSSCOMPILING TRUE) set(CMAKE_VERBOSE_MAKEFILE on)#Shoul make print everythign ?? #################################################################################################### #VARIABLES : defined by user #################################################################################################### set(LINKER startup/STM32F042K6Tx_FLASH.ld) set(STARTUP startup/startup_stm32f042x6.s) set(CPU_MCU "-mcpu=cortex-m0") set(EXECUTABLE ${PROJECT_NAME}.out) #################################################################################################### #SOURCES #################################################################################################### # For flags please check https://manned.org/arm-none-eabi-gcc/34fd6095 set(C_SOURCES Src/main.c Src/stm32f0xx_it.c Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_exti.c Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_rcc.c Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_utils.c Src/system_stm32f0xx.c Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_gpio.c Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_pwr.c) set(C_HEADERS Inc/main.h Inc/stm32_assert.h Inc/stm32f0xx_it.h) set(ASM_SOURCES ${STARTUP}) #################################################################################################### #FLAGS #################################################################################################### # For flags please check https://manned.org/arm-none-eabi-gcc/34fd6095 set(C_FLAGS -mthumb #Instruction set : https://stackoverflow.com/questions/10638130/what-is-the-arm-thumb-instruction-set -Wall #Error : If you don't know this one please chek basical compiling -fdata-sections #Optimization : Linker can perform optimizations to improve locality of reference in the instruction space. -fdiagnostics-color=always -ffunction-sections)#Optimization : used with -fdata-sections set(LINKER_FLAGS -mthumb -specs=nano.specs -lc -lm -lnosys -Wl,--gc-sections) #################################################################################################### #COMPILATION #################################################################################################### add_executable(${EXECUTABLE} ${C_SOURCES} ${C_HEADERS} ${ASM_SOURCES}) target_compile_options(${EXECUTABLE} PRIVATE ${CPU_MCU} ${C_FLAGS} $<$:-O -g -gdwarf-2>) target_compile_definitions(${EXECUTABLE} PRIVATE -DUSE_FULL_LL_DRIVER -DSTM32F042x6 -DHSE_VALUE=8000000 -DHSE_STARTUP_TIMEOUT=100 -DLSE_STARTUP_TIMEOUT=5000 -DLSE_VALUE=32768 -DHSI_VALUE=8000000 -DLSI_VALUE=40000 -DVDD_VALUE=3300 -DPREFETCH_ENABLE=1 -DINSTRUCTION_CACHE_ENABLE=0 -DDATA_CACHE_ENABLE=0) target_include_directories(${EXECUTABLE} PRIVATE Inc Drivers/STM32F0xx_HAL_Driver/Inc Drivers/CMSIS/Device/ST/STM32F0xx/Include Drivers/CMSIS/Include) #################################################################################################### #LINKING #################################################################################################### target_link_options(${EXECUTABLE} PRIVATE ${CPU_MCU} -mthumb -specs=nano.specs -T${CMAKE_SOURCE_DIR}/${LINKER} -lc -lm -lnosys -Wl,-Map=${PROJECT_NAME}.map,--cref -Wl,--gc-sections) #################################################################################################### #CUSTOM COMMANDS #################################################################################################### add_custom_command(TARGET ${EXECUTABLE} POST_BUILD COMMAND arm-none-eabi-size ${EXECUTABLE}) add_custom_command(TARGET ${EXECUTABLE} POST_BUILD COMMAND arm-none-eabi-objcopy -O ihex ${EXECUTABLE} ${PROJECT_NAME}.hex COMMAND arm-none-eabi-objcopy -O binary ${EXECUTABLE} ${PROJECT_NAME}.bin) #################################################################################################### #CUSTOM Comments from dev. #################################################################################################### #This is one possible trick to handle the assenbly compiling. #We can't use arm-non-eabi-as because it can onaly hande macros. #So this bizzare Variable makes shure that whne the asembly compiling is called the -x assembler-with-cpp flag is passed #target_compile_options(${EXECUTABLE} PRIVATE # $<$:-x assembler-with-cpp ${ASM_FLAGS}>)