Correcting the Linker Flags for CMake - cmake

I am trying to convert an embedded gcc arm- project to use ARMClang instead of GCC.
My focus was to use CMake to automate the task of generating the make files, but I could
not figure out why I can not enforce the linker flags and I always get
following error during build
[ 96%] Building ASM object CMakeFiles/CLION-f103-armclang.elf.dir/startup/startup_stm32f103xb.o
Fatal error: A9912E: No --cpu selected
The contents of my CMakeLists.txt file is as below
#THIS FILE IS AUTO GENERATED FROM THE TEMPLATE! DO NOT CHANGE!
SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_VERSION 1)
cmake_minimum_required(VERSION 3.15)
# specify cross compilers and tools
#SET(CMAKE_C_COMPILER_ID ARMClang)
#SET(CMAKE_CXX_COMPILER_ID ARMClang)
#SET(CMAKE_ASM_COMPILER_ID ARMClang)
SET(TARGET "arm-arm-none-eabi")
SET(CMAKE_C_COMPILER_TARGET ${TARGET})
SET(CMAKE_CXX_COMPILER_TARGET ${TARGET})
SET(CMAKE_ASM_COMPILER_TARGET ${TARGET})
SET(CMAKE_SYSTEM_PROCESSOR Cortex-M3)
SET(CMAKE_C_COMPILER_ID ARMClang)
SET(CMAKE_C_COMPILER_WORKS 1)
SET(CMAKE_C_COMPILER armclang)
SET(CMAKE_CXX_COMPILER_WORKS 1)
SET(CMAKE_CXX_COMPILER armclang)
SET(CMAKE_ASM_COMPILER_WORKS 1)
set(CMAKE_ASM_COMPILER armasm)
#set(CMAKE_AR arm-none-eabi-ar)
#set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
#set(CMAKE_OBJDUMP arm-none-eabi-objdump)
#set(SIZE arm-none-eabi-size)
SET(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32F103RBTx_FLASH.ld)
#Uncomment for hardware floating point
#SET(FPU_FLAGS "-mfloat-abi=hard -mfpu=fpv4-sp-d16")
#add_definitions(-DARM_MATH_CM4 -DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -D__FPU_PRESENT=1)
#Uncomment for software floating point
#SET(FPU_FLAGS "-mfloat-abi=soft")
SET(COMMON_FLAGS
"${FPU_FLAGS} -mthumb -ffunction-sections -fdata-sections \
-g -fno-common -fmessage-length=0")
SET(WARNING_FLAGS "-Wno-packed -Wno-missing-variable-declarations -Wno-missing-prototypes \
-Wno-missing-noreturn -Wno-sign-conversion -Wno-nonportable-include-path \
-Wno-reserved-id-macro -Wno-unused-macros -Wno-documentation-unknown-command \
-Wno-documentation -Wno-license-management -Wno-parentheses-equality")
SET(COMPILER_OPT_FLAGS "-flto -Ofast -ffunction-sections ")
SET(TCPU_FLAGS "--target=arm-arm-none-eabi -mcpu=cortex-m3")
SET(CMAKE_CXX_FLAGS_INIT "${COMMON_FLAGS} ${WARNING_FLAGS} ${COMPILER_OPT_FLAGS} ${TCPU_FLAGS} -std=c++11 -fno-rtti -funsigned-char -fshort-enums -fshort-wchar -gdwarf-3")
SET(CMAKE_C_FLAGS_INIT "${COMMON_FLAGS} ${WARNING_FLAGS} ${COMPILER_OPT_FLAGS} ${TCPU_FLAGS} -std=gnu99 -fno-rtti -flto -funsigned-char -fshort-enums -fshort-wchar -gdwarf-3")
#SET(CMAKE_EXE_LINKER_FLAGS_INIT "--info sizes --info totals --info unused --info veneers -g --lto -Wl,-gc-sections,--print-memory-usage -T ${LINKER_SCRIPT}")
SET(CMAKE_EXE_LINKER_FLAGS_INIT "--info sizes --info totals --cpu Cortex-M3\
--info unused --info veneers -g\
--lto -gc-sections,--print-memory-usage\
-T ${LINKER_SCRIPT}" CACHE INTERNAL "" FORCE)
PROJECT(CLION-f103-armclang C CXX ASM)
set(CMAKE_CXX_STANDARD 11)
#add_definitions(-DARM_MATH_CM4 -DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -D__FPU_PRESENT=1)
add_definitions(-D__weak=__attribute__\(\(weak\)\) -D__packed=__attribute__\(\(__packed__\)\) -DUSE_HAL_DRIVER -DSTM32F103xB)
file(GLOB_RECURSE SOURCES "startup/*.*" "Drivers/*.*" "Core/*.*")
include_directories(Core/Inc Drivers/STM32F1xx_HAL_Driver/Inc Drivers/STM32F1xx_HAL_Driver/Inc/Legacy Drivers/CMSIS/Device/ST/STM32F1xx/Include Drivers/CMSIS/Include)
add_executable(${PROJECT_NAME}.elf ${SOURCES} ${LINKER_SCRIPT})
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS_INIT} -Wl,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map" CACHE INTERNAL "" FORCE)
set(HEX_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex)
set(BIN_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin)
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
COMMENT "Building ${HEX_FILE}
Building ${BIN_FILE}")
Firstly what are the necessary changes for the CMakeLists.txt file to make the script to build and link properly!?
Secondly how to make the linker output flags looks like following as much as possible.
--cpu Cortex-M3 -g
-I.\RTE\_stm32f103rbt6-LCD-CubeMX
-IC:\Users\U1\AppData\Local\Arm\Packs\ARM\CMSIS\5.5.1\CMSIS\Core\Include
-IC:\Users\U1\AppData\Local\Arm\Packs\Keil\STM32F1xx_DFP\2.3.0\Device\Include
--pd "__UVISION_VERSION SETA 528"
--pd "_RTE_ SETA 1"
--pd "STM32F10X_MD SETA 1"
--list *.lst
--xref -o stm32f103rbt6-LCD-CubeMX\*.o
--depend stm32f103rbt6-LCD-CubeMX\*.d
Any help is really appreciated

Related

cmake extract substring from variable

I have variable CC_OPTIONS has value set like below
-arch arm64 -mcpu=abc1 -c --debug -O2 -static -fstack-protector -ffreestanding -nostartfiles -std=c11
I wanted to extract -mcpu=abc1 from CC_OPTIONS
Tried below approach, but getting more than what i wanted.
string(REGEX REPLACE ".*mcpu=(.*)\ .*" "\\1" CPU_TYPE "${CC_OPTIONS}")
any suggestions?
If you use if(MATCHES) you can get character groups of the match using CMAKE_MATCH_<n>
set(MY_VAR "-arch arm64 -mcpu=abc1 -c --debug -O2 -static -fstack-protector -ffreestanding -nostartfiles -std=c11")
if (MY_VAR MATCHES "^([^ ]+ +)*(-mcpu=[^ ]+)( +[^ ]+)*$")
message(STATUS "Found match: ${CMAKE_MATCH_2}")
else()
message(FATAL_ERROR "mismatch")
endif()
Like that:
cmake_minimum_required (VERSION 2.8.11)
project (HELLO)
set(CC_OPTIONS "-arch arm64 -mcpu=abc1 -c --debug -O2 -static -fstack-protector -ffreestanding -nostartfiles -std=c11")
message(${CC_OPTIONS})
string(REGEX MATCH "\\-mcpu=[^ $]+" CPU_TYPE ${CC_OPTIONS})
message(${CPU_TYPE})
Example:
$ cmake .
-arch arm64 -mcpu=abc1 -c --debug -O2 -static -fstack-protector -ffreestanding -nostartfiles -std=c11
-mcpu=abc1
-- Configuring done
-- Generating done
-- Build files have been written to: /home/ja/cmake

CMake Assembler error "No such instruction"

I am moving an already existing project from Atmel Studio 7.0 with arm-gnu toolchain to CMake with MinGW generator.
I have configured the CXX and C compiler flags as follows:
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-D__SAMD21G18A__ -DARM_MATH_CM0 -DF_CPU=48000000L -DARDUINO=10808 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD -DUSB_VID=0x239A -DUSB_PID=0x800B -DUSB_PRODUCT="\"Feather M0\"" -DUSB_MANUFACTURER="\"Adafruit\"" -DUSBCON -DDEBUG -DDEBUG_PRINT -DADAFRUIT_FONA_DEBUG -DMQTT_DEBUG -DMQTT_ERROR -ffunction-sections -fno-rtti -fno-exceptions -mlong-calls -Wall -Wa -mcpu=cortex-m0plus -std=gnu99")
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} "-x c D__SAMD21G18A__ -DARM_MATH_CM0 -DF_CPU=48000000L -DARDUINO=10808 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD -DUSB_VID=0x239A -DUSB_PID=0x800B -DUSB_PRODUCT="\"Feather M0\"" -DUSB_MANUFACTURER="\"Adafruit\"" -DUSBCON -DDEBUG -DDEBUG_PRINT -DADAFRUIT_FONA_DEBUG -DMQTT_DEBUG -DMQTT_ERROR -ffunction-sections -mlong-calls -Wall -mcpu=cortex-m0plus -Wa-c -std=gnu99")
Here is the exact verbose command that generates the error.
:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\build --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_progress_start C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\build\CMakeFiles C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\build\\CMakeFiles\progress.marks
C:/ProgramData/chocolatey/lib/make/tools/install/bin/make.exe -f CMakeFiles\Makefile2 all
make[1]: Entering directory 'C:/svn/ATSAMD21_FLowTube_CMAKE/uart2lte/build'
C:/ProgramData/chocolatey/lib/make/tools/install/bin/make.exe -f Library\CMakeFiles\Library.dir\build.make Library/CMakeFiles/Library.dir/depend
make[2]: Entering directory 'C:/svn/ATSAMD21_FLowTube_CMAKE/uart2lte/build'
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\Library C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\build C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\build\Library C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\build\Library\CMakeFiles\Library.dir\DependInfo.cmake --color=
make[2]: Leaving directory 'C:/svn/ATSAMD21_FLowTube_CMAKE/uart2lte/build'
C:/ProgramData/chocolatey/lib/make/tools/install/bin/make.exe -f Library\CMakeFiles\Library.dir\build.make Library/CMakeFiles/Library.dir/build
make[2]: Entering directory 'C:/svn/ATSAMD21_FLowTube_CMAKE/uart2lte/build'
[ 1%] Building CXX object Library/CMakeFiles/Library.dir/src/Adafruit_SleepyDog/utility/WatchdogSAMD.cpp.obj
cd /d C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\build\Library && C:\MinGW\bin\g++.exe #CMakeFiles/Library.dir/includes_CXX.rsp -march=native -mno-avx -D__SAMD21G18A__ -DARM_MATH_CM0 -DF_CPU=48000000L -DARDUINO=10808 -DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD -DUSB_VID=0x239A -DUSB_PID=0x800B -DUSB_PRODUCT=;"Feather;M0"" -DUSB_MANUFACTURER=""Adafruit"" -DUSBCON -DDEBUG -DDEBUG_PRINT -DADAFRUIT_FONA_DEBUG -DMQTT_DEBUG -DMQTT_ERROR -ffunction-sections -fno-rtti -fno-exceptions -mlong-calls -Wall -Wa -mcpu=cortex-m0plus -std=gnu99" -o CMakeFiles\Library.dir\src\Adafruit_SleepyDog\utility\WatchdogSAMD.cpp.obj -c C:\svn\ATSAMD21_FLowTube_CMAKE\uart2lte\Library\src\Adafruit_SleepyDog\utility\WatchdogSAMD.cpp
C:\Users\rajusa\AppData\Local\Temp\ccAWF2FJ.s: Assembler messages:
C:\Users\rajusa\AppData\Local\Temp\ccAWF2FJ.s:47: Error: number of operands mismatch for `ds'
C:\Users\rajusa\AppData\Local\Temp\ccAWF2FJ.s:53: Error: no such instruction: `isb 0xF'
C:\Users\rajusa\AppData\Local\Temp\ccAWF2FJ.s:527: Error: number of operands mismatch for `ds'
C:\Users\rajusa\AppData\Local\Temp\ccAWF2FJ.s:533: Error: no such instruction: `wfi'
Any idea what might be the reason - in terms of toolchain - assembler ? Is there any way to specify assembler flags in CMake?
You're using MinGW GCC, which essentially targets Windows.
So I don't believe you can target other platforms..
What you need is a GCC compiler that runs on windows that supports the target platform(s) you need.
For Atmel ARM you can try something like this: http://winavr.sourceforge.net/ (though maybe something more recent may exist).

MinGW+cmake on Windows 10 produce error: '__MINGW_EXTENSION' does not name a type

I have spent long time developing C/C++ under Linux, now I'm trying to port/compile my project under windows where I have no experinece. I want to keep the workflow as close to Linux as possible so I go with g++/MinGW and cmake.
When I do standard approach
cd Build
cmake .. -G "MinGW Makefiles"
make
I got tons of following errors:
PS D:\git\SimpleSimulationEngine\cpp\Build> make VERBOSE=1
"C:\Program Files\CMake\bin\cmake.exe" -SD:\git\SimpleSimulationEngine\cpp -BD:\git\SimpleSimulationEngine\cpp\Build --check-build-system CMakeFiles\Makefile.cmake 0
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_progress_start D:\git\SimpleSimulationEngine\cpp\Build\CMakeFiles D:\git\SimpleSimulationEngine\cpp\Build\\CMakeFiles\progress.marks
C:/MinGW/bin/make -f CMakeFiles\Makefile2 all
make[1]: Entering directory 'D:/git/SimpleSimulationEngine/cpp/Build'
C:/MinGW/bin/make -f common\algorithms\CMakeFiles\algorithms.dir\build.make common/algorithms/CMakeFiles/algorithms.dir/depend
make[2]: Entering directory 'D:/git/SimpleSimulationEngine/cpp/Build'
"C:\Program Files\CMake\bin\cmake.exe" -E cmake_depends "MinGW Makefiles" D:\git\SimpleSimulationEngine\cpp D:\git\SimpleSimulationEngine\cpp\common\algorithms D:\git\SimpleSimulationEngine\cpp\Build D:\git\SimpleSimulationEngine\cpp\Build\common\algorithms D:\git\SimpleSimulationEngine\cpp\Build\common\algorithms\CMakeFiles\algorithms.dir\DependInfo.cmake --color=
make[2]: Leaving directory 'D:/git/SimpleSimulationEngine/cpp/Build'
C:/MinGW/bin/make -f common\algorithms\CMakeFiles\algorithms.dir\build.make common/algorithms/CMakeFiles/algorithms.dir/build
make[2]: Entering directory 'D:/git/SimpleSimulationEngine/cpp/Build'
[ 1%] Building CXX object common/algorithms/CMakeFiles/algorithms.dir/main.cpp.obj
cd /d D:\git\SimpleSimulationEngine\cpp\Build\common\algorithms && C:\MinGW\bin\g++.exe #CMakeFiles/algorithms.dir/includes_CXX.rsp -Wall -std=c++17 -g -Og -fPIC -fno-strict-aliasing -Wno-maybe-uninitialized -Wno-char-subscripts -Wno-write-strings -Wno-format -Wno-parentheses -Wno-unused-but-set-variable -Wno-narrowing -Wno-unused-result -Wno-sign-compare -Wno-strict-aliasing -Wno-unused-variable -Wno-unused-value -Wno-comment -Wno-misleading-indentation -Werror=return-type -o CMakeFiles\algorithms.dir\main.cpp.obj -c D:\git\SimpleSimulationEngine\cpp\common\algorithms\main.cpp
In file included from c:\mingw\x86_64-w64-mingw32\include\stdlib.h:9:0,
from c:\mingw\include\c++\6.1.0\cstdlib:75,
from D:/git/SimpleSimulationEngine/cpp/common/utils/testUtils.h:6,
from D:\git\SimpleSimulationEngine\cpp\common\algorithms\main.cpp:2:
c:\mingw\x86_64-w64-mingw32\include\crtdefs.h:35:1: error: '__MINGW_EXTENSION' does not name a type
__MINGW_EXTENSION typedef unsigned __int64 size_t;
^~~~~~~~~~~~~~~~~
c:\mingw\x86_64-w64-mingw32\include\crtdefs.h:45:1: error: '__MINGW_EXTENSION' does not name a type
__MINGW_EXTENSION typedef __int64 ssize_t;
^~~~~~~~~~~~~~~~~
c:\mingw\x86_64-w64-mingw32\include\crtdefs.h:52:9: error: 'size_t' does not name a type
typedef size_t rsize_t;
^~~~~~
c:\mingw\x86_64-w64-mingw32\include\crtdefs.h:62:1: error: '__MINGW_EXTENSION' does not name a type
__MINGW_EXTENSION typedef __int64 intptr_t;
^~~~~~~~~~~~~~~~~
c:\mingw\x86_64-w64-mingw32\include\crtdefs.h:75:1: error: '__MINGW_EXTENSION' does not name a type
__MINGW_EXTENSION typedef unsigned __int64 uintptr_t;
I'm not sure my MinGW environment and libraries are setup properly, since I tried some older minGW version before, than I reinstalled it. Also I have installed MSYS2 in an atempt to install GLEW. But I do not use MSYS2 now, I use some stand alone instalation of MinGW and cmake.
There is nothing special in my CMakeLists.txt
cmake_minimum_required ( VERSION 2.8 )
project ( SimpleSimulationEngine )
set(default_build_type Release)
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++17" )
SET( IGNORE_WARRNING_FLAGS "-Wno-maybe-uninitialized -Wno-char-subscripts -Wno-write-strings -Wno-format -Wno-parentheses -Wno-unused-but-set-variable -Wno-narrowing -Wno-unused-result -Wno-sign-compare -Wno-strict-aliasing -Wno-unused-variable -Wno-unused-value -Wno-comment -Wno-misleading-indentation " )
SET( WARRNING_TO_ERROR "-Werror=return-type")
SET( AXULIARY_COMPILE_FLAGS "-g -Og -fPIC -fno-strict-aliasing ")
SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${AXULIARY_COMPILE_FLAGS} ${IGNORE_WARRNING_FLAGS}
message ( "CMAKE_CXX_FLAGS " ${CMAKE_CXX_FLAGS} )
When I check my environment variables/path there does not seem to be anything fishy (like two versions of MinGW)

Error compiling freertos for nucleo stm32f767

I have generated code using cubeMX and while compiling it gives me the following errors. I have already tried several fixes but none of them is working.
/tmp/ccvxTV8U.s: Assembler messages:
/tmp/ccvxTV8U.s:758: Error: selected processor does not support `vstmdbeq r0!,{s16-s31}' in Thumb mode
/tmp/ccvxTV8U.s:760: Error: instruction not allowed in IT block -- `stmdb r0!,{r4-r11,r14}'
/tmp/ccvxTV8U.s:782: Error: selected processor does not support `vldmiaeq r0!,{s16-s31}' in Thumb mode
/tmp/ccvxTV8U.s:784: Error: instruction not allowed in IT block -- `msr psp,r0'
CMakeLists.txt
IDE: CLion 2019.3
#THIS FILE IS AUTO GENERATED FROM THE TEMPLATE! DO NOT CHANGE!
SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_VERSION 1)
cmake_minimum_required(VERSION 3.13)
# specify cross compilers and tools
SET(CMAKE_C_COMPILER_WORKS 1)
SET(CMAKE_C_COMPILER arm-none-eabi-gcc)
SET(CMAKE_CXX_COMPILER_WORKS 1)
SET(CMAKE_CXX_COMPILER arm-none-eabi-g++)
set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)
set(CMAKE_AR arm-none-eabi-ar)
set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
set(CMAKE_OBJDUMP arm-none-eabi-objdump)
set(SIZE arm-none-eabi-size)
SET(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32F767ZITx_FLASH.ld)
#Uncomment for hardware floating point
SET(FPU_FLAGS "-mfloat-abi=hard -mfpu=fpv4-sp-d16")
add_definitions(-DARM_MATH_CM4 -DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -D__FPU_PRESENT=1)
#Uncomment for software floating point
#SET(FPU_FLAGS "-mfloat-abi=soft")
SET(COMMON_FLAGS
"-mcpu=cortex-m7 ${FPU_FLAGS} -mthumb -mthumb-interwork -ffunction-sections -fdata-sections \
-g -fno-common -fmessage-length=0 -specs=nosys.specs -specs=nano.specs")
SET(CMAKE_CXX_FLAGS_INIT "${COMMON_FLAGS} -std=c++11")
SET(CMAKE_C_FLAGS_INIT "${COMMON_FLAGS} -std=gnu99")
SET(CMAKE_EXE_LINKER_FLAGS_INIT "-Wl,-gc-sections,--print-memory-usage -T ${LINKER_SCRIPT}")
PROJECT(freertos_test C CXX ASM)
set(CMAKE_CXX_STANDARD 11)
#add_definitions(-DARM_MATH_CM4 -DARM_MATH_MATRIX_CHECK -DARM_MATH_ROUNDING -D__FPU_PRESENT=1)
add_definitions(-D__weak=__attribute__\(\(weak\)\) -D__packed=__attribute__\(\(__packed__\)\) -DUSE_HAL_DRIVER -DSTM32F767xx)
file(GLOB_RECURSE SOURCES "Middlewares/*.*" "startup/*.*" "Drivers/*.*" "Core/*.*")
include_directories(Core/Inc Drivers/STM32F7xx_HAL_Driver/Inc Drivers/STM32F7xx_HAL_Driver/Inc/Legacy Drivers/CMSIS/Device/ST/STM32F7xx/Include Drivers/CMSIS/Include Middlewares/Third_Party/FreeRTOS/Source/include Middlewares/Third_Party/FreeRTOS/Source/CMSIS_RTOS Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM7/r0p1)
add_executable(${PROJECT_NAME}.elf ${SOURCES} ${LINKER_SCRIPT})
set(CMAKE_EXE_LINKER_FLAGS
"${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map")
set(HEX_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex)
set(BIN_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin)
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
COMMENT "Building ${HEX_FILE}
Building ${BIN_FILE}")
I'm using the NUCLEO-F767ZI with a STM32F767
file(GLOB_RECURSE SOURCES "Middlewares/*.*"
You are compiling FreeRTOS for all possible implementations for all possible cpus, so you are also compiling sources not compatible at all with your current cpu. You should compile sources only for your destination cpu.
That would most probably be, assuming the folder Middlewares is taken from cubemx:
file(GLOB src1
Middlewares/Third_Party/FreeRTOS/Source/portable/GCC/ARM_CM4F/*.c
Middlewares/Third_Party/FreeRTOS/Source/*.c
)
And add only the needed include path:
target_include_directories(YOUR_TARGET PUBLIC
Middlewares/Third_Party/FreeRTOS/Source/include
)

From makefile to Cmake - stm32

I would like to test CLion for my stm32 project since it now support remote debugging! To do so I need to setup Cmake for my project and it is my issue.
I tried using this link which seems to be depreciated so I made some changes. It almost builds but there is a problem with the .elf .bin .hex.
CMakeLists.txt:
project(F466cmake)
cmake_minimum_required(VERSION 3.10)
add_definitions(-DSTM32F446xx)
file(GLOB_RECURSE USER_SOURCES "Src/*.c")
file(GLOB_RECURSE HAL_SOURCES "Drivers/STM32F4xx_HAL_Driver/Src/*.c")
add_library(CMSIS
Drivers/CMSIS/Device/Src/system_stm32f4xx.c
Drivers/CMSIS/Device/Src/startup_stm32f446xx.s)
include_directories(Inc)
include_directories(Drivers/STM32F4xx_HAL_Driver/Inc)
include_directories(Drivers/CMSIS/Inc)
include_directories(Drivers/CMSIS/Device/Inc)
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32F446RETx_FLASH.ld)
set(COMMON_FLAGS "-mcpu=cortex-m4 -mthumb -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -g -fno-common -fmessage-length=0")
set(CMAKE_CXX_FLAGS "${COMMON_FLAGS} -std=c++11")
set(CMAKE_C_FLAGS "${COMMON_FLAGS} -std=gnu99")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-gc-sections -T ${LINKER_SCRIPT}")
add_executable(${PROJECT_NAME}.elf ${USER_SOURCES} ${HAL_SOURCES} ${LINKER_SCRIPT})
target_link_libraries(${PROJECT_NAME}.elf CMSIS)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.map")
set(HEX_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.hex)
set(BIN_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.bin)
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
COMMENT "Building ${HEX_FILE} \nBuilding ${BIN_FILE}")
terminal output:
[ 95%] Building C object CMakeFiles/F466cmake.elf.dir/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c.o
[100%] Linking C executable F466cmake.elf
/home/flo/bin/gcc-arm-none-eabi-7-2018-q2-update/bin/../lib/gcc/arm-none-eabi/7.3.1/../../../../arm-none-eabi/bin/ld: warning: cannot find entry symbol Reset_Handler; defaulting to 0000000008000000
Building /home/flo/STM32Cube/Testing/build/F466cmake.hex
Building /home/flo/STM32Cube/Testing/build/F466cmake.bin
/usr/bin/objcopy: Unable to recognise the format of the input file `/home/flo/STM32Cube/Testing/build/F466cmake.elf'
CMakeFiles/F466cmake.elf.dir/build.make:563: recipe for target 'F466cmake.elf' failed
make[2]: *** [F466cmake.elf] Error 1
make[2]: *** Deleting file 'F466cmake.elf'
CMakeFiles/Makefile2:104: recipe for target 'CMakeFiles/F466cmake.elf.dir/all' failed
make[1]: *** [CMakeFiles/F466cmake.elf.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
Got it to work, thanks to Chris for the guidance. The issue was the ASM was not build and I had to link arm object copy.
CMakeLists.txt:
project(F466cmake C ASM)
cmake_minimum_required(VERSION 3.10)
add_definitions(-DSTM32F446xx)
file(GLOB_RECURSE USER_SOURCES "Src/*.c")
file(GLOB_RECURSE HAL_SOURCES "Drivers/STM32F4xx_HAL_Driver/Src/*.c")
add_library(CMSIS
Drivers/CMSIS/Device/Src/system_stm32f4xx.c)
add_library(STARTUP
Drivers/CMSIS/Device/Src/startup_stm32f446xx.s)
set_source_files_properties(Drivers/CMSIS/Device/Src/startup_stm32f446xx.s PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp")
set_property(SOURCE Drivers/CMSIS/Device/Src/startup_stm32f446xx.s PROPERTY LANGUAGE C)
include_directories(Inc)
include_directories(Drivers/STM32F4xx_HAL_Driver/Inc)
include_directories(Drivers/CMSIS/Inc)
include_directories(Drivers/CMSIS/Device/Inc)
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
set(OBJCOPY arm-none-eabi-objcopy)
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/STM32F446RETx_FLASH.ld)
set(COMMON_FLAGS "-mcpu=cortex-m4 -mthumb -mthumb-interwork -mfloat-abi=hard -mfpu=fpv4-sp-d16 -ffunction-sections -fdata-sections -g -fno-common -fmessage-length=0")
set(CMAKE_CXX_FLAGS "${COMMON_FLAGS} -std=c++11")
set(CMAKE_C_FLAGS "${COMMON_FLAGS} -std=gnu99")
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-gc-sections -T ${LINKER_SCRIPT}")
add_executable(${PROJECT_NAME}.elf ${USER_SOURCES} ${HAL_SOURCES} ${LINKER_SCRIPT})
target_link_libraries(${PROJECT_NAME}.elf CMSIS STARTUP)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.map")
set(HEX_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.hex)
set(BIN_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.bin)
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
COMMAND ${OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE}
COMMAND ${OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE}
COMMENT "Building ${HEX_FILE} \nBuilding ${BIN_FILE}")