When working in console I'm using shell script to source many environment variables required for configuration and build. I see there is a setting to add variables separately, but that's a long and often changing list - I'd love to be able to just pass the script name so it's run in the shell cmake-tools is working.
Some setting like "pre-configuration commands".
It might be worth mentioning that I'm working with SSH remote connection plugin, and cmake-tools is installed on remote machine.
This might be easily doable by augmenting the Kits schema. Something similar is done to load environment variables for the MSVC compiler, but it's internal to the extension.
I would also like to see this functionality - I'm using CMake to build some quite old code, in which some build steps are performed in bash scripts. Because I can't source the required rc file before calling CMake, these legacy steps crash the build. The CMake plugin is therefore not usable for these builds!
I'd like this feature too. My particular use case, and I bet shared by many, is to activate a Conda enviroment before building, so I build with the right Python libraries (CMake itself respects activated envs as priority in FindPython).
This feature was implemented and will be released with 1.4.
CMake Tools 1.4.0 Beta is available on GitHub.
https://github.com/microsoft/vscode-cmake-tools/releases/tag/1.4.0-beta
Please try it out and let us know if you encounter any issues.
This is essential for my workflow - I have to source several scripts to set up my build environment. This option worked great! Much easier than maintaining a very long list of environment variables. Thanks for adding it!!
This fix is available in CMake Tools #1.4.0 which has been released.
I cannot see the settings in the CMake Tools configuration. I tried to set it manually using cmake.environmentVariablesShellScript and cmake.environmentVariablesShellScriptDirectory to no avail.
From looking at the PR that introduced this functionality, it should be the "environmentSetupScript" property of a kit. Manually add that to the kit you are using, in the kits file json. Let us know how that goes.
I tried setting the environmentSetupScript property of a kit in cmake-tools-kits.json and it didn't seem to work. Will the given be script be run or "sourced". My setup script contains many environment variables, therefore i would like vscode to effectively run "source
I tried setting the environmentSetupScript property of a kit in cmake-tools-kits.json and it didn't seem to work. Will the given be script be run or "sourced". My setup script contains many environment variables, therefore i would like vscode to effectively run "source "
I am having the same issue where this property seems to have no effect. In case it is a run instead of source, I tried making a separate script to source what I need, and though it works when I call it manually it is not called when cmake is configured.
From looking at the PR that introduced this functionality, it should be the "environmentSetupScript" property of a kit. Manually add that to the kit you are using, in the kits file json. Let us know how that goes.
Thank you! Actually, it works for me. I just edited cmake-tools-kits.json and added the following lines to enable Intel toolchain:
{
"name": "Intel 19.0.5.281",
"environmentSetupScript": "/opt/intel/bin/iccvars.sh intel64",
"compilers": {
"C": "/opt/intel/compilers_and_libraries_2019.5.281/linux/bin/intel64/icc",
"CXX": "/opt/intel/compilers_and_libraries_2019.5.281/linux/bin/intel64/icpc",
"Fortran": "/opt/intel/compilers_and_libraries_2019.5.281/linux/bin/intel64/ifort"
}
}
Then, whenever I switch to Intel 19.0.5.281 kit, /opt/intel/bin/iccvars.sh intel64 script runs and setups the environment.
environmentSetupScript does not work for me in a remote docker container with CMake Tools 1.4.1. A simple test is the following cmake-kits.json which is successfully picked up by the extension.
[
{
"name": "gcc7 setup environment",
"environmentSetupScript": "export PYTHONPATH=/root/",
"compilers": {
"C": "/usr/bin/gcc-7",
"CXX": "/usr/bin/g++-7"
}
}
]
I then have a line of message(STATUS $ENV{PYTHONPATH}) in the CMakeLists.txt to verify it, but It's blank. Configure fails because of missing env vars. I also tried putting the env vars in a .sh script and writing "environmentSetupScript": source file.sh", same issue. All I need is that the shell, whichever the extension uses to execute the cmake calls, respects ~/.bashrc.
@duanyutong Try
"environmentSetupScript": file.sh
@jheaff1 Thanks. I tried that in various ways and here are my observations.
.sh file it points to cannot simply contain source ~/.bashrc or source $HOME/.bashrc or even the full absolute path; it has to contain the environment variable definitions itself.sh script only once when the kit is first selected; so, if the script is modified, one has to refresh the kit selection to get it to reload the script; it's pretty unexpected that it doesn't load the latest script on disk upon executionIt seems that executing cmake calls in the same kind of shell as the vscode integrated terminal would be a simpler and more general solution.
@jheaff1 Thanks. I tried that in various ways and here are my observations.
- the
.shfile it points to cannot simply containsource ~/.bashrcorsource $HOME/.bashrcor even the full absolute path; it has to contain the environment variable definitions itself
I can confirm that it cannot source an external file.
The feature would be essential to integrate the Intel OneApi Toolkit since they provide a script that must be sourced and would be very annoying to rewrite.
https://software.intel.com/content/www/us/en/develop/documentation/get-started-with-intel-oneapi-base-linux/top/before-you-begin.html#before-you-begin_GUID-338EB548-7DB6-410E-B4BF-E65C017389C4
In my case the setup script must be sourced even before any attempt to run CMake. The CMake version installed on the remote is very old and not relevant - only the one set up by the script is. (Same is true for git and Python - only after sourcing the setup script they are of the correct version).
My manual process is:
cd <project-dir>
source setup.sh
cd build
cmake ..., make ..., etc.
Same here, need to . /opt/ros/melodic/setup.bash to get the ROS1 env setup right before the cmake .. call. Or else:
[cmake] ImportError: No module named catkin.environment_cache
I'm having issues with the parsing of environment variables. In my case the output of printenv contains these two lines
BASH_FUNC_module()=() { eval `/usr/bin/modulecmd bash $*`
}
which causes
[kit] Error parsing environment variable: }
Maybe the solution to this issue should be adjusted to parse multiline environment variables, or to _actually execute_ the shell script, rather than only importing the environment...
EDIT: Should I open a new issue instead of hoping to get a response from a closed one?
Can it be a custom command to run before build?
For an example, I'm working remotely on the server with modules: example
Every time before any build I should source a custom script which loads modules I need for my build.
The simplest way for me would be able to call a custom script which loads those variables. But I'm not sure if "source load_script.sh" will help for a kit to build with all modules sourced.
For those who came for ROS.
...
"cmake.configureSettings": {
"CMAKE_PREFIX_PATH": "/opt/ros/${ROS_DISTRO}"
},
...
Most helpful comment
I would also like to see this functionality - I'm using CMake to build some quite old code, in which some build steps are performed in bash scripts. Because I can't source the required rc file before calling CMake, these legacy steps crash the build. The CMake plugin is therefore not usable for these builds!