From makefile to Cmake - stm32 - cmake

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}")

Related

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).

Correcting the Linker Flags for 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

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
)

Android Studio NDK iostream file not found and does not able to enable neon in CMakeList

I am new on using NDK and CMake, and got the problem when I compiled my C++ library, Android studio keeps compiling that
Error:(28, 2) error: "NEON support not enabled"
Error:error: 'neon_vector_type' attribute is not supported for this
target
Error:(17, 10) fatal error: 'iostream' file not found
I have see some solution saying that I should add APP_STL := stlport_static in Application.mk
However, I am using CMakeLists instead of Application.mk.
So I added -DANDROID_ARM_NEON=TRUE -DAPP_STL=stlport_static on CMAKE_C_FLAGS, but it still produce the same error
This is my CMakeLists
set (pathToProject /home/user/project)
set (pathToOpenCv /home/user/project/OpenCV330)
FILE(GLOB_RECURSE cppfiles src/main/cpp/src/*)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED on)
find_package(OpenMP)
add_definitions(-fPIC)
add_definitions(-fopenmp)
add_definitions(-Ofast)
add_definitions(-DANDROID_STL=c++_shared)
add_definitions(-flax-vector-conversions)
add_definitions(-fopenmp)
cmake_minimum_required(VERSION 3.4.1)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fpermissive -DANDROID_ARM_NEON=TRUE -DAPP_STL=stlport_static")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
include_directories(${pathToProject}/app/src/main/cpp/src/include)
include_directories(${pathToOpenCv}/sdk/native/jni/include)
add_library(lib_opencv SHARED IMPORTED)
add_library(native-lib SHARED src/main/cpp/native-lib.cpp )
add_library(mylibrary SHARED ${cppfiles} )
set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${pathToProject}/app/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so)
find_library(log-lib log)
target_link_libraries(
native-lib
${log-lib}
lib_opencv
mylibrary
)
Updated:
I also found 1 more compiling message, looks like the -std=c++11 is not actually applied while compiling
[10/11] Building CXX object CMakeFiles/mylibrary.dir/src/main/cpp/src/yuv420sp.cpp.o
FAILED: /home/user/Downloads/android-ndk-r14b/toolchains/llvm/prebuilt/linux-x86_64/bin/clang --target=i686-none-linux-android --gcc-toolchain=/home/user/Downloads/android-ndk-r14b/toolchains/x86-4.9/prebuilt/linux-x86_64 --sysroot=/home/user/Downloads/android-ndk-r14b/platforms/android-24/arch-x86 -Dmylibrary_EXPORTS -I../../../../src/main/cpp/include -I/home/user/git/project/OpenCV-android-sdk3.3.0/sdk/native/jni/include -I../../../../src/main/cpp/build/include -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -Wa,--noexecstack -Wformat -Werror=format-security -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -Wa,--noexecstack -Wformat -Werror=format-security -O0 -fno-limit-debug-info -O0 -fno-limit-debug-info -fPIC -MD -MT CMakeFiles/mylibrary.dir/src/main/cpp/src/object_wrap.c.o -MF CMakeFiles/mylibrary.dir/src/main/cpp/src/object_wrap.c.o.d -o CMakeFiles/mylibrary.dir/src/main/cpp/object_wrap.c.o -c /home/user/git/project/app/src/main/cpp/object_wrap.c
In file included from /home/user/git/project/app/src/main/cpp/src/object_wrap.c:209:
/home/user/git/project/app/src/main/cpp/src/object.h:17:10: fatal error: 'iostream' file not found
#include <iostream>
^
Also tried to set the flag in app gradle, still not working
externalNativeBuild {
cmake {
cppFlags "-std=c++11", "-Wno-error=format-security"
arguments "-DANDROID_STL=gnustl_static", "-DANDROID_ARM_NEON=TRUE"
}
}
if I set -DANDROID_STL=stlport_static, it will give two more error
Error:(25, 10) fatal error: 'thread' file not found
Error:(424, 14) fatal error: 'array' file not found
After changing the to gcc toolchain in gradle, problem solved.
arguments "-DANDROID_TOOLCHAIN=gcc","-DANDROID_ARM_NEON=TRUE" ,"-DANDROID_STL_FORCE_FEATURES=OFF"
cppFlags "-std=gnu++11", "-Wno-error=format-security"

cmake package_search_module for glfw3 finds package, doesn't supply full lib path

This seems pretty straightforward but I'm wasting enormous amounts of time getting it working. I just want to build and link a main.cpp file that includes glfw3.h, but cmake is not seeing the lib path for GLFW. the call to package_search_module is providing the right include dir, but the resulting GLFW_LIBRARIES value only has the lib name 'glfw3' in it and its dir is not being given on the command line for the build.
What am I missing here?
Here is my very simple CMakeFiles.txt:
cmake_minimum_required(VERSION 3.3)
project(gltest)
set(CMAKE_VERBOSE_MAKEFILE true)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(SOURCE_FILES main.cpp)
add_executable(gltest ${SOURCE_FILES})
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})
target_link_libraries(gltest ${GLFW_LIBRARIES})
message("GLFW_LIBRARIES=${GLFW_LIBRARIES}")
And here is the build output, where you can see at the top there that GLFW_LIBRARIES contains 'glfw3':
/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug --target all -- -j 8
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -H/Users/dave/dev/gltest -B/Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug --check-build-system CMakeFiles/Makefile.cmake 0
GLFW_LIBRARIES=glfw3
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_progress_start /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug/CMakeFiles /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug/CMakeFiles/progress.marks
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/Makefile2 all
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/gltest.dir/build.make CMakeFiles/gltest.dir/depend
cd /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug && /Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_depends "Unix Makefiles" /Users/dave/dev/gltest /Users/dave/dev/gltest /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug /Users/dave/Library/Caches/CLion12/cmake/generated/7a31a53e/7a31a53e/Debug/CMakeFiles/gltest.dir/DependInfo.cmake --color=
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f CMakeFiles/gltest.dir/build.make CMakeFiles/gltest.dir/build
[ 50%] Linking CXX executable gltest
/Applications/CLion.app/Contents/bin/cmake/bin/cmake -E cmake_link_script CMakeFiles/gltest.dir/link.txt --verbose=1
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -std=c++11 -g -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names CMakeFiles/gltest.dir/main.cpp.o -o gltest -lglfw3
ld: library not found for -lglfw3
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [gltest] Error 1
make[1]: *** [CMakeFiles/gltest.dir/all] Error 2
make: *** [all] Error 2
And, finally, here is the glfw3.pc pkg-config that is used for the pkg_search_module call:
prefix=/usr/local/Cellar/glfw3/3.2.1
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib
Name: GLFW
Description: A multi-platform library for OpenGL, window and input
Version: 3.2.1
URL: http://www.glfw.org/
Requires.private:
Libs: -L${libdir} -lglfw3
Libs.private: -framework Cocoa -framework IOKit -framework CoreFoundation -framework CoreVideo
Cflags: -I${includedir}
~
Update: I got it working with this, but it still feels wrong
cmake docs recommend against using link_directories, but I am able to make this work by using that and building up a list of link libraries:
set(LINK_LIBRARIES )
# GLFW lib
find_package(PkgConfig REQUIRED)
pkg_search_module(GLFW REQUIRED glfw3)
include_directories(${GLFW_INCLUDE_DIRS})
link_directories(${GLFW_LIBRARY_DIRS})
set(LINK_LIBRARIES ${LINK_LIBRARIES} ${GLFW_LIBRARIES})
add_executable(gltest ${SOURCE_FILES})
target_link_libraries(gltest ${LINK_LIBRARIES})
You need <XPREFIX>_LDFLAGS (all required linker flag) and maybe <XPREFIX>_LDFLAGS_OTHER (all other linker flags) with <XPREFIX> = GLFW, acccording to the documentation https://cmake.org/cmake/help/v3.6/module/FindPkgConfig.html