Vscode-cmake-tools: Allow setting environment variables via shell/cmd script

Created on 26 Dec 2017  路  10Comments  路  Source: microsoft/vscode-cmake-tools

It would be great to have support for setting environment variables via a script in addition to the current name-value lists (i.e. cmake.environment). This would help building against third-party libraries relying on shell/batch scripts to prepare the build environment (e.g., _Intel Performance Libraries_ - each library exposes a .sh/.bat script which sets relevant environment variables).

Feature Request configure feedback wanted!

Most helpful comment

This request was addressed by the addition of environmentSetupScript in the Kit schema in version 1.4.0.

All 10 comments

Sounds useful.

What sort of design/UX would you like to see?

I'm not really sure how it's usually done, though I was thinking about something like this:

    "cmake.environmentScript": "source ${workspaceRoot}/path/to/script.sh"

and on Windows:

    "cmake.environmentScript": "${workspaceRoot}\\path\\to\\script.bat"

Do you need the script only in the build step or in the configure step of Cmake?

I would prefer a preConfigure and preBuild Script step.
Is this script step multiproject specific, project specific, variant specific or kit specific?

I almost feel like this is getting close to the idea of another Kit type. The VS kits are generated in a similar manner (by invoking the vcvars batch files and collecting environment variables). Perhaps it belongs there?

Do you need the script only in the build step or in the configure step of Cmake?

Actually all of them:

  • in the configure step: to detect the presence of a third-party library (e.g., _Intel Performance Libraries_ set <LIB>ROOT environment variables)
  • in the build step: to pick up correct paths and/or compiler flags (e.g., _Intel Performance Libraries_ set CPATH/INCLUDE and LIBRARY_PATH/LIB environment variables)
  • in the test step and debug: to launch an application built against a third-party library (e.g., _Intel Performance Libraries_ set LD_LIBRARY_PATH/PATH environment variables)

I think the environmentPreparationScript belongs to the kits. It is a additional preparation step before cmake is running. May be it needs to be added to each kit, because it is not a separate compiler more a extended compiler configuration.

I would also be interested in something like this. We already have a batch file that sets all necessary variables for our version of VS2017 build tools as well as some others we need internally. It would be great if we could just make cmake-tools use that as a kit.

Has there been any progress in that direction? What would be the direction forward?

I made a workaround script. Use at your own risk.

This will also be useful for Yocto SDKs: https://www.yoctoproject.org/docs/current/mega-manual/mega-manual.html#sdk-running-the-sdk-environment-setup-script

The work-around script doesn't work as-is for it, since the setup script sources other files in as well.

This request was addressed by the addition of environmentSetupScript in the Kit schema in version 1.4.0.

Was this page helpful?
0 / 5 - 0 ratings