Migrating a CMake project from ESP-IDF v3.2 to v3.3 - component "main" error

meowsqueak
Posts: 151
Joined: Thu Jun 15, 2017 4:54 am
Location: New Zealand

Migrating a CMake project from ESP-IDF v3.2 to v3.3 - component "main" error

Postby meowsqueak » Sun Nov 17, 2019 12:21 am

I have a CMakeLists.txt that works fine with ESP IDF v3.2, but when I try to build it (from clean check-out) with ESP IDF v3.3 I get the following CMake error:

Code: Select all

$ $IDF_PATH/tools/idf.py build
[...]
-- Component paths: [...];/home/me/my-project/main
[...]
-- Component libraries: 
CMake Error at CMakeLists.txt:9 (target_compile_options):
  Cannot specify compile options for target "main" which is not built by this
  project.
Line 9 of my CMakeLists.txt file looks like this:

Code: Select all

target_compile_options(main PRIVATE -Wno-unknown-pragmas)
(This is required to keep CLion happy)

So the target "main" was valid with the IDF v3.2 build system, but does not seem to exist with the v3.3 build system.

I have other directives that also use the "main" target and they show the same error.

Is there an easy fix for this?

meowsqueak
Posts: 151
Joined: Thu Jun 15, 2017 4:54 am
Location: New Zealand

Re: Migrating a CMake project from ESP-IDF v3.2 to v3.3 - component "main" error

Postby meowsqueak » Sat Nov 23, 2019 3:17 am

It looks like v3.2's project.cmake used the directory of the component that contained the main() function as the name of the target executable, whereas v3.3 uses $IDF_PROJECT_EXECUTABLE instead. So I was able to fix this by changing my rules such as this:

Code: Select all

target_compile_options(main PRIVATE -Wno-unknown-pragmas)
To this:

Code: Select all

target_compile_options(${IDF_PROJECT_EXECUTABLE} PRIVATE -Wno-unknown-pragmas)
Once I did this, I was able to get to the next step (see next post).
Last edited by meowsqueak on Sat Nov 23, 2019 3:56 am, edited 1 time in total.

meowsqueak
Posts: 151
Joined: Thu Jun 15, 2017 4:54 am
Location: New Zealand

Re: Migrating a CMake project from ESP-IDF v3.2 to v3.3 - component "main" error

Postby meowsqueak » Sat Nov 23, 2019 3:56 am

In case this is useful to anyone in the future (including future me):

With ESP IDF v3.2, I had the following in my top-level CMakeLists.txt file:
execute_process(COMMAND "git" "describe" "--match=NeVeRmAtCh" "--always" "--abbrev=14" "--dirty"
RESULT_VARIABLE git_result
OUTPUT_VARIABLE git_output
OUTPUT_STRIP_TRAILING_WHITESPACE)

target_compile_definitions(main PUBLIC GIT_COMMIT="${git_output}")
This had the effect of including the option "-DGIT_COMMIT=..." whenever building code within the "main" component (my top-level component where my main() function is, amongst many others). I use this preprocessor definition within the code.

Now I'm migrating the project to ESP IDF v3.3, and I've discovered (above) that "main" isn't a valid target name any more, so I've tried to replace it with ${IDF_PROJECT_EXECUTABLE}, however that doesn't have the same effect - the compile-time definition -DGIT_COMMIT=... is not added to the compiler command line.

I moved this into main/CMakeLists.txt and using ${COMPONENT_TARGET} instead:

Code: Select all

target_compile_definitions(${COMPONENT_TARGET} PUBLIC GIT_COMMIT="${git_output}")
This seems to work and adds the preprocessor definition to the command line.

I'm not sure why it wouldn't work against the ${IDF_PROJECT_EXECUTABLE} target however.

Who is online

Users browsing this forum: No registered users and 104 guests