You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
155 lines
6.9 KiB
155 lines
6.9 KiB
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") #This flag is now part of a library 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")
|
|
set(CMAKE_EXE_LINKER_FLAGS "--specs=nosys.specs")
|
|
####################################################################################################
|
|
#PROJECT & 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_CXX_STANDARD 17)
|
|
set(CMAKE_SYSTEM_NAME Generic)
|
|
set(CMAKE_SYSTEM_PROCESSOR arm)
|
|
set(CMAKE_CROSSCOMPILING TRUE)
|
|
set(CMAKE_VERBOSE_MAKEFILE off)#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(C_FUNC c_functions)
|
|
set(CPP_FUNC cpp_functions)
|
|
set(AS_FUNC assembly_functions)
|
|
set(EXECUTABLE ${PROJECT_NAME}.out)
|
|
####################################################################################################
|
|
#SOURCES
|
|
####################################################################################################
|
|
set(C_SOURCES
|
|
Src/stm32f0xx_it.c
|
|
Src/system_stm32f0xx.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
|
|
Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_gpio.c
|
|
Drivers/STM32F0xx_HAL_Driver/Src/stm32f0xx_ll_pwr.c)
|
|
|
|
set (C_INCLUDES
|
|
Inc
|
|
cppSrc
|
|
Drivers/STM32F0xx_HAL_Driver/Inc
|
|
Drivers/CMSIS/Device/ST/STM32F0xx/Include
|
|
Drivers/CMSIS/Include)
|
|
|
|
# For flags please check https://manned.org/arm-none-eabi-gcc/34fd6095
|
|
set(C_FLAGS
|
|
${CPU_MCU}
|
|
-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
|
|
$<$<CONFIG:Debug>:-O -g -gdwarf-2>)
|
|
|
|
set(C_DEFS
|
|
-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)
|
|
|
|
set (AS_SOURCES ${STARTUP})
|
|
set (AS_INCLUDES ${C_INCLUDES})
|
|
set (AS_FLAGS -x assembler-with-cpp ${C_FLAGS})
|
|
set (AS_DEFS ${C_DEFS})
|
|
|
|
set (CPP_SOURCES cppSrc/transfer.cpp)
|
|
set (CPP_INCLUDES ${C_INCLUDES} )
|
|
set (CPP_FLAGS ${C_FLAGS})
|
|
set (CPP_DEFS ${C_DEFS})
|
|
|
|
set(LINKER_FLAGS
|
|
-mthumb
|
|
-specs=nano.specs
|
|
-lc
|
|
-lm
|
|
-lnosys
|
|
-Wl,--gc-sections)
|
|
####################################################################################################
|
|
#LIBRARIES
|
|
####################################################################################################
|
|
add_library(${AS_FUNC} ${AS_SOURCES})
|
|
target_compile_options(${AS_FUNC} PRIVATE ${AS_FLAGS})
|
|
target_compile_definitions(${AS_FUNC} PRIVATE ${AS_DEFS})
|
|
|
|
add_library(${C_FUNC} ${C_SOURCES})
|
|
target_compile_options(${C_FUNC} PRIVATE ${C_FLAGS})
|
|
target_compile_definitions(${C_FUNC} PRIVATE ${C_DEFS})
|
|
target_include_directories(${C_FUNC} PUBLIC ${C_INCLUDES})
|
|
|
|
add_library(${CPP_FUNC} ${CPP_SOURCES})
|
|
target_compile_options(${CPP_FUNC} PRIVATE ${CPP_FLAGS})
|
|
target_compile_definitions(${CPP_FUNC} PRIVATE ${CPP_DEFS})
|
|
target_include_directories(${CPP_FUNC} PUBLIC ${CPP_INCLUDES})
|
|
|
|
#link_directories(cppSrc Inc/)
|
|
#target_link_libraries(${CPP_FUNC} ${C_FUNC})
|
|
#target_link_libraries(${C_FUNC} ${CPP_FUNC})
|
|
|
|
####################################################################################################
|
|
#COMPILATION
|
|
####################################################################################################
|
|
add_executable(${EXECUTABLE} Src/main.c)
|
|
target_compile_options(${EXECUTABLE} PRIVATE ${C_FLAGS})
|
|
target_compile_definitions(${EXECUTABLE} PRIVATE ${C_DEFS})
|
|
target_include_directories(${EXECUTABLE} PUBLIC ${C_INCLUDES})
|
|
####################################################################################################
|
|
#LINKING
|
|
####################################################################################################
|
|
target_link_libraries(${EXECUTABLE} ${AS_FUNC} ${C_FUNC} ${CPP_FUNC})
|
|
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.
|
|
####################################################################################################
|
|
# Link For hheader dependency : https://stackoverflow.com/questions/11216408/cmake-dependencies-headers-between-apps-libraries-in-same-project
|
|
#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
|
|
# $<$<COMPILE_LANGUAGE:ASM>:-x assembler-with-cpp ${ASM_FLAGS}>)
|