Skip to content

Commit a023407

Browse files
Improve CMake build option handling and API
Summary: - Add some new API to make it easier for ISVs to provide defaults. - Fully connect UI elements to CMake build process - Add some missing UI elements (such as customizing generator) - CMake generator default within CDT changed to Ninja Details: Add API to set CMake generator default (eg Ninja) ISV can set their desired CMake generator by overriding `CMakeBuildConfiguration.getDefaultProperties`. ISVs can also further fine tune the build process by overriding `CMakeBuildConfiguration.getDefaultProperties` Remove API `IOsOverrides` and related code. `IOsOverrides` was a partial implementation to achieve builds in Docker containers, however the work was not complete and it the extra code was complicating some basic use cases of setting defaults Add support for all generators to CMake build settings UI page by using a Combo instead of radio buttons. The non-deprecated generators that are built-in to CDT populate the Combo, but additional generators can be manually entered in the Combo. Rename clean command to clean target to better reflect its use as the argument passed to cmake's --target command line. Add all target for the argument passed to cmake's --target command line when doing a normal build. Clarify usage of UI overrides and change the UI to be "use defaults" (i.e. invert the checkbox). This is a **breaking** change as it means user projects that were using UI overrides will revert to using defaults. This is done on purpose as so many little things have changed in CMake settings, that reverting to defaults on upgrade seems like a logical decision. In addition *use defaults* matches the other GUIs in Eclipse, for example the MBS build command settings. Populate all defaults in getDefaultProperties() so that all CMake build settings are displayed as used (greyed out) and can be used as a starting point when editing settings. Simplify some of the code in CMakeBuildTab. Fix parsing of extra args so that quoted strings work. Refactored manual tests document and brought it up to date. Correct command line option for CMake's --warn-unused-vars Correct command line option for CMake's --warn-uninitialized Overall this is an API breaking change and the CHANGELOG-API.md has been updated with all the API changes in and around ICMakeProperties, including fixing typos in WarnUninitialized methods. Fixes #1055 Fixes #818 Part of #1000 Co-authored-by: John Moule <[email protected]> Co-authored-by: Jonah Graham <[email protected]>
1 parent 11dfaa4 commit a023407

30 files changed

+921
-1154
lines changed

NewAndNoteworthy/CDT-12.0.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,21 @@ The minimum version of GLIBC required is now 2.31.
1212
This version can be found in Ubuntu 20.04 and later, RHEL 9.0 and later and other distros as well.
1313
CDT's native components will likely work with older versions of glibc too, assuming they provide the required APIs for Eclipse CDT.
1414

15+
# Core Build
16+
17+
## More CMake build settings are now available in the user interface
18+
19+
The CMake build setting GUI has been updated to include more CMake settings, and some of the settings that did not used to do the correct thing have been updated for more consistent behavior.
20+
The way these settings are saved has been slightly modified, meaning workspaces with CMake projects from before CDT 12 will have their build settings restored to defaults.
21+
Build settings can be customized by unchecking "Use default CMake settings".
22+
23+
TODO: Before release add the final screenshot for the build settings here. I am not including it now because the UI keeps changing.
24+
25+
## Default build system generator for CMake changed to Ninja on all platforms
26+
27+
The default for CMake's build system generator is now Ninja on all platforms.
28+
Users who want to use other build system generators can select their desired generator in the build settings.
29+
1530
# Managed Build
1631

1732
## New *C Project* and new *C++ Project* available via *New C/C++ Project* wizard

NewAndNoteworthy/CHANGELOG-API.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@ This section describes API removals that occurred in past releases, and upcoming
88

99
Below is the detailed descriptions of API changes and mitigation efforts API consumers need to take.
1010

11+
## API Changes in CDT 12.0.
12+
13+
### org.eclipse.cdt.cmake.core.properties refactored
14+
15+
A significant simplification to the CMake build properties was completed, this included removing some API that was not used.
16+
The following classes have been removed or modified in API breaking ways:
17+
18+
- org.eclipse.cdt.cmake.core.properties.ICMakePropertiesController removed
19+
- org.eclipse.cdt.cmake.core.properties.IGeneralProperties removed
20+
- org.eclipse.cdt.cmake.core.properties.IOsOverrides removed
21+
- org.eclipse.cdt.cmake.core.properties.ICMakeProperties:
22+
- new methods added to compensate for removal of IOsOverrides
23+
- reset method removed
24+
- spelling corrected for methods with Uninitialized in the name
25+
- setWarnUnused renamed to setWarnUnusedVars and isWarnUnused renamed to isWarnUnusedVars
26+
27+
1128
## API Changes in CDT 11.5.
1229

1330
### org.eclipse.cdt.make.ui.dialogs.DiscoveredPathContainerPage removed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ Bundle-SymbolicName: org.eclipse.cdt.cmake.core.tests
55
Bundle-Version: 1.0.0.qualifier
66
Fragment-Host: org.eclipse.cdt.cmake.core;bundle-version="1.5.0"
77
Import-Package: org.assertj.core.api;version="[3.24.2,4.0.0)",
8-
org.junit.jupiter.api;version="[5.9.3,6.0.0)"
8+
org.junit.jupiter.api;version="[5.9.3,6.0.0)",
9+
org.mockito;version="[5.15.0,6.0.0)",
10+
org.mockito.stubbing;version="[5.15.0,6.0.0)"
911
Automatic-Module-Name: org.eclipse.cdt.cmake.core.tests
1012
Bundle-Vendor: %Bundle-Vendor
1113
Bundle-Copyright: %Bundle-Copyright
12-
Require-Bundle: org.junit
14+
Require-Bundle: org.junit,
15+
org.eclipse.cdt.core.tests;bundle-version="[5.4.0,6.0.0)"
1316

Lines changed: 299 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,299 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2025 Renesas Electronics Europe.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*******************************************************************************/
11+
package org.eclipse.cdt.cmake.core;
12+
13+
import static org.hamcrest.MatcherAssert.assertThat;
14+
import static org.hamcrest.Matchers.contains;
15+
import static org.hamcrest.Matchers.is;
16+
import static org.hamcrest.Matchers.nullValue;
17+
import static org.mockito.Mockito.mock;
18+
import static org.mockito.Mockito.when;
19+
20+
import java.util.ArrayList;
21+
import java.util.HashMap;
22+
import java.util.List;
23+
import java.util.Map;
24+
25+
import org.eclipse.cdt.cmake.core.properties.CMakeGenerator;
26+
import org.eclipse.cdt.cmake.core.properties.ICMakeGenerator;
27+
import org.eclipse.cdt.cmake.core.properties.ICMakeProperties;
28+
import org.eclipse.cdt.core.CCProjectNature;
29+
import org.eclipse.cdt.core.CProjectNature;
30+
import org.eclipse.cdt.core.build.IToolChain;
31+
import org.eclipse.cdt.core.testplugin.ResourceHelper;
32+
import org.eclipse.cdt.core.testplugin.util.BaseTestCase5;
33+
import org.eclipse.cdt.utils.CommandLineUtil;
34+
import org.eclipse.core.resources.IBuildConfiguration;
35+
import org.eclipse.core.resources.IProject;
36+
import org.eclipse.core.resources.IProjectDescription;
37+
import org.junit.jupiter.api.BeforeEach;
38+
import org.junit.jupiter.api.Test;
39+
40+
/**
41+
* Tests a new API added to the CMake Build Configuration which allows default CMake properties to be set.
42+
* See the new interface {@link ICMakeBuildConfiguration}.
43+
*/
44+
public class CMakeBuildConfigurationTests extends BaseTestCase5 {
45+
private IBuildConfiguration buildConfig;
46+
private IToolChain mockToolchain;
47+
48+
@BeforeEach
49+
public void setup() throws Exception {
50+
// Create a CMake project
51+
IProject project = createCMakeProject();
52+
// Get the default build config from the project (it always has one)
53+
buildConfig = project.getBuildConfig(IBuildConfiguration.DEFAULT_CONFIG_NAME);
54+
// Setup a toolchain ready to use for creating the valid ICBuildConfiguration
55+
mockToolchain = mock(IToolChain.class);
56+
when(mockToolchain.getProperty(IToolChain.ATTR_OS)).thenReturn("osDummy");
57+
when(mockToolchain.getProperty(IToolChain.ATTR_ARCH)).thenReturn("archDummy");
58+
when(mockToolchain.getTypeId()).thenReturn("tc_typeId");
59+
when(mockToolchain.getId()).thenReturn("tcId");
60+
when(mockToolchain.getBuildConfigNameFragment()).thenReturn("buildConfigName");
61+
}
62+
63+
/**
64+
* Test for {@link ICMakeProperties#setGenerator()}.
65+
*
66+
* This test also verifies that what the ISV overrides in getCMakeProperties is what takes effect.
67+
*/
68+
@Test
69+
public void getCMakePropertiesTestSetGenerator() throws Exception {
70+
CMakeBuildConfiguration cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName",
71+
mockToolchain) {
72+
73+
@Override
74+
public ICMakeProperties getCMakeProperties() {
75+
ICMakeProperties properties = super.getCMakeProperties();
76+
properties.setGenerator(CMakeGenerator.WatcomWMake);
77+
return properties;
78+
}
79+
};
80+
81+
// Call the new method on ICMakeBuildConfiguration to get the default CMake properties.
82+
ICMakeProperties cMakeProperties = cmBuildConfig.getCMakeProperties();
83+
assertThat(cMakeProperties.getGenerator(), is(CMakeGenerator.WatcomWMake));
84+
}
85+
86+
/**
87+
* Test for {@link ICMakeProperties#setExtraArguments()}
88+
*
89+
* This test also verifies that what the ISV overrides in getCMakeProperties is what takes effect.
90+
*/
91+
@Test
92+
public void getCMakePropertiesTestSetExtraArguments() throws Exception {
93+
// Create a C Build Configuration using the default build config and an arbitrary name
94+
CMakeBuildConfiguration cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName",
95+
mockToolchain) {
96+
97+
@Override
98+
public ICMakeProperties getCMakeProperties() {
99+
ICMakeProperties properties = super.getCMakeProperties();
100+
properties.setExtraArguments(
101+
new ArrayList<>((List.of("-DplatformAgnosticArgsTest0=0", "-DplatformAgnosticArgsTest1=1"))));
102+
return properties;
103+
}
104+
};
105+
// Call the new method on ICMakeBuildConfiguration to get the default CMake properties.
106+
ICMakeProperties cMakeProperties = cmBuildConfig.getCMakeProperties();
107+
List<String> extraArguments = cMakeProperties.getExtraArguments();
108+
assertThat(extraArguments, contains("-DplatformAgnosticArgsTest0=0", "-DplatformAgnosticArgsTest1=1"));
109+
}
110+
111+
/**
112+
* Test for {@link CMakeBuildConfiguration#getDefaultProperties()}
113+
*/
114+
@Test
115+
public void getDefaultProperties() throws Exception {
116+
// Create a C Build Configuration using the default build config and an arbitrary name
117+
CMakeBuildConfiguration cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName",
118+
mockToolchain) {
119+
120+
@Override
121+
public Map<String, String> getDefaultProperties() {
122+
var defs = new HashMap<>(super.getDefaultProperties());
123+
defs.put(CMAKE_GENERATOR, CMakeGenerator.WatcomWMake.getCMakeName());
124+
return defs;
125+
}
126+
};
127+
// Call the new method on ICMakeBuildConfiguration to get the default CMake properties.
128+
ICMakeProperties cMakeProperties = cmBuildConfig.getCMakeProperties();
129+
assertThat(cMakeProperties.getGenerator(), is(CMakeGenerator.WatcomWMake));
130+
}
131+
132+
@Test
133+
public void getDefaultPropertiesTestExtraArgs() throws Exception {
134+
// Create a C Build Configuration using the default build config and an arbitrary name
135+
CMakeBuildConfiguration cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName",
136+
mockToolchain) {
137+
@Override
138+
public Map<String, String> getDefaultProperties() {
139+
var defs = new HashMap<>(super.getDefaultProperties());
140+
defs.put(CMAKE_ARGUMENTS, "-Dtest0=0 -Dtest1=1");
141+
return defs;
142+
}
143+
};
144+
// Call the new method on ICMakeBuildConfiguration to get the default CMake properties.
145+
ICMakeProperties cMakeProperties = cmBuildConfig.getCMakeProperties();
146+
List<String> extraArguments = cMakeProperties.getExtraArguments();
147+
assertThat(extraArguments, contains("-Dtest0=0", "-Dtest1=1"));
148+
}
149+
150+
/**
151+
* Test that a custom cmake generator can be entered and auto-created
152+
*/
153+
@Test
154+
public void customCMakeGeneratorEntryAuto() throws Exception {
155+
// Create a C Build Configuration using the default build config and an arbitrary name
156+
CMakeBuildConfiguration cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName",
157+
mockToolchain) {
158+
@Override
159+
public Map<String, String> getDefaultProperties() {
160+
var defs = new HashMap<>(super.getDefaultProperties());
161+
// A custom generator for a custom cmake version
162+
defs.put(CMAKE_GENERATOR, "My Personal Generator");
163+
return defs;
164+
}
165+
};
166+
167+
// Call the new method on ICMakeBuildConfiguration to get the default CMake properties.
168+
ICMakeProperties cMakeProperties = cmBuildConfig.getCMakeProperties();
169+
assertThat(cMakeProperties.getGenerator().getCMakeName(), is("My Personal Generator"));
170+
assertThat(cMakeProperties.getGenerator().getIgnoreErrOption(), is(nullValue()));
171+
assertThat(cMakeProperties.getGenerator().getMakefileName(), is(nullValue()));
172+
}
173+
174+
/**
175+
* Test that a custom cmake generator can be entered and manually-created
176+
*/
177+
@Test
178+
public void customCMakeGeneratorEntryManual() throws Exception {
179+
// Create a C Build Configuration using the default build config and an arbitrary name
180+
CMakeBuildConfiguration cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName",
181+
mockToolchain) {
182+
@Override
183+
public Map<String, String> getDefaultProperties() {
184+
var defs = new HashMap<>(super.getDefaultProperties());
185+
// A custom generator for a custom cmake version
186+
defs.put(CMAKE_GENERATOR, "My Personal Generator");
187+
return defs;
188+
}
189+
190+
@Override
191+
public ICMakeProperties getCMakeProperties() {
192+
ICMakeProperties properties = super.getCMakeProperties();
193+
if ("My Personal Generator".equals(properties.getGenerator().getCMakeName())) {
194+
var generator = new ICMakeGenerator() {
195+
@Override
196+
public String getMakefileName() {
197+
return "MyMak.mak";
198+
}
199+
200+
@Override
201+
public String getIgnoreErrOption() {
202+
return "-mycustom";
203+
}
204+
205+
@Override
206+
public String getCMakeName() {
207+
return "My Personal Generator";
208+
}
209+
};
210+
properties.setGenerator(generator);
211+
}
212+
return properties;
213+
}
214+
};
215+
216+
// Call the new method on ICMakeBuildConfiguration to get the default CMake properties.
217+
ICMakeProperties cMakeProperties = cmBuildConfig.getCMakeProperties();
218+
assertThat(cMakeProperties.getGenerator().getCMakeName(), is("My Personal Generator"));
219+
assertThat(cMakeProperties.getGenerator().getIgnoreErrOption(), is("-mycustom"));
220+
assertThat(cMakeProperties.getGenerator().getMakefileName(), is("MyMak.mak"));
221+
}
222+
223+
/**
224+
* Test all and clean targets and cmake command have working defaults
225+
*/
226+
@Test
227+
public void targetsAndCommandDefaults() throws Exception {
228+
// Create a C Build Configuration using the default build config and an arbitrary name
229+
CMakeBuildConfiguration cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName",
230+
mockToolchain);
231+
232+
// Call the new method on ICMakeBuildConfiguration to get the default CMake properties.
233+
ICMakeProperties cMakeProperties = cmBuildConfig.getCMakeProperties();
234+
assertThat(cMakeProperties.getCommand(), is("cmake"));
235+
assertThat(cMakeProperties.getAllTarget(), is("all"));
236+
assertThat(cMakeProperties.getCleanTarget(), is("clean"));
237+
}
238+
239+
/**
240+
* Test all and clean targets and cmake command can be overridden
241+
*/
242+
@Test
243+
public void targetsAndCommand() throws Exception {
244+
// Create a C Build Configuration using the default build config and an arbitrary name
245+
CMakeBuildConfiguration cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName",
246+
mockToolchain) {
247+
@Override
248+
public Map<String, String> getDefaultProperties() {
249+
var defs = new HashMap<>(super.getDefaultProperties());
250+
defs.put(CMAKE_BUILD_COMMAND, "mycmake");
251+
defs.put(CMAKE_ALL_TARGET, "myall");
252+
defs.put(CMAKE_CLEAN_TARGET, "myclean");
253+
return defs;
254+
}
255+
};
256+
257+
// Call the new method on ICMakeBuildConfiguration to get the default CMake properties.
258+
ICMakeProperties cMakeProperties = cmBuildConfig.getCMakeProperties();
259+
assertThat(cMakeProperties.getCommand(), is("mycmake"));
260+
assertThat(cMakeProperties.getAllTarget(), is("myall"));
261+
assertThat(cMakeProperties.getCleanTarget(), is("myclean"));
262+
}
263+
264+
/**
265+
* Test that extra arguments parse correctly, e.g. handles ".
266+
*
267+
* Note that this test is minimal here as the real functionality is in {@link CommandLineUtil}
268+
* and all the special cases are tested in CommandLineUtilTest.
269+
*/
270+
@Test
271+
public void extraArgumentsParseCorrectly() throws Exception {
272+
// Create a C Build Configuration using the default build config and an arbitrary name
273+
CMakeBuildConfiguration cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName",
274+
mockToolchain) {
275+
@Override
276+
public Map<String, String> getDefaultProperties() {
277+
var defs = new HashMap<>(super.getDefaultProperties());
278+
defs.put(CMAKE_ARGUMENTS, "-Da=\"something with space and quotes\" \"-Danother=quoted\"");
279+
return defs;
280+
}
281+
};
282+
283+
// Call the new method on ICMakeBuildConfiguration to get the default CMake properties.
284+
ICMakeProperties cMakeProperties = cmBuildConfig.getCMakeProperties();
285+
assertThat(cMakeProperties.getExtraArguments(),
286+
is(List.of("-Da=something with space and quotes", "-Danother=quoted")));
287+
}
288+
289+
private IProject createCMakeProject() throws Exception {
290+
// Create a plain Eclipse project
291+
IProject project = ResourceHelper.createProject(this.getName());
292+
// Add C/C++ and CMake natures to make it a CMake project
293+
IProjectDescription description = project.getDescription();
294+
description.setNatureIds(
295+
new String[] { CProjectNature.C_NATURE_ID, CCProjectNature.CC_NATURE_ID, CMakeNature.ID });
296+
project.setDescription(description, null);
297+
return project;
298+
}
299+
}

0 commit comments

Comments
 (0)