A new CMAKE project is created by writing CMakeLists.txt file.
Adjusting a some project to specific micro-controller and board is made by running CMAKE utility with three commandline parameters.
CMAKE project examples can be found at directories :
Let look CMAKE system running example at the command line –
The next line
give CMAKE a compilation rules file for ARM
describe microcontroller model
sets the board name
sets that program must be located in the FLASH memory see Choosing CMAKE linkage
sets to CMAKE a project generation variant. May be some of them are suitable for you:
additional CMAKE options is set build type Release/Debug
The build variant is set by -DLINKAGE option. There is three build variants:
FLASH – program image located in FLASH, program starts its execution from FLASH, data and some code section (.text.ram_code) is loaded to internal RAM.
RAM – program image located in FLASH, program starts its execution from FLASH, const data section (.rodata) and some code section (.text.rom_code) stay in FALSH, other code sections and data sections is loaded to internal RAM.
ONE_SECT – all program image is located in ONE SECTION, this section located in internal ram by default. But you can set the start and length of this section by using ONE_SEC_START and ONE_SEC_LENGTH variables. \сode -DLINKAGE=ONE_SECT -DONE_SEC_START=0xa0400000 -DONE_SEC_LENGTH=0x10000
Every build type gives its own linker script (FLASH.ld, ONE.ld, RAM.ld).
sets MCU model, makes mcu_id.h file with core type and MCU model definitions.
sets board, also tries to find in bsp floder a file this name EA_v1_1 and makes bsp_board_def.h file with string include "bps_board_EA_v1_1". Also add -D_HASBSPBRD=1 option to compiler.
There is a way to make additional options to compiller. Next example shows how to set optimization option by size.
Also there are options to each language COMMON_C_FLAGS, COMMON_CXX_FLAGS, COMMON_ASM_FLAGS , and COMMON_LD_FLAGS for linker.
Stack pointer is sets to the end of SRAM memory. For more information see linker and runtime asm file.
STARTAP_INIT_STACK_FILE_H variable point to stack size settings file, by default startup_lpc_stack_generic.h.in is used.
Remove -ffunction-sections -fdata-sections compilation options.
set status register value. By default it is MODE_SYS, but if there is TARGET_HAS_RTOS variable the value is set as (MODE_SVC|I_BIT|F_BIT). This masks interrupts before scheduler starts. TARGET_HAS_RTOS variable is set automaticli if there is "FreeRTOSConfig.h" or "iConfig.h" file in the root folder of project or one or two folder level higher.
CMAKE is a lisp-like language. Variables are set by SET command. case ARE not IMPORTANT
Variable value is taken by curly braces like in Bash in opposite of parentheses like in Makefiles. Variables in CMAKE are represented like lists and can hold many elements.
Concatenation operations made in this manner :
CMakeLists.txt file for CMAKE can hold:
There is CMakeLists.txt example in Device/NXP/LPC2xxx/templates/empty_main/cmake
There is CMakeLists.txt example in Device/NXP/Drivers/Examples/UART/Interrupt/GCC_CMAKE
CMAKE system makes some temporary files (CMakeCache.txt, Makefile) and CMakeFiles directory in running directory. CMakeFiles directory is used for building and store all temporary results. Thus all trash files like *.obj, *.o, *.d and so on are NOT stored in main sources directories.
In the process of making project for CodeBlocks all libraries and executables are stored in list of targets automatically. It is a pity but there is no cross-compilation support for CodeBlock project files. That is why it is recommended to copy *.cbp file to *2.cbp and change project compiler from MinGW to ARM after that.