espressif / idf-eclipse-plugin

Espressif-IDE (based on Eclipse CDT) for ESP-IDF CMake based projects 4.x and above
Eclipse Public License 2.0
295 stars 115 forks source link

Environment variables defined in Run Configuration was undefined when used in a CMakeList.txt (IEP-812) #636

Open tsctrl opened 1 year ago

tsctrl commented 1 year ago

Describe the bug Environment variables defined in Run Configuration was undefined when used in a CMakeList.txt Motivation: i am trying to build code based on different configuration for different device specification where should be easier to be added and executed in the run configuration instead of sdkconfig.

image

To Reproduce Steps to reproduce the behavior:

  1. Go to Run Configuration Dropdown
  2. Click on edit
  3. Go to Environment tab
  4. Add new env variable TEST with value Test1
  5. Run sample cmake below:
if (NOT DEFINED $ENV{TEST})
    message(FATAL_ERROR "TEST  IS NOT DEFINED.")
endif()

Behavior $ENV variable is undefined

Expected behavior $ENV variable should be captured by CMake during build

Espressif-IDE Product Information:

IDF_PATH: \esp-idf\esp-idf-v4.4.1 IDF_PYTHON_ENV_PATH: .espressif\python_env\idf4.4_py3.8_env PATH: .espressif\tools\xtensa-esp32-elf\esp-2021r2-patch3-8.4.0\xtensa-esp32-elf\bin;.espressif\tools\xtensa-esp32s2-elf\esp-2021r2-patch3-8.4.0\xtensa-esp32s2-elf\bin;.espressif\tools\xtensa-esp32s3-elf\esp-2021r2-patch3-8.4.0\xtensa-esp32s3-elf\bin;.espressif\tools\xtensa-clang\12.0.1-d9341b81fc\xtensa-esp32-elf-clang\bin;.espressif\tools\riscv32-esp-elf\esp-2021r2-patch3-8.4.0\riscv32-esp-elf\bin;.espressif\tools\esp32ulp-elf\2.28.51-esp-20191205\esp32ulp-elf-binutils\bin;.espressif\tools\esp32s2ulp-elf\2.28.51-esp-20191205\esp32s2ulp-elf-binutils\bin;N.espressif\tools\cmake\3.20.3\bin;.espressif\tools\openocd-esp32\v0.11.0-esp32-20211220\openocd-esp32\bin;.espressif\tools\ninja\1.10.2\;.espressif\tools\idf-exe\1.0.3\;.espressif\tools\ccache\4.3\ccache-4.3-windows-64;.espressif\tools\dfu-util\0.9\dfu-util-0.9-win64;

Operating System: windows 10 Java Runtime Version: 11.0.14.1+10-LTS Eclipse Version: 4.22.0.v20211124-1800 Eclipse CDT Version: 10.5.0.202109270023 IDF Eclipse Plugin Version: 2.4.2.202203081345 ESP-IDF v4.4.1-dirty Python set for IDF_PYTHON_ENV: Python 3.8.7 Python declared in PATH variable: Python 3.9.0

alirana01 commented 1 year ago

Hi

@tsctrl Thank you for reporting the issue. Can you please try to define the variable in eclipse's settings. C/C++ -> Build -> Environment And add the variable there and see if it helps.

Thanks

alirana01 commented 1 year ago

@tsctrl Further clarification on the issue the Env vars you are trying to set are for the launch not build so if you need variables in the build you need to configure them in the build configuration.

Thanks

tsctrl commented 1 year ago

hi @alirana01 ,

this issue was not resolve. adding variable in c++ env will set global variable for all build and not for specific run build. your suggestion was not solving this issue. adding variable in c++ configuration is similar as adding settings in the cmake files or in machine env variable which is not change for every run configuration build.

i was looking for settings to be dynamically change for each different run build not shared c++ env that was set for all build.

tsctrl commented 1 year ago

@alirana01 please reopen this issue.

thanks! @kolipakakondal

igrr commented 1 year ago

@tsctrl one alternative is to add build-specific settings via CMake arguments in the Additional CMake Arguments field on the Build Settings tab of the Edit Configuration window. If you add an argument such as -DFOO=1, then variable FOO will be defined to 1 in CMake.

image
tsctrl commented 1 year ago

i tried, added the variable in the additional cmake arguments but it will be the shared same value for all run build, so this approach also does not solve this issue and also the same as adding the argument directly on the cmake file or adding the argument using idf.py command for each build.

tsctrl commented 1 year ago

the objective is to have different env val for different run build.

say, run build esp32-foo1 is to build with config variable FOO=1 run build esp32-foo2 is to build with config variable FOO=2

with this we dont have to manually change cmake file for every build. please also give suggestion on other possible approach.

kolipakakondal commented 1 year ago

the objective is to have different env val for different run build.

say, run build esp32-foo1 is to build with config variable FOO=1 run build esp32-foo2 is to build with config variable FOO=2

with this we dont have to manually change cmake file for every build. please also give suggestion on other possible approach.

Hi @tsctrl You can achieve this by duplicating the existing launch configuration. Please follow the below instructions

  1. Click on the project launch configuration Edit button (Gear icon from the top toolbar)
  2. Click on Duplicate
  3. Change the launch configuration name as you desired
  4. Navigate to the Build Settings Tab
  5. Provide additional arguments in Additional CMake arguments
  6. Click on Ok

Now you've two launch configurations for your project to address the specific needs.

We will work on the environment variable issue you've mentioned, thanks for bringing this up.

Screenshot 2022-11-28 at 10 43 30 AM
tsctrl commented 1 year ago

hi @kolipakakondal i have done as above but the additional cmake arguments will always be the same for all run configuration.

let say i change the cmake additional configuration in run config A. the run config B also will have the same cmake argument. means the same cmake configuration are shared between all run configuration.

this behaviour was invalidates the point of having multuple additional cmake arguments for each run configuration.

igrr commented 1 year ago

i have done as above but the additional cmake arguments will always be the same for all run configuration.

I can confirm this! For some reason, modifying "Additional CMake arguments" for one configuration changes this setting for all other configurations...

kolipakakondal commented 1 year ago

Thanks for verifying @igrr @tsctrl let me fix this and provide a nightly build

kolipakakondal commented 1 year ago

Hi, I thought I could provide a quick fix to handle this -after spending a couple of hours realized this is a lot more complicated than I thought as the underlying build infrastructure to handle multiple build configurations for a project is missing in Eclipse CDT CMake itself.

We will take this up on priority to build this feature. Let me also reopen this bug as the environment variables are not getting parsed during the build.

kolipakakondal commented 1 year ago

Hi, I thought I could provide a quick fix to handle this -after spending a couple of hours realized this is a lot more complicated than I thought as the underlying build infrastructure to handle multiple build configurations for a project is missing in Eclipse CDT CMake itself.

We will take this up on priority to build this feature. Let me also reopen this bug as the environment variables are not getting parsed during the build.

Issue related to handling multiple build configurations and saving was addressed in IEP v2.8.0 released.