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.
121 lines
5.8 KiB
121 lines
5.8 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(CPP_ENTRY_HEADER ${CMAKE_SOURCE_DIR}/nucleo_f042k6)
|
|
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 ??
|
|
set(CSL_DIR csl/stm32f042)
|
|
####################################################################################################
|
|
#VARIABLES : defined by user
|
|
####################################################################################################
|
|
set(LINKER ${CSL_DIR}/startup/STM32F042K6Tx_FLASH.ld)
|
|
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
|
|
####################################################################################################
|
|
|
|
# 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 (CPP_SOURCES cppSrc/transfer.cpp)
|
|
set (CPP_INCLUDES nucleo_f042k6)#${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)
|
|
####################################################################################################
|
|
#SUBDIRECTORIES
|
|
####################################################################################################
|
|
add_subdirectory(csl)
|
|
|
|
####################################################################################################
|
|
#EXECUTABLE
|
|
####################################################################################################
|
|
add_executable(${EXECUTABLE} nucleo_f042k6/bls_nucleo_f042k6.cpp)
|
|
target_compile_options(${EXECUTABLE} PRIVATE ${CPP_FLAGS})
|
|
target_compile_definitions(${EXECUTABLE} PRIVATE ${CPP_DEFS})
|
|
target_include_directories(${EXECUTABLE} PUBLIC ${CPP_INCLUDES})
|
|
|
|
####################################################################################################
|
|
#LINKING EXECUTEABLE
|
|
####################################################################################################
|
|
target_link_libraries(${EXECUTABLE} sub::startup sub::cSources)#${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}>)
|