Environment variables issues in cmake project in remote ssh mode, while building, and for build configs

已完成

Hey there,

I've got several issues regarding environment variables in remote ssh mode. I use cmake for my project and and the remote ssh mode to develop on a linux virtual box (CentOS 7).

Regarding building of the project, I was able to manually set the required environment variables via File->Settings->Build, Execution, Deployment->CMake-><Profile>->Environment. The first problem is that CLion automatically generates run configurations from cmake targets (at least that's what I think where they come from), however, again, environment variables are not correctly set from .bashrc/.bash_profile or anywhere else. The issue here is that in my case there are > 100 run targets and manually setting the correct environment variables is very tedious at best. Imagine changing the folder structure in my test environment (for whatever reason) and I have to reset all run configs again.. 

While these two issues have manual workarounds (if quite tedious ones), what I struggle with right now are the header search paths. Since, again, CLion apparently has some issues with environment variables in remote ssh mode, I only have the option to set them manually via File->Settings->Build, Execution, Deployment->CMake-><Profile>->Environment. Yet, somehow the contents of CPLUS_INCLUDE_PATH do not appear in the header search paths, and neither does adding 'include_directories($ENV{CPLUS_INCLUDE_PATH})' to my CMakeLists.txt (if that is the correct way to do it?). Reloading CMake Project, 'Tools->CMake->Reset Cache and Reload Project', and 'Tools->Resync with Remote Hosts' does not seem to resolve that issue.

So I guess I have two questions to ask

  1. How can I make sure that Clion's Frontend does take CPLUS_INCLUDE_PATH into consideration for header search paths (so that I don't get the '... file not found' errors and can jump into these header files; building with cmake works just fine, because there I can manually set the variable) ?
  2. Why is it impossible for CLion's remote ssh mode to just load a script setting the required remote environment variables? I saw many threads & issues stating that this is a very common problem in multiple projects, some of which aren't easy to fix via manually setting environment variables, because they are somewhat dynamic.

Thanks in advance for any kind of information for these two questions!

评论操作 固定链接

Hello!

1. Could you please add message($ENV{CPLUS_INCLUDE_PATH}) to your CMakeLists.txt and check in the CMake tool window whether the path is correct? And what CLion version do you use?

2. There is a feature request - https://youtrack.jetbrains.com/issue/CPP-15976. Feel free to comment or upvote the issue in order to get updates. See https://intellij-support.jetbrains.com/hc/en-us/articles/207241135-How-to-follow-YouTrack-issues-and-receive-notifications if you are not familiar with YouTrack.

0
评论操作 固定链接

Hey, thanks for that quick reply! message($ENV{CPLUS_INCLUDE_PATH}) outputs exactly what I would have expected. Note that importing the same project in CLion installed on the remote machine directly actually shows the correct header search paths without further configuration. I use CLion 2020.2,Build #CL-202.6397.106, built on July 28, 2020 Runtime version: 11.0.7+10-b944.20 amd64. As host I use Windows 10, build 19041.388

0
评论操作 固定链接

Please create a simple sample project that reflects the structure of your project and with which the issue can be reproduced, and send it to clion-support at jetbrains.com.

0
评论操作 固定链接

I did find a workaround:

I created a bash script that looks like this:

export PATH=/home/user/Qt/5.15.1/gcc_64/bin/:$PATH
/home/user/Documents/cmake-3.19.0-rc3-Linux-x86_64/bin/cmake $@

And set my toolchain's cmake to that file. Now whenever there is a configuration or building operation the script would pick up the arguments, setup the environment and then call cmake with passed parameters.

 

0
评论操作 固定链接

For Ahmed Hani's answer, it's better to double-quote $@, so as to prevent some errors.

0

请先登录再写评论。