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 bfe4276a8f3..c1092ed2ebb 100644 --- a/cmake/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF +++ b/cmake/org.eclipse.cdt.cmake.core/META-INF/MANIFEST.MF @@ -16,6 +16,7 @@ Require-Bundle: org.eclipse.core.runtime, Bundle-RequiredExecutionEnvironment: JavaSE-11 Bundle-ActivationPolicy: lazy Export-Package: org.eclipse.cdt.cmake.core, - org.eclipse.cdt.cmake.core.internal;x-friends:="org.eclipse.cdt.cmake.ui" + org.eclipse.cdt.cmake.core.internal;x-friends:="org.eclipse.cdt.cmake.ui", + org.eclipse.cdt.cmake.core.properties Automatic-Module-Name: org.eclipse.cdt.cmake.core Bundle-Localization: plugin 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/internal/properties/AbstractOsOverrides.java new file mode 100644 index 00000000000..4451ca6ad69 --- /dev/null +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/properties/AbstractOsOverrides.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2020 Martin Weber. + * + * 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.internal.properties; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +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 + */ +public abstract class AbstractOsOverrides implements IOsOverrides { + + private String command; + private boolean useDefaultCommand; + private CMakeGenerator generator; + private List extraArguments = new ArrayList<>(0); + + /** + * Creates a new object, initialized with all default values. + */ + public AbstractOsOverrides() { + reset(); + } + + /** + * Sets each value to its default. + */ + public void reset() { + setCommand("cmake"); //$NON-NLS-1$ + useDefaultCommand = true; + setGenerator(CMakeGenerator.UnixMakefiles); + extraArguments.clear(); + } + + @Override + public final boolean getUseDefaultCommand() { + return useDefaultCommand; + } + + @Override + public void setUseDefaultCommand(boolean useDefaultCommand) { + this.useDefaultCommand = useDefaultCommand; + } + + @Override + public final String getCommand() { + return command; + } + + @Override + public void setCommand(String command) { + this.command = Objects.requireNonNull(command, "command"); //$NON-NLS-1$ + } + + @Override + public final CMakeGenerator getGenerator() { + return generator; + } + + @Override + public void setGenerator(CMakeGenerator generator) { + this.generator = Objects.requireNonNull(generator, "generator"); //$NON-NLS-1$ + } + + @Override + public final List getExtraArguments() { + return List.copyOf(extraArguments); + } + + @Override + public void setExtraArguments(List extraArguments) { + this.extraArguments = extraArguments; + } + +} \ 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 new file mode 100644 index 00000000000..241cc6beaf3 --- /dev/null +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/properties/CMakePropertiesBean.java @@ -0,0 +1,176 @@ +/******************************************************************************* + * Copyright (c) 2020 Martin Weber. + * + * 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.internal.properties; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +import org.eclipse.cdt.cmake.core.properties.ICMakeProperties; + +/** + * Holds project Properties for cmake. Follows the Java-Beans pattern to make (de-)serialization easier. + * + * @author Martin Weber + */ +public class CMakePropertiesBean implements ICMakeProperties { + + private boolean warnNoDev, debugTryCompile, debugOutput, trace, warnUnitialized, warnUnused; + private String cacheFile; + private boolean clearCache; + private List extraArguments = new ArrayList<>(0); + private LinuxOverrides linuxOverrides = new LinuxOverrides(); + private WindowsOverrides windowsOverrides = new WindowsOverrides(); + private String buildType; + + /** + * Creates a new object, initialized with all default values. + */ + public CMakePropertiesBean() { + reset(true); + } + + @Override + public boolean isWarnNoDev() { + return warnNoDev; + } + + @Override + public void setWarnNoDev(boolean warnNoDev) { + this.warnNoDev = warnNoDev; + } + + @Override + public boolean isDebugTryCompile() { + return debugTryCompile; + } + + @Override + public void setDebugTryCompile(boolean debugTryCompile) { + this.debugTryCompile = debugTryCompile; + } + + @Override + public boolean isDebugOutput() { + return debugOutput; + } + + @Override + public void setDebugOutput(boolean debugOutput) { + this.debugOutput = debugOutput; + } + + @Override + public boolean isTrace() { + return trace; + } + + @Override + public void setTrace(boolean trace) { + this.trace = trace; + } + + @Override + public boolean isWarnUnitialized() { + return warnUnitialized; + } + + @Override + public void setWarnUnitialized(boolean warnUnitialized) { + this.warnUnitialized = warnUnitialized; + } + + @Override + public boolean isWarnUnused() { + return warnUnused; + } + + @Override + public void setWarnUnused(boolean warnUnused) { + this.warnUnused = warnUnused; + } + + @Override + public String getBuildType() { + return buildType; + } + + @Override + public void setBuildType(String buildType) { + this.buildType = buildType; + } + + @Override + public List getExtraArguments() { + return List.copyOf(extraArguments); + } + + @Override + public void setExtraArguments(List extraArguments) { + this.extraArguments = extraArguments; + } + + @Override + public LinuxOverrides getLinuxOverrides() { + return linuxOverrides; + } + + public void setLinuxOverrides(LinuxOverrides linuxOverrides) { + this.linuxOverrides = linuxOverrides; + } + + @Override + public WindowsOverrides getWindowsOverrides() { + return windowsOverrides; + } + + public void setWindowsOverrides(WindowsOverrides windowsOverrides) { + this.windowsOverrides = windowsOverrides; + } + + @Override + public String getCacheFile() { + return cacheFile; + } + + @Override + public void setCacheFile(String cacheFile) { + this.cacheFile = Objects.requireNonNull(cacheFile); + } + + @Override + public boolean isClearCache() { + return clearCache; + } + + @Override + public void setClearCache(boolean clearCache) { + this.clearCache = clearCache; + } + + @Override + public void reset(boolean resetOsOverrides) { + warnNoDev = false; + debugTryCompile = false; + debugOutput = false; + trace = false; + warnUnitialized = false; + warnUnused = false; + extraArguments.clear(); + cacheFile = ""; //$NON-NLS-1$ + + if (resetOsOverrides) { + linuxOverrides.reset(); + windowsOverrides.reset(); + } + } +} 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/internal/properties/LinuxOverrides.java new file mode 100644 index 00000000000..d07699089d1 --- /dev/null +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/properties/LinuxOverrides.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2020 Martin Weber. + * + * 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.internal.properties; + +/** + * Preferences that override/augment the generic properties when running under + * Linux. + * + * @author Martin Weber + */ +public class LinuxOverrides extends AbstractOsOverrides { + + /** + * Creates a new object, initialized with all default values. + */ + public LinuxOverrides() { + } +} 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/internal/properties/WindowsOverrides.java new file mode 100644 index 00000000000..4e79f113d70 --- /dev/null +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/properties/WindowsOverrides.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2020 Martin Weber. + * + * 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.internal.properties; + +import org.eclipse.cdt.cmake.core.properties.CMakeGenerator; + +/** + * Preferences that override/augment the generic properties when running under + * Windows. + * + * @author Martin Weber + */ +public class WindowsOverrides extends AbstractOsOverrides { + + /** Overridden to set a sensible generator. */ + @Override + public void reset() { + super.reset(); + setGenerator(CMakeGenerator.MinGWMakefiles); + } +} diff --git a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/CMakeGenerator.java b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/CMakeGenerator.java new file mode 100644 index 00000000000..4841bf9f258 --- /dev/null +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/CMakeGenerator.java @@ -0,0 +1,83 @@ +/******************************************************************************* + * Copyright (c) 2020 Martin Weber. + * + * 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; + +/** + * Represents a cmake build-script generator including information about the + * makefile (build-script) processor that builds from the generated script. + * + * @author Martin Weber + */ +public enum CMakeGenerator { + /* + * Implementation Note: Please do not include generators for IDE project files, + * such as "Eclipse CDT4 - Unix Makefiles". + */ + + // linux generators + UnixMakefiles("Unix Makefiles"), //$NON-NLS-1$ + // Ninja + Ninja("Ninja", "-k 0") { //$NON-NLS-1$ //$NON-NLS-2$ + @Override + public String getMakefileName() { + return "build.ninja"; //$NON-NLS-1$ + } + }, + // windows generators + NMakeMakefilesJOM("NMake Makefiles JOM"), //$NON-NLS-1$ + MinGWMakefiles("MinGW Makefiles"), //$NON-NLS-1$ + MSYSMakefiles("MSYS Makefiles"), //$NON-NLS-1$ + NMakeMakefiles("NMake Makefiles"), //$NON-NLS-1$ + BorlandMakefiles("Borland Makefiles"), //$NON-NLS-1$ + WatcomWMake("Watcom WMake"); //$NON-NLS-1$ + + private final String name; + private String ignoreErrOption; + + private CMakeGenerator(String name, String ignoreErrOption) { + this.name = name; + this.ignoreErrOption = ignoreErrOption; + } + + private CMakeGenerator(String name) { + this(name, "-k"); //$NON-NLS-1$ + } + + /** + * Gets the cmake argument that specifies the build-script generator. + * + * @return a non-empty string, which must be a valid argument for cmake's -G + * option. + */ + public String getCMakeName() { + return name; + } + + /** + * Gets the name of the top-level makefile (build-script) which is interpreted + * by the build-script processor. + * + * @return name of the makefile. + */ + public String getMakefileName() { + return "Makefile"; //$NON-NLS-1$ + } + + /** + * Gets the build-script processor“s command argument(s) to ignore build errors. + * + * @return the command option string or {@code null} if no argument is needed. + */ + public String getIgnoreErrOption() { + return ignoreErrOption; + } +} 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 new file mode 100644 index 00000000000..d81577bf27d --- /dev/null +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/ICMakeProperties.java @@ -0,0 +1,158 @@ +/******************************************************************************* + * Copyright (c) 2020 Martin Weber. + * + * 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 java.util.List; + +/** + * Holds project Properties for cmake. + * + * @author Martin Weber + */ +public interface ICMakeProperties { + + /** + * {@code -Wno-dev} + */ + boolean isWarnNoDev(); + + /** + * {@code -Wno-dev} + */ + void setWarnNoDev(boolean warnNoDev); + + /** + * {@code --debug-trycompile} + */ + boolean isDebugTryCompile(); + + /** + * {@code --debug-trycompile} + */ + void setDebugTryCompile(boolean debugTryCompile); + + /** + * {@code --debug-output} + */ + boolean isDebugOutput(); + + /** + * {@code --debug-output} + */ + void setDebugOutput(boolean debugOutput); + + /** + * {@code --trace} + */ + boolean isTrace(); + + /** + * {@code --trace} + */ + void setTrace(boolean trace); + + /** + * {@code --warn-uninitialized} + */ + boolean isWarnUnitialized(); + + /** + * {@code --warn-uninitialized} + */ + void setWarnUnitialized(boolean warnUnitialized); + + /** + * {@code --warn-unused-vars} + */ + boolean isWarnUnused(); + + /** + * {@code --warn-unused-vars} + */ + void setWarnUnused(boolean warnUnused); + + /** Gets the build type ({@code Debug}, {@code Release}, ...). The returned value is passed to cmake + * as the {@code CMAKE_BUILD_TYPE} symbol on the command-line. + * + * @return the build type String. If null or {@link String#isBlank() blank}, no + * {@code CMAKE_BUILD_TYPE} symbol argument will be given to cmake, causing it to use its + * default build-type. + */ + String getBuildType(); + + /** Sets the build type. + * @param buildType the build type to set. May be null or {@link String#isBlank() blank}. + * @see #getBuildType() + */ + void setBuildType(String buildType); + + /** + * Gets the list of extra arguments to pass on the cmake command-line. + * + * @return a unmodifiable list, never {@code null} + * + */ + List getExtraArguments(); + + /** + * Sets the list of extra arguments to pass on the cmake command-line. + */ + void setExtraArguments(List extraArguments); + + /** + * Gets the name of the file that is used to pre-populate the cmake cache. + * {@code -C} + * + * @return the file name to set. If null or {@link String#isBlank() blank}, the cmake cache shall not be + * pre-populated. + */ + String getCacheFile(); + + /** + * Sets the name of the file that is used to pre-populate the cmake cache. + * {@code -C} + * + * @param cacheFile + * the file name. May be null or {@link String#isBlank() blank}. + * @see #getCacheFile() + */ + void setCacheFile(String cacheFile); + + /** Gets whether to clear the cmake-cache before build. If set to true, this will force to run cmake + * prior to each build. + */ + boolean isClearCache(); + + /** Sets whether to clear the cmake-cache before build. + */ + void setClearCache(boolean clearCache); + + /** + * Gets the override/augmenting properties to apply when the build runs on linux. + */ + IOsOverrides getLinuxOverrides(); + + /** + * Gets the override/augmenting properties to apply when the build runs on windows. + */ + IOsOverrides getWindowsOverrides(); + + /** + * Sets each property to its default value. This is intended for UIs that wish to implement a restore-defaults feature.
+ * + * @param resetOsOverrides + * whether to also reset the OS-specific overrides ({@link #getLinuxOverrides()}, + * {@link #getWindowsOverrides()}). If the overrides are displayed in separate tabs in the UI, false + * should be specified. + */ + void reset(boolean resetOsOverrides); +} \ 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 new file mode 100644 index 00000000000..8549e96fd0f --- /dev/null +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/ICMakePropertiesController.java @@ -0,0 +1,28 @@ +/******************************************************************************* + * Copyright (c) 2020 Martin Weber. + * + * 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; + +/** + * Responsible for loading and persting @code ICMakeProperties} objects. + * + * @author Martin Weber + */ +public interface ICMakePropertiesController { + + /** Creates a new {@code ICMakeProperties} object, initialized from the persistence store. + */ + ICMakeProperties load(); + + /** Saves the specified {@code ICMakeProperties} object to the persistence store. + */ + void save(ICMakeProperties properties); +} diff --git a/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/IGeneralProperties.java b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/IGeneralProperties.java new file mode 100644 index 00000000000..baa34b0176e --- /dev/null +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/IGeneralProperties.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (c) 2020 Martin Weber. + * + * 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; + +/** + * General, non-cmake related project settings. + * + * @author Martin Weber + * + */ +public interface IGeneralProperties { + + /** + * Gets the name of the top-level directory relative to the project root. + */ + String getSourceDirectory(); + + /** + * Sets the name of the top-level directory relative to the project root. + */ + void setSourceDirectory(String sourceDirectory); + + /** + * Gets the name of the build directory. + */ + String getBuildDirectory(); + + /** + * Sets the name of the build directory. + */ + void setBuildDirectory(String buildDirectory); +} \ No newline at end of file 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 new file mode 100644 index 00000000000..2d70ed7e62a --- /dev/null +++ b/cmake/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/properties/IOsOverrides.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2020 Martin Weber. + * + * 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 java.util.List; + +/** + * Properties that override/augment the generic properties when running under a + * specific OS. + * + * @author Martin Weber + */ +public interface IOsOverrides { + + /** + * Gets whether to use the default cmake command. + */ + boolean getUseDefaultCommand(); + + /** + * Sets whether to use the default cmake command. + */ + void setUseDefaultCommand(boolean useDefaultCommand); + + /** + * Gets the cmake command. Has no effect if {@link #getUseDefaultCommand()} returns false. + */ + String getCommand(); + + /** + * Sets the cmake command. + */ + void setCommand(String command); + + /** + * Gets the cmake buildscript generator. + */ + CMakeGenerator getGenerator(); + + /** + * Sets the cmake build-script generator. + */ + void setGenerator(CMakeGenerator generator); + + /** + * Gets the list of extra arguments to pass on the cmake command-line. + * + * @return an unmodifiable list, never {@code null} + */ + List getExtraArguments(); + + /** + * Sets the list of extra arguments to pass on the cmake command-line. + */ + void setExtraArguments(List extraArguments); +} \ No newline at end of file diff --git a/cmake/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/CMakePreferencePage.java b/cmake/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/CMakePreferencePage.java index 4c85aab6ae4..162955e6889 100644 --- a/cmake/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/CMakePreferencePage.java +++ b/cmake/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/CMakePreferencePage.java @@ -43,6 +43,9 @@ import org.eclipse.swt.widgets.TableItem; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; +/** + * GUI page to configure workbench preferences for cmake. + */ public class CMakePreferencePage extends PreferencePage implements IWorkbenchPreferencePage { private ICMakeToolChainManager manager;