Creating CMake Project with Amazon Freertos

Hello, I am using the ESP32 devkitc andrying to use the amazon freertos with my own applications. I ran the demo application successfully however now i want to develop my own application so I tried to use CMake and Add the amazon freertos as subdirectory as guided by Amazon document “Getting started with the Espressif ESP32-DevKitC and the ESP-WROVER-KIT”.

I use following CMake Example from here

cmake_minimum_required(VERSION 3.13)

project(my_app)

add_executable(my_app main.c)

#Tell IDF build to link against this target
set(IDF_PROJECT_EXECUTABLE my_app)

#AFR_BOARD tells which board we need to target.
set(AFR_BOARD espressif.esp32_devkitc CACHE INTERNAL “”)

add_subdirectory(amazon-freertos)

target_link_libraries(my_app PRIVATE AFR::mqtt)

but when i try to build the project it report following error:
add_executable cannot create target “my_app” because another target with
the same name already exists. The existing target is an executable created
in source directory

Please give me some directions In order to create the Project with amazon freertos.

Hi, can you share more information about the folder structure that you have? The location of the CMakeLists.txt file is relevant for setting up the amazon-freertos repository as a submodule.

You may find this previous forum post helpful:

The original question was related to a specific file, but it contains information about setting up your own custom project as well.

Hello!
I want create cmake project in following structure:
-amazon-freertos
-components
-src
- main.c
CMakeLists.txt

and the CMakeLists.txt looks like this :
cmake_minimum_required(VERSION 3.13)

project(freertos_examples)

add_executable(my_app src/main.c)
#Tell IDF build to link against this target.
set(IDF_PROJECT_EXECUTABLE my_app)

#Add FreeRTOS as a subdirectory. AFR_BOARD tells which board to target.

set(AFR_BOARD espressif.esp32_devkitc CACHE INTERNAL “”)

add_subdirectory(freertos)

#Link against the mqtt library so that we can use it. Dependencies are transitively

#linked.

target_link_libraries(my_app PRIVATE AFR::mqtt)

target_link_libraries(my_app PRIVATE AFR::freertos)

target_link_libraries(my_app PRIVATE AFR::kernel)

but the problem is in the following Cmake lines :
add_executable(my_app src/main.c)
#Tell IDF build to link against this target.
set(IDF_PROJECT_EXECUTABLE my_app)

when i use my_app in these two lines above as All the CMakeLists Example I have seen online i get the error that says : add_executable cannot create target “my_app” because another target with
the same name already exists. The existing target is an executable created
in source directory

To solve that i changed those two lines as following :
add_executable(my_app src/main.c)
#Tell IDF build to link against this target.
set(IDF_PROJECT_EXECUTABLE my_app2) #replaced my_app with my_app2

after this I can generate the build directory.
however when i run command : cmake --build build i get following errors :
FAILED: my_app
cmd.exe /C “cd . && C:\Users\Naitik.espressif\tools\xtensa-esp32-elf\esp-2020r3-8.4.0\xtensa-esp32-elf\bin\xtensa-esp32-elf-g++.exe -mlongcalls -Wl,–gc-sections -Wl,–cref -Wl,–Map=aws_demos.map -Wl,–undefined=uxTopUsedPriority @CMakeFiles\my_app.rsp -o my_app && cd .”
c:/users/naitik/.espressif/tools/xtensa-esp32-elf/esp-2020r3-8.4.0/xtensa-esp32-elf/bin/…/lib/gcc/xtensa-esp32-elf/8.4.0/…/…/…/…/xtensa-esp32-elf/bin/ld.exe: cannot open linker script file esp32.project.ld: No such file or directory
collect2.exe: error: ld returned 1 exit status
[1784/1804] Generating ld/esp32.project.ld
ninja: build stopped: subcommand failed.

can you please Help me to understand why CMakeLists.txt from examples is not working.

I went through the forum post you’ve linked but its seems like CMake file there consists microchip related directories as well I tried to remove those and edited for esp32 and specified src/main.c but that neither worked for me.