Skip to content

Commit b7fa359

Browse files
Bug579242: allow user to override CMake Settings (#683)
The Launch Bar Launch Configuration, Build Settings tab allows the user to customise the CMake Settings (CMake generator, extra arguments, build command and clean command). But changing these settings did not affect the CMake build. This is now fixed. A "Use these settings" checkbox allows the user to choose settings from the UI or use the operating system defaults.
1 parent 1589b8b commit b7fa359

File tree

14 files changed

+492
-20
lines changed

14 files changed

+492
-20
lines changed

NewAndNoteworthy/CDT-11.5.md

+12
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,18 @@ The original locations of object files within a GNU archive are now calculated u
3232

3333
Managed build _Static Library_ projects using a _Cross GCC_, _Cygwin GCC_, _Linux GCC_ or _MinGW GCC_ toolchain now use the `-P` archiver flag by default to generate the necessary path information.
3434

35+
# CMake
36+
The Launch Bar Launch Configuration Build Settings tab has been updated so it can now correctly control the CMake Generator setting. The "Additional CMake arguments" field can also be used to inject CMake defines into the CMakeCache.txt file to populate it with customizable settings for the project. Use the new "Use these settings" checkbox to control whether to use either the operating system defaults or settings from the UI.
37+
38+
When "Use these settings" checkbox is unchecked, the operating system defaults are used during the CMake build.
39+
40+
<p align="center"><img src="images/CDT-11.5-Build_Settings_Use_these_settings_unchecked.PNG" width="50%"></p>
41+
42+
When the "Use these settings" checkbox is checked, the UI settings are used during the CMake build.
43+
44+
<p align="center"><img src="images/CDT-11.5-Build_Settings_Use_these_settings_checked.PNG" width="50%"></p>
45+
46+
3547
# API Changes, current and planned
3648

3749
## Breaking API changes
Loading
Loading

TESTING.md

+8
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,11 @@ DISPLAY=:99 mvn verify
117117
or specify the `DISPLAY` in the Eclipse JUnit launch configuration:
118118

119119
![junit_env_display.png](images/junit_env_display.png "screenshot of how to set custom DISPLAY")
120+
121+
## Manual Testing
122+
### CMake Build Settings tab
123+
A set of manual tests that check it is possible to control the CMake build using the Launch Bar Launch Configuration > Build Settings tab.
124+
125+
[CMake Build Settings tests](./cmake/org.eclipse.cdt.cmake.ui.tests/manualTests/Bug579242_manual_tests.md)
126+
127+

cmake/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.cdt.cmake.core;singleton:=true
5-
Bundle-Version: 1.5.400.qualifier
5+
Bundle-Version: 1.5.500.qualifier
66
Bundle-Activator: org.eclipse.cdt.cmake.core.internal.Activator
77
Bundle-Vendor: %providerName
88
Require-Bundle: org.eclipse.core.runtime,

cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java

+56-3
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@
1818
import java.nio.file.SimpleFileVisitor;
1919
import java.nio.file.attribute.BasicFileAttributes;
2020
import java.util.ArrayList;
21+
import java.util.Arrays;
2122
import java.util.HashMap;
2223
import java.util.List;
2324
import java.util.Map;
2425
import java.util.Objects;
2526
import java.util.function.Consumer;
27+
import java.util.stream.Collectors;
2628

2729
import org.eclipse.cdt.cmake.core.CMakeErrorParser;
2830
import org.eclipse.cdt.cmake.core.CMakeExecutionMarkerFactory;
@@ -66,14 +68,19 @@
6668
import org.eclipse.core.runtime.NullProgressMonitor;
6769
import org.eclipse.core.runtime.Platform;
6870
import org.eclipse.core.runtime.jobs.Job;
71+
import org.osgi.service.prefs.Preferences;
6972

7073
public class CMakeBuildConfiguration extends CBuildConfiguration {
7174

75+
public static final String CMAKE_USE_UI_OVERRIDES = "cmake.use.ui.overrides"; //$NON-NLS-1$
76+
public static final boolean CMAKE_USE_UI_OVERRIDES_DEFAULT = false;
7277
public static final String CMAKE_GENERATOR = "cmake.generator"; //$NON-NLS-1$
7378
public static final String CMAKE_ARGUMENTS = "cmake.arguments"; //$NON-NLS-1$
7479
public static final String CMAKE_ENV = "cmake.environment"; //$NON-NLS-1$
7580
public static final String BUILD_COMMAND = "cmake.command.build"; //$NON-NLS-1$
81+
public static final String BUILD_COMMAND_DEFAULT = "cmake"; //$NON-NLS-1$
7682
public static final String CLEAN_COMMAND = "cmake.command.clean"; //$NON-NLS-1$
83+
public static final String CLEAN_COMMAND_DEFAULT = "clean"; //$NON-NLS-1$
7784

7885
private ICMakeToolChainFile toolChainFile;
7986

@@ -261,6 +268,23 @@ public IProject[] build(int kind, Map<String, String> args, IConsole console, IP
261268
}
262269
}
263270

271+
/**
272+
* When UI overrides are in force, gets the user specified clean target (if not blank), otherwise the default clean target.
273+
* @return Always a non-null String indicating the clean target.
274+
*/
275+
private String getCleanCommand() {
276+
String retVal = CLEAN_COMMAND_DEFAULT;
277+
Preferences settings = this.getSettings();
278+
boolean useUiOverrides = settings.getBoolean(CMAKE_USE_UI_OVERRIDES, CMAKE_USE_UI_OVERRIDES_DEFAULT);
279+
if (useUiOverrides) {
280+
String cleanCommand = settings.get(CLEAN_COMMAND, CLEAN_COMMAND_DEFAULT);
281+
if (!cleanCommand.isBlank()) {
282+
retVal = cleanCommand;
283+
}
284+
}
285+
return retVal;
286+
}
287+
264288
@Override
265289
public void clean(IConsole console, IProgressMonitor monitor) throws CoreException {
266290
IProject project = getProject();
@@ -271,7 +295,7 @@ public void clean(IConsole console, IProgressMonitor monitor) throws CoreExcepti
271295
ICMakeProperties cmakeProperties = getPropertiesController().load();
272296
CommandDescriptorBuilder cmdBuilder = new CommandDescriptorBuilder(cmakeProperties,
273297
new SimpleOsOverridesSelector());
274-
CommandDescriptor command = cmdBuilder.makeCMakeBuildCommandline("clean"); //$NON-NLS-1$
298+
CommandDescriptor command = cmdBuilder.makeCMakeBuildCommandline(getCleanCommand());
275299
ConsoleOutputStream outStream = console.getOutputStream();
276300

277301
Path buildDir = getBuildDirectory();
@@ -547,7 +571,12 @@ public void shutdown() {
547571
}
548572
} // CMakeIndexerInfoConsumer
549573

550-
private static class SimpleOsOverridesSelector implements IOsOverridesSelector {
574+
/**
575+
* Supports OS overrides and also User Interface (UI) overrides, provided in the CMakeBuildTab. The UI
576+
* overrides are stored in the intermediary CBuildConfiguration Preferences (CBuildConfiguration.getSettings())
577+
* and used only when CMAKE_USE_UI_OVERRIDES is true.
578+
*/
579+
private class SimpleOsOverridesSelector implements IOsOverridesSelector {
551580

552581
@Override
553582
public IOsOverrides getOsOverrides(ICMakeProperties cmakeProperties) {
@@ -561,7 +590,31 @@ public IOsOverrides getOsOverrides(ICMakeProperties cmakeProperties) {
561590
// fall back to linux, if OS is unknown
562591
overrides = cmakeProperties.getLinuxOverrides();
563592
}
564-
return overrides;
593+
return getUiOrOsOverrides(overrides);
594+
}
595+
596+
private IOsOverrides getUiOrOsOverrides(IOsOverrides osOverrides) {
597+
IOsOverrides retVal = Objects.requireNonNull(osOverrides, "osOverrides must not be null"); //$NON-NLS-1$
598+
Preferences settings = getSettings();
599+
boolean useUiOverrides = settings.getBoolean(CMAKE_USE_UI_OVERRIDES, CMAKE_USE_UI_OVERRIDES_DEFAULT);
600+
if (useUiOverrides) {
601+
// Set UI override for generator
602+
String gen = settings.get(CMAKE_GENERATOR, ""); //$NON-NLS-1$
603+
retVal.setGenerator(CMakeGenerator.getGenerator(gen));
604+
// Set UI override for Extra Arguments
605+
String extraArgsStr = settings.get(CMAKE_ARGUMENTS, ""); //$NON-NLS-1$
606+
// Convert String of args, separated by 1 or more spaces, into list of Strings
607+
List<String> extraArgs = Arrays.stream(extraArgsStr.split("\\s+")).map(entry -> entry.trim()) //$NON-NLS-1$
608+
.collect(Collectors.toList());
609+
retVal.setExtraArguments(extraArgs);
610+
// Set UI override for cmake build command, unless it's the default
611+
String buildCommand = settings.get(BUILD_COMMAND, BUILD_COMMAND_DEFAULT);
612+
if (!buildCommand.isBlank() && !BUILD_COMMAND_DEFAULT.equals(buildCommand)) {
613+
retVal.setUseDefaultCommand(false);
614+
retVal.setCommand(buildCommand);
615+
}
616+
}
617+
return retVal;
565618
}
566619
} // SimpleOsOverridesSelector
567620
}

cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CommandDescriptorBuilder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ CommandDescriptor makeCMakeCommandline(Path toolChainFile) throws CoreException
5656
List<String> env = new ArrayList<>();
5757

5858
// defaults for all OSes...
59-
args.add("cmake"); //$NON-NLS-1$
59+
args.add(CMakeBuildConfiguration.BUILD_COMMAND_DEFAULT);
6060
/* add general settings */
6161
if (cmakeProperties.isWarnNoDev())
6262
args.add("-Wno-dev"); //$NON-NLS-1$
@@ -111,7 +111,7 @@ CommandDescriptor makeCMakeBuildCommandline(String buildscriptTarget) throws Cor
111111

112112
IOsOverrides osOverrides = overridesSelector.getOsOverrides(cmakeProperties);
113113
if (osOverrides.getUseDefaultCommand()) {
114-
args.add("cmake"); //$NON-NLS-1$
114+
args.add(CMakeBuildConfiguration.BUILD_COMMAND_DEFAULT);
115115
} else {
116116
IStringVariableManager varManager = VariablesPlugin.getDefault().getStringVariableManager();
117117
String cmd = varManager.performStringSubstitution(osOverrides.getCommand());

cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/properties/AbstractOsOverrides.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.List;
1616
import java.util.Objects;
1717

18+
import org.eclipse.cdt.cmake.core.internal.CMakeBuildConfiguration;
1819
import org.eclipse.cdt.cmake.core.properties.CMakeGenerator;
1920
import org.eclipse.cdt.cmake.core.properties.IOsOverrides;
2021

@@ -42,7 +43,7 @@ public AbstractOsOverrides() {
4243
* Sets each value to its default.
4344
*/
4445
public void reset() {
45-
setCommand("cmake"); //$NON-NLS-1$
46+
setCommand(CMakeBuildConfiguration.BUILD_COMMAND_DEFAULT);
4647
useDefaultCommand = true;
4748
setGenerator(CMakeGenerator.UnixMakefiles);
4849
extraArguments.clear();

cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/CMakeGenerator.java

+12
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,16 @@ public String getMakefileName() {
8181
public String getIgnoreErrOption() {
8282
return ignoreErrOption;
8383
}
84+
85+
/**
86+
* @since 1.5
87+
*/
88+
public static CMakeGenerator getGenerator(String generatorName) {
89+
for (CMakeGenerator gen : values()) {
90+
if (gen.getCMakeName().equals(generatorName)) {
91+
return gen;
92+
}
93+
}
94+
return null;
95+
}
8496
}

0 commit comments

Comments
 (0)