Clion: Modify CMake Build Environment Settings
Hi,
First post, but I have been using PyCharm and Clion for quite some time. I'm a complete beginner with the IntelliJ Idea Plugin SDK so I apologize for any basic questions.
I currently have a class derived from AnAction and I want to set some environment variables for the current CMake project. My AnAction looks like the following (sorry for the formatting but there doesn't seem to be markdown options):
public class EnvironAction extends AnAction {
public EnvironAction() {
}
@Override
public void actionPerformed(AnActionEvent event) {
Project project = event.getProject();
if (project == null) {
System.out.println("No project has been set");
return;
}
HashMap<String, String> buildEnviron = BuildContext.getEnvironment();
CMakeWorkspace workspace = CMakeWorkspace.getInstance(project);
CMakeSettings settings = workspace.getSettings();
for (CMakeSettings.Configuration config : settings.getConfigurations()) {
String configName = config.getConfigName();
System.out.println(configName);
String options = config.getGenerationOptions();
System.out.println(options);
System.out.format("Updating %s Environment", configName);
Map<String, String> configEnviron = config.getAdditionalGenerationEnvironment();
for (Map.Entry<String, String> entry : buildEnviron.entrySet()) {
configEnviron.put(entry.getKey(), entry.getValue());
}
}
}
}
However, configEnviron is a UnmodifiableMap which raises an Exception when put is called. So my question is: how do I modify the additional generation environment for a CMakeSettings.Configuration object?
Also, setting these environment variables in CMakeLists.txt is not an option since they are calculated right before build time.
Thanks,
Josh
Please sign in to leave a comment.
Joshua,
sorry for the delay.
To modify CMake build configurations you need to update the whole list: