espressif / vscode-esp-idf-extension

Visual Studio Code extension for ESP-IDF projects
https://docs.espressif.com/projects/vscode-esp-idf-extension/en/latest/
Apache License 2.0
1.07k stars 305 forks source link

Project configurations with complier arguments, wrong compiler (VSC-1522) #1346

Open KestrelLuca opened 2 days ago

KestrelLuca commented 2 days ago

hello guys, My goal is to build the same code for different products conditionally and everything works using idf.py. I have created different profiles in Project Configuration Editor which differ just for the Compile arguments and Build Directory path (all the other fields are empty).

For a given product the Compile arguments has e.g. -DPRODUCT=P1 and then the CMakeLists.txt adds the compile define

if(PRODUCT STREQUAL "P1")
    add_compile_definitions(P1)
elseif(PRODUCT STREQUAL "P2")
...
else()
    message(FATAL_ERROR "Unknown PRODUCT: ${PRODUCT}")
endif()

Now, after selecting the project configuration and build, it fails. I have noticed that it is identifying the wrong compilers and I'm getting

-- The C compiler identification is MSVC 19.37.32822.0
-- The CXX compiler identification is MSVC 19.37.32822.0
-- The ASM compiler identification is GNU
-- Found assembler: D:/Espressif/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin/xtensa-esp32-elf-gcc.exe
-- Detecting C compiler ABI info

-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.37.32822/bin/Hostx64/x64/cl.exe - broken
CMake Error at D:/Espressif/tools/cmake/3.24.0/share/cmake-3.24/Modules/CMakeTestCCompiler.cmake:69 (message):  
  The C compiler....

instead of

-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- The ASM compiler identification is GNU
-- Found assembler: D:/Espressif/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin/xtensa-esp32-elf-gcc.exe
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/Espressif/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin/xtensa-esp32-elf-gcc.exe - skipped
-- Detecting C compile features       
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info    
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: D:/Espressif/tools/xtensa-esp-elf/esp-13.2.0_20240530/xtensa-esp-elf/bin/xtensa-esp32-elf-g++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Building ESP-IDF components for target esp32

I have no idea why... can you please clarify what is happening?

Since clearly something is changing my configurations, I then decided to remove the project configurations and try to use the idf.cmakeCompilerArgs method.

As suggested here I tried to add idf.cmakeCompilerArgs to the workspace settings.json but the result is the same...

I also tried to use a different approach like "idf.cmakeCompilerArgs": ["-DP1=On"] and change the CMakelists in

if(${P1})
    add_compile_definitions(P1)
...
endif()`

or 

`if(${P1})
    add_definitions(-DP1)
...
endif()

By removing the idf.cmakeCompilerArgs and the profile configurations everything is correctly recognised and the code builds (of course by pressing build I'll get the Unknown PRODUCT: message).

can you please help? what am I missing? Thanks

Originally posted by @KestrelLuca in https://github.com/espressif/vscode-esp-idf-extension/issues/1309#issuecomment-2493913798

brianignacio5 commented 1 day ago

You mention that the code works using idf.py right ? Could you share the command you execute in idf.py ? If you are using @ please the content too. I just want to compare both resulting cmake commands.