From ac04d3b242d3dc0cb76cb546f4f9ac5871497378 Mon Sep 17 00:00:00 2001 From: John Moule Date: Fri, 17 Jan 2025 17:53:42 +0000 Subject: [PATCH] Add API to set CMake generator default (eg Ninja) ISV can set their desired CMake generator default (eg Ninja). Addresses Issue: CDT CMake Improvements #1000, IDE-82683-REQ-012 CMake generator default --- .../META-INF/MANIFEST.MF | 3 +- .../core/CMakeBuildConfigurationTests.java | 201 ++++++++++++++++++ .../META-INF/MANIFEST.MF | 2 +- .../cmake/core/CMakeBuildConfiguration.java | 115 ++++++---- .../core/CMakeBuildConfigurationProvider.java | 2 +- .../cmake/core/ICMakeBuildConfiguration.java | 26 +++ .../org/eclipse/cdt/cmake/core/Messages.java | 2 +- .../internal/CMakePropertiesController.java | 2 + .../properties/CMakePropertiesBean.java | 13 ++ .../properties/AbstractOsOverrides.java | 15 +- .../properties/CMakePropertiesFactory.java | 22 ++ .../core/properties/ICMakeProperties.java | 5 + .../ICMakePropertiesController.java | 1 + .../cmake/core/properties/IOsOverrides.java | 7 + .../properties/LinuxOverrides.java | 7 +- .../properties/WindowsOverrides.java | 12 +- .../META-INF/MANIFEST.MF | 3 +- 17 files changed, 371 insertions(+), 67 deletions(-) create mode 100644 cmake/org.eclipse.cdt.cmake.core.tests/src/org/eclipse/cdt/cmake/core/CMakeBuildConfigurationTests.java create mode 100644 cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/ICMakeBuildConfiguration.java rename cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/{internal => }/properties/AbstractOsOverrides.java (85%) create mode 100644 cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/CMakePropertiesFactory.java rename cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/{internal => }/properties/LinuxOverrides.java (84%) rename cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/{internal => }/properties/WindowsOverrides.java (71%) diff --git a/cmake/org.eclipse.cdt.cmake.core.tests/META-INF/MANIFEST.MF b/cmake/org.eclipse.cdt.cmake.core.tests/META-INF/MANIFEST.MF index a8ff015db30..b22df517ff1 100644 --- a/cmake/org.eclipse.cdt.cmake.core.tests/META-INF/MANIFEST.MF +++ b/cmake/org.eclipse.cdt.cmake.core.tests/META-INF/MANIFEST.MF @@ -9,5 +9,6 @@ Import-Package: org.assertj.core.api;version="[3.24.2,4.0.0)", Automatic-Module-Name: org.eclipse.cdt.cmake.core.tests Bundle-Vendor: %Bundle-Vendor Bundle-Copyright: %Bundle-Copyright -Require-Bundle: org.junit +Require-Bundle: org.junit, + org.eclipse.cdt.core.tests;bundle-version="[5.4.0,6.0.0)" diff --git a/cmake/org.eclipse.cdt.cmake.core.tests/src/org/eclipse/cdt/cmake/core/CMakeBuildConfigurationTests.java b/cmake/org.eclipse.cdt.cmake.core.tests/src/org/eclipse/cdt/cmake/core/CMakeBuildConfigurationTests.java new file mode 100644 index 00000000000..186c9c2dfb0 --- /dev/null +++ b/cmake/org.eclipse.cdt.cmake.core.tests/src/org/eclipse/cdt/cmake/core/CMakeBuildConfigurationTests.java @@ -0,0 +1,201 @@ +/******************************************************************************* + * Copyright (c) 2025 Renesas Electronics Europe. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.cdt.cmake.core; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.is; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.cdt.cmake.core.properties.CMakeGenerator; +import org.eclipse.cdt.cmake.core.properties.ICMakeProperties; +import org.eclipse.cdt.cmake.core.properties.IOsOverrides; +import org.eclipse.cdt.core.CCProjectNature; +import org.eclipse.cdt.core.CProjectNature; +import org.eclipse.cdt.core.testplugin.ResourceHelper; +import org.eclipse.cdt.core.testplugin.util.BaseTestCase5; +import org.eclipse.core.resources.IBuildConfiguration; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.runtime.CoreException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +/** + * Tests a new API added to the CMake Build Configuration which allows default CMake properties to be set. + * See the new interface {@link ICMakeBuildConfiguration}. + */ +public class CMakeBuildConfigurationTests extends BaseTestCase5 { + private IBuildConfiguration buildConfig; + + @BeforeEach + public void setup() throws Exception { + // Create a CMake project + IProject project = createCMakeProject(); + // Get the default build config from the project (it always has one) + buildConfig = project.getBuildConfig(IBuildConfiguration.DEFAULT_CONFIG_NAME); + } + + /** + * Test for {@link IOsOverrides#setGenerator()}. + */ + @Test + public void getCMakePropertiesTestSetGenerator() throws Exception { + CMakeBuildConfigurationExtended cmBuildConfig = new CMakeBuildConfigurationExtended(buildConfig, + "cmBuildConfigName") { + + @Override + public ICMakeProperties getCMakeProperties() { + ICMakeProperties properties = super.getCMakeProperties(); + + IOsOverrides windowsOverrides = properties.getWindowsOverrides(); + windowsOverrides.setGenerator(CMakeGenerator.NMakeMakefiles); + IOsOverrides linuxOverrides = properties.getLinuxOverrides(); + linuxOverrides.setGenerator(CMakeGenerator.UnixMakefiles); + return properties; + } + }; + + // Call the new method on ICMakeBuildConfiguration to get the default CMake properties. + ICMakeProperties cMakeProperties = cmBuildConfig.getCMakeProperties(); + + // Get overrides for Windows host and check the default value for getGenerator. + IOsOverrides windowsOverrides = cMakeProperties.getWindowsOverrides(); + CMakeGenerator winGenerator = windowsOverrides.getGenerator(); + assertThat(winGenerator, is(CMakeGenerator.NMakeMakefiles)); + + // Get overrides for Linux host and check the default value for getGenerator. + IOsOverrides linuxOverrides = cMakeProperties.getLinuxOverrides(); + CMakeGenerator linuxGenerator = linuxOverrides.getGenerator(); + assertThat(linuxGenerator, is(CMakeGenerator.UnixMakefiles)); + } + + /** + * Test for {@link IOsOverrides#setDefaultGenerator()}. Also tests that {@link ICMakeProperties#reset(boolean)} works as expected. + */ + @Test + public void getCMakePropertiesTestSetDefaultGenerator() throws Exception { + CMakeBuildConfigurationExtended cmBuildConfig = new CMakeBuildConfigurationExtended(buildConfig, + "cmBuildConfigName") { + + @Override + public ICMakeProperties getCMakeProperties() { + ICMakeProperties properties = super.getCMakeProperties(); + + IOsOverrides windowsOverrides = properties.getWindowsOverrides(); + windowsOverrides.setDefaultGenerator(CMakeGenerator.NMakeMakefiles); + IOsOverrides linuxOverrides = properties.getLinuxOverrides(); + linuxOverrides.setDefaultGenerator(CMakeGenerator.UnixMakefiles); + // reset(true) causes the CMake generator to be reset to it's default value. + properties.reset(true); + return properties; + } + }; + + // Call the new method on ICMakeBuildConfiguration to get the default CMake properties. + ICMakeProperties cMakeProperties = cmBuildConfig.getCMakeProperties(); + + // Get overrides for Windows host and check the default value for getGenerator. + IOsOverrides windowsOverrides = cMakeProperties.getWindowsOverrides(); + CMakeGenerator winGenerator = windowsOverrides.getGenerator(); + assertThat(winGenerator, is(CMakeGenerator.NMakeMakefiles)); + + // Get overrides for Linux host and check the default value for getGenerator. + IOsOverrides linuxOverrides = cMakeProperties.getLinuxOverrides(); + CMakeGenerator linuxGenerator = linuxOverrides.getGenerator(); + assertThat(linuxGenerator, is(CMakeGenerator.UnixMakefiles)); + } + + /** + * Test for {@link ICMakeProperties#setExtraArguments()} + * This is a different extraArguments to IOsOverrides#setExtraArguments(). + * Presumably ICMakeProperties#setExtraArguments() are platform agnostic extra arguments, where as + * IOsOverrides#setExtraArguments() can be set different for Linux and Windows. + */ + @Test + public void getCMakePropertiesTestSetExtraArguments() throws Exception { + // Create a C Build Configuration using the default build config and an arbitrary name + CMakeBuildConfigurationExtended cmBuildConfig = new CMakeBuildConfigurationExtended(buildConfig, + "cmBuildConfigName") { + + @Override + public ICMakeProperties getCMakeProperties() { + ICMakeProperties properties = super.getCMakeProperties(); + properties.setExtraArguments( + new ArrayList<>((List.of("-DplatformAgnosticArgsTest0=0", "-DplatformAgnosticArgsTest1=1")))); + return properties; + } + }; + // Call the new method on ICMakeBuildConfiguration to get the default CMake properties. + ICMakeProperties cMakeProperties = cmBuildConfig.getCMakeProperties(); + List extraArguments = cMakeProperties.getExtraArguments(); + assertThat(extraArguments, contains("-DplatformAgnosticArgsTest0=0", "-DplatformAgnosticArgsTest1=1")); + } + + /** + * Test for {@link IOsOverrides#setExtraArguments()} + */ + @Test + public void getCMakePropertiesTestIOsOverridesSetExtraArguments() throws Exception { + // Create a C Build Configuration using the default build config and an arbitrary name + CMakeBuildConfigurationExtended cmBuildConfig = new CMakeBuildConfigurationExtended(buildConfig, + "cmBuildConfigName"); + // Call the new method on ICMakeBuildConfiguration to get the default CMake properties. + ICMakeProperties cMakeProperties = cmBuildConfig.getCMakeProperties(); + + // Get overrides for Windows host and check the default value for getExtraArguments. + IOsOverrides windowsOverrides = cMakeProperties.getWindowsOverrides(); + List winExtraArguments = windowsOverrides.getExtraArguments(); + assertThat(winExtraArguments, contains("-Dtest0=0", "-Dtest1=1")); + + // Get overrides for Linux host and check the default value for getExtraArguments. + IOsOverrides linuxOverrides = cMakeProperties.getLinuxOverrides(); + List linuxExtraArguments = linuxOverrides.getExtraArguments(); + assertThat(linuxExtraArguments, contains("-DLinuxtest0=0", "-DLinuxtest1=1")); + } + + private class CMakeBuildConfigurationExtended extends CMakeBuildConfiguration { + + public CMakeBuildConfigurationExtended(IBuildConfiguration config, String name) throws CoreException { + super(config, name); + } + + @Override + public ICMakeProperties getCMakeProperties() { + // get the built-in CDT defaults + ICMakeProperties properties = super.getCMakeProperties(); + + // provide my customizations (I don't know what Renesas/extenders may actually want to do here) + properties.setWarnUnitialized(true); + + IOsOverrides windowsOverrides = properties.getWindowsOverrides(); + windowsOverrides.setExtraArguments(new ArrayList<>((List.of("-Dtest0=0", "-Dtest1=1")))); + + IOsOverrides linuxOverrides = properties.getLinuxOverrides(); + linuxOverrides.setExtraArguments(new ArrayList<>((List.of("-DLinuxtest0=0", "-DLinuxtest1=1")))); + + return properties; + } + } + + private IProject createCMakeProject() throws Exception { + // Create a plain Eclipse project + IProject project = ResourceHelper.createProject(this.getName()); + // Add C/C++ and CMake natures to make it a CMake project + IProjectDescription description = project.getDescription(); + description.setNatureIds( + new String[] { CProjectNature.C_NATURE_ID, CCProjectNature.CC_NATURE_ID, CMakeNature.ID }); + project.setDescription(description, null); + return project; + } +} diff --git a/cmake/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF b/cmake/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF index e805cfdfcc0..c051e258602 100644 --- a/cmake/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF +++ b/cmake/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.cdt.cmake.core;singleton:=true -Bundle-Version: 1.6.0.qualifier +Bundle-Version: 2.0.0.qualifier Bundle-Activator: org.eclipse.cdt.cmake.core.internal.Activator Bundle-Vendor: %providerName Require-Bundle: org.eclipse.core.runtime, diff --git a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeBuildConfiguration.java b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeBuildConfiguration.java index 5b437b7bd35..2714c90b700 100644 --- a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeBuildConfiguration.java +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeBuildConfiguration.java @@ -34,6 +34,7 @@ import org.eclipse.cdt.cmake.core.internal.CommandDescriptorBuilder.CommandDescriptor; import org.eclipse.cdt.cmake.core.internal.IOsOverridesSelector; import org.eclipse.cdt.cmake.core.properties.CMakeGenerator; +import org.eclipse.cdt.cmake.core.properties.CMakePropertiesFactory; import org.eclipse.cdt.cmake.core.properties.ICMakeProperties; import org.eclipse.cdt.cmake.core.properties.ICMakePropertiesController; import org.eclipse.cdt.cmake.core.properties.IOsOverrides; @@ -72,13 +73,14 @@ import org.osgi.service.prefs.Preferences; /** - * @since 1.6 + * @since 2.0 */ -public class CMakeBuildConfiguration extends CBuildConfiguration { +public class CMakeBuildConfiguration extends CBuildConfiguration implements ICMakeBuildConfiguration { public static final String CMAKE_USE_UI_OVERRIDES = "cmake.use.ui.overrides"; //$NON-NLS-1$ public static final boolean CMAKE_USE_UI_OVERRIDES_DEFAULT = false; public static final String CMAKE_GENERATOR = "cmake.generator"; //$NON-NLS-1$ + public static final String CMAKE_GENERATOR_DEFAULT = "Ninja"; //$NON-NLS-1$ public static final String CMAKE_ARGUMENTS = "cmake.arguments"; //$NON-NLS-1$ public static final String CMAKE_ENV = "cmake.environment"; //$NON-NLS-1$ public static final String BUILD_COMMAND = "cmake.command.build"; //$NON-NLS-1$ @@ -124,6 +126,45 @@ public CMakeBuildConfiguration(IBuildConfiguration config, String name, IToolCha this.toolChainFile = toolChainFile; } + @Override + public ICMakeProperties getCMakeProperties() { + // Create CMake default properties + ICMakeProperties properties = CMakePropertiesFactory.createProperties(); + // Set defaults for both platforms + IOsOverrides windowsOverrides = properties.getWindowsOverrides(); + windowsOverrides.setDefaultGenerator(CMakeGenerator.Ninja); + IOsOverrides linuxOverrides = properties.getLinuxOverrides(); + linuxOverrides.setDefaultGenerator(CMakeGenerator.Ninja); + // reset(true) causes the CMake generator to be reset to it's default value. + properties.reset(true); + + /* + * Set values for this OS platform for CMake defaults and if UI overrides is enable for UI property values + */ + IOsOverrides osOverrides = properties.getPlatformOsOverrides(properties); + // CMAKE_GENERATOR + String cmakeGeneratorCmakeDefault = osOverrides.getGenerator().getCMakeName(); + // CMAKE_ARGUMENTS + String extraArgsCmakeDefault = osOverrides.getExtraArguments().stream().map(String::trim) + .collect(Collectors.joining(" ")); //$NON-NLS-1$ + + String useUiOverrides = getProperty(CMAKE_USE_UI_OVERRIDES); + if (Boolean.parseBoolean(useUiOverrides)) { + // UI overrides are enabled so UI overridden values take precedence if not null otherwise use CMake default + // CMAKE_GENERATOR + String cmakeGeneratorUiValue = getProperty(CMakeBuildConfiguration.CMAKE_GENERATOR); + String cmakeGenerator = cmakeGeneratorUiValue == null ? cmakeGeneratorCmakeDefault : cmakeGeneratorUiValue; + osOverrides.setGenerator(CMakeGenerator.getGenerator(cmakeGenerator)); + // CMAKE_ARGUMENTS + String extraArgsUiValue = getProperty(CMAKE_ARGUMENTS); + String extraArgs = extraArgsUiValue == null ? extraArgsCmakeDefault : extraArgsUiValue; + List extraArgsList = Arrays.stream(extraArgs.split("\\s+")).map(entry -> entry.trim()) //$NON-NLS-1$ + .collect(Collectors.toList()); + osOverrides.setExtraArguments(extraArgsList); + } + return properties; + } + /** * Gets the tool-chain description file to pass to the cmake command-line. * @@ -162,7 +203,8 @@ public IProject[] build(int kind, Map args, IConsole console, IP runCMake = true; } - ICMakeProperties cmakeProperties = getPropertiesController().load(); + ICMakeProperties cmakeProperties = getCMakeProperties(); + runCMake |= !Files.exists(buildDir.resolve("CMakeCache.txt")); //$NON-NLS-1$ // Causes CMAKE_BUILD_TYPE to be set according to the launch mode @@ -303,7 +345,7 @@ public void clean(IConsole console, IProgressMonitor monitor) throws CoreExcepti project.deleteMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE); - ICMakeProperties cmakeProperties = getPropertiesController().load(); + ICMakeProperties cmakeProperties = getCMakeProperties(); CommandDescriptorBuilder cmdBuilder = new CommandDescriptorBuilder(cmakeProperties, new SimpleOsOverridesSelector()); CommandDescriptor command = cmdBuilder.makeCMakeBuildCommandline(getCleanCommand()); @@ -405,7 +447,7 @@ private ICMakePropertiesController getPropertiesController() { @SuppressWarnings("unchecked") public T getAdapter(Class adapter) { if (ICMakePropertiesController.class.equals(adapter)) { - return (T) pc; + return (T) getPropertiesController(); } return super.getAdapter(adapter); } @@ -582,50 +624,33 @@ public void shutdown() { } } // CMakeIndexerInfoConsumer - /** - * Supports OS overrides and also User Interface (UI) overrides, provided in the CMakeBuildTab. The UI - * overrides are stored in the intermediary CBuildConfiguration Preferences (CBuildConfiguration.getSettings()) - * and used only when CMAKE_USE_UI_OVERRIDES is true. - */ private class SimpleOsOverridesSelector implements IOsOverridesSelector { @Override public IOsOverrides getOsOverrides(ICMakeProperties cmakeProperties) { - IOsOverrides overrides; - // get overrides. Simplistic approach ATM, probably a strategy might fit better. - // see comment in CMakeIndexerInfoConsumer#getFileForCMakePath() - final String os = Platform.getOS(); - if (Platform.OS_WIN32.equals(os)) { - overrides = cmakeProperties.getWindowsOverrides(); - } else { - // fall back to linux, if OS is unknown - overrides = cmakeProperties.getLinuxOverrides(); - } - return getUiOrOsOverrides(overrides); - } - - private IOsOverrides getUiOrOsOverrides(IOsOverrides osOverrides) { - IOsOverrides retVal = Objects.requireNonNull(osOverrides, "osOverrides must not be null"); //$NON-NLS-1$ - Preferences settings = getSettings(); - boolean useUiOverrides = settings.getBoolean(CMAKE_USE_UI_OVERRIDES, CMAKE_USE_UI_OVERRIDES_DEFAULT); - if (useUiOverrides) { - // Set UI override for generator - String gen = settings.get(CMAKE_GENERATOR, ""); //$NON-NLS-1$ - retVal.setGenerator(CMakeGenerator.getGenerator(gen)); - // Set UI override for Extra Arguments - String extraArgsStr = settings.get(CMAKE_ARGUMENTS, ""); //$NON-NLS-1$ - // Convert String of args, separated by 1 or more spaces, into list of Strings - List extraArgs = Arrays.stream(extraArgsStr.split("\\s+")).map(entry -> entry.trim()) //$NON-NLS-1$ - .collect(Collectors.toList()); - retVal.setExtraArguments(extraArgs); - // Set UI override for cmake build command, unless it's the default - String buildCommand = settings.get(BUILD_COMMAND, BUILD_COMMAND_DEFAULT); - if (!buildCommand.isBlank() && !BUILD_COMMAND_DEFAULT.equals(buildCommand)) { - retVal.setUseDefaultCommand(false); - retVal.setCommand(buildCommand); - } - } - return retVal; + return cmakeProperties.getPlatformOsOverrides(cmakeProperties); } } // SimpleOsOverridesSelector + + @Override + public Map getDefaultProperties() { + return Map.of(// + CMAKE_GENERATOR, CMAKE_GENERATOR_DEFAULT, // + CMAKE_USE_UI_OVERRIDES, Boolean.toString(CMAKE_USE_UI_OVERRIDES_DEFAULT), // + CMAKE_ARGUMENTS, "" // //$NON-NLS-1$ + ); + } + + @Override + public Map getProperties() { + var map = new HashMap(); + map.putAll(getDefaultProperties()); + map.putAll(super.getProperties()); + return map; + } + + @Override + public String getProperty(String name) { + return getSettings().get(name, getDefaultProperties().get(name)); + } } diff --git a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeBuildConfigurationProvider.java b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeBuildConfigurationProvider.java index ab2b976a532..d1bf2dd7cb5 100644 --- a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeBuildConfigurationProvider.java +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/CMakeBuildConfigurationProvider.java @@ -27,7 +27,7 @@ import org.eclipse.core.runtime.Platform; /** - * @since 1.6 + * @since 2.0 */ public class CMakeBuildConfigurationProvider implements ICBuildConfigurationProvider { diff --git a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/ICMakeBuildConfiguration.java b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/ICMakeBuildConfiguration.java new file mode 100644 index 00000000000..12d6a35344a --- /dev/null +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/ICMakeBuildConfiguration.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2025 Renesas Electronics Europe. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.cdt.cmake.core; + +import org.eclipse.cdt.cmake.core.properties.ICMakeProperties; + +/** + * @since 2.0 + */ +public interface ICMakeBuildConfiguration { + + /** + * Provides a set of default CMake properties. The ICMakeProperties can then, for + * example, provide a default value for the CMake generator. + * @return A ICMakeProperties object containing default values. Must not be null. + */ + ICMakeProperties getCMakeProperties(); +} diff --git a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/Messages.java b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/Messages.java index 8fb930da018..127052040b7 100644 --- a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/Messages.java +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/Messages.java @@ -16,7 +16,7 @@ * @noextend This class is not intended to be subclassed by clients. * @noinstantiate This class is not intended to be instantiated by clients. * @noreference This class is not intended to be referenced by clients. - * @since 1.6 + * @since 2.0 */ public class Messages extends NLS { private static final String BUNDLE_NAME = "org.eclipse.cdt.cmake.core.messages"; //$NON-NLS-1$ diff --git a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakePropertiesController.java b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakePropertiesController.java index f857357b490..75eaea39c9a 100644 --- a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakePropertiesController.java +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakePropertiesController.java @@ -41,6 +41,7 @@ * us to delete file CMakeCache.txt to avoid complaints by cmake. * @author Martin Weber */ +@Deprecated public class CMakePropertiesController implements ICMakePropertiesController { private final Path storageFile; @@ -158,4 +159,5 @@ private boolean hasExtraArgumentChanged(List expected, List actu } return false; } + } \ No newline at end of file diff --git a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/properties/CMakePropertiesBean.java b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/properties/CMakePropertiesBean.java index e24b40c8e66..024febe92af 100644 --- a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/properties/CMakePropertiesBean.java +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/properties/CMakePropertiesBean.java @@ -15,6 +15,10 @@ import java.util.List; import org.eclipse.cdt.cmake.core.properties.ICMakeProperties; +import org.eclipse.cdt.cmake.core.properties.IOsOverrides; +import org.eclipse.cdt.cmake.core.properties.LinuxOverrides; +import org.eclipse.cdt.cmake.core.properties.WindowsOverrides; +import org.eclipse.core.runtime.Platform; /** * Holds project Properties for cmake. Follows the Java-Beans pattern to make (de-)serialization easier. @@ -172,4 +176,13 @@ public void reset(boolean resetOsOverrides) { windowsOverrides.reset(); } } + + @Override + public IOsOverrides getPlatformOsOverrides(ICMakeProperties cmakeProperties) { + if (Platform.OS_WIN32.equals(Platform.getOS())) { + return cmakeProperties.getWindowsOverrides(); + } else { + return cmakeProperties.getLinuxOverrides(); + } + } } diff --git a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/properties/AbstractOsOverrides.java b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/AbstractOsOverrides.java similarity index 85% rename from cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/properties/AbstractOsOverrides.java rename to cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/AbstractOsOverrides.java index 8d5909c74d5..0ab625540ed 100644 --- a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/properties/AbstractOsOverrides.java +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/AbstractOsOverrides.java @@ -9,21 +9,20 @@ * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ -package org.eclipse.cdt.cmake.core.internal.properties; +package org.eclipse.cdt.cmake.core.properties; import java.util.ArrayList; import java.util.List; import java.util.Objects; import org.eclipse.cdt.cmake.core.CMakeBuildConfiguration; -import org.eclipse.cdt.cmake.core.properties.CMakeGenerator; -import org.eclipse.cdt.cmake.core.properties.IOsOverrides; /** * Preferences that override/augment the generic properties when running under a * specific OS. * * @author Martin Weber + * @since 2.0 */ public abstract class AbstractOsOverrides implements IOsOverrides { @@ -31,6 +30,8 @@ public abstract class AbstractOsOverrides implements IOsOverrides { private boolean useDefaultCommand; private CMakeGenerator generator; private List extraArguments = new ArrayList<>(0); + private CMakeGenerator defaultGenerator = CMakeGenerator + .getGenerator(CMakeBuildConfiguration.CMAKE_GENERATOR_DEFAULT); /** * Creates a new object, initialized with all default values. @@ -45,7 +46,7 @@ public AbstractOsOverrides() { public void reset() { setCommand(CMakeBuildConfiguration.BUILD_COMMAND_DEFAULT); useDefaultCommand = true; - setGenerator(CMakeGenerator.UnixMakefiles); + setGenerator(defaultGenerator); extraArguments.clear(); } @@ -89,4 +90,8 @@ public void setExtraArguments(List extraArguments) { this.extraArguments = extraArguments; } -} \ No newline at end of file + @Override + public void setDefaultGenerator(CMakeGenerator defaultGenerator) { + this.defaultGenerator = defaultGenerator; + } +} diff --git a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/CMakePropertiesFactory.java b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/CMakePropertiesFactory.java new file mode 100644 index 00000000000..71336495d75 --- /dev/null +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/CMakePropertiesFactory.java @@ -0,0 +1,22 @@ +/******************************************************************************* + * Copyright (c) 2025 Renesas Electronics Europe. + * + * This program and the accompanying materials + * are made available under the terms of the Eclipse Public License 2.0 + * which accompanies this distribution, and is available at + * https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + *******************************************************************************/ +package org.eclipse.cdt.cmake.core.properties; + +import org.eclipse.cdt.cmake.core.internal.properties.CMakePropertiesBean; + +/** + * @since 2.0 + */ +public class CMakePropertiesFactory { + public static ICMakeProperties createProperties() { + return new CMakePropertiesBean(); + } +} diff --git a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/ICMakeProperties.java b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/ICMakeProperties.java index a817efc78b2..3f885f82e9b 100644 --- a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/ICMakeProperties.java +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/ICMakeProperties.java @@ -159,4 +159,9 @@ public interface ICMakeProperties { * should be specified. */ void reset(boolean resetOsOverrides); + + /** + * @since 2.0 + */ + IOsOverrides getPlatformOsOverrides(ICMakeProperties cmakeProperties); } \ No newline at end of file diff --git a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/ICMakePropertiesController.java b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/ICMakePropertiesController.java index 09a6e717fee..9607e9ab01a 100644 --- a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/ICMakePropertiesController.java +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/ICMakePropertiesController.java @@ -19,6 +19,7 @@ * @author Martin Weber * @since 1.4 */ +@Deprecated public interface ICMakePropertiesController { /** Creates a new {@code ICMakeProperties} object, initialized from the persistence store. diff --git a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/IOsOverrides.java b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/IOsOverrides.java index 37f4dfe801b..e4aba9d7f82 100644 --- a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/IOsOverrides.java +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/IOsOverrides.java @@ -63,4 +63,11 @@ public interface IOsOverrides { * Sets the list of extra arguments to pass on the cmake command-line. */ void setExtraArguments(List extraArguments); + + /** + * Sets a value that is used when a {@link ICMakeProperties#reset(true)} call is performed, setting the value + * of the CMake generator (see {@link #getGenerator()}) to it's default value. + * @since 2.0 + */ + void setDefaultGenerator(CMakeGenerator defaultGenerator); } \ No newline at end of file diff --git a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/properties/LinuxOverrides.java b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/LinuxOverrides.java similarity index 84% rename from cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/properties/LinuxOverrides.java rename to cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/LinuxOverrides.java index d07699089d1..55c842dfb76 100644 --- a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/properties/LinuxOverrides.java +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/LinuxOverrides.java @@ -9,19 +9,18 @@ * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ -package org.eclipse.cdt.cmake.core.internal.properties; +package org.eclipse.cdt.cmake.core.properties; /** * Preferences that override/augment the generic properties when running under * Linux. * * @author Martin Weber + * @since 2.0 */ public class LinuxOverrides extends AbstractOsOverrides { - /** - * Creates a new object, initialized with all default values. - */ public LinuxOverrides() { + super(); } } diff --git a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/properties/WindowsOverrides.java b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/WindowsOverrides.java similarity index 71% rename from cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/properties/WindowsOverrides.java rename to cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/WindowsOverrides.java index 4e79f113d70..939df6450f4 100644 --- a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/properties/WindowsOverrides.java +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/WindowsOverrides.java @@ -9,22 +9,18 @@ * SPDX-License-Identifier: EPL-2.0 *******************************************************************************/ -package org.eclipse.cdt.cmake.core.internal.properties; - -import org.eclipse.cdt.cmake.core.properties.CMakeGenerator; +package org.eclipse.cdt.cmake.core.properties; /** * Preferences that override/augment the generic properties when running under * Windows. * * @author Martin Weber + * @since 2.0 */ public class WindowsOverrides extends AbstractOsOverrides { - /** Overridden to set a sensible generator. */ - @Override - public void reset() { - super.reset(); - setGenerator(CMakeGenerator.MinGWMakefiles); + public WindowsOverrides() { + super(); } } diff --git a/debug/org.eclipse.cdt.debug.core/META-INF/MANIFEST.MF b/debug/org.eclipse.cdt.debug.core/META-INF/MANIFEST.MF index 659be2ed292..bbc9c9a3d58 100644 --- a/debug/org.eclipse.cdt.debug.core/META-INF/MANIFEST.MF +++ b/debug/org.eclipse.cdt.debug.core/META-INF/MANIFEST.MF @@ -44,7 +44,8 @@ Require-Bundle: org.eclipse.cdt.core;bundle-version="[8.3.0,9.0.0)", org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)", org.eclipse.core.variables;bundle-version="3.2.0", org.eclipse.debug.core;bundle-version="[3.2.0,4.0.0)", - org.eclipse.launchbar.core;bundle-version="2.0.0" + org.eclipse.launchbar.core;bundle-version="2.0.0", + org.eclipse.cdt.cmake.core Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-17 Automatic-Module-Name: org.eclipse.cdt.debug.core