1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-10 17:55:39 +02:00

Bug 567488: Define command-line options to pass to cmake for build-script generation

Change-Id: Ie62549cf2c0ddbdb0c9934d3cdb928874b8362aa
Signed-off-by: Martin Weber <fifteenknots505@gmail.com>
This commit is contained in:
Martin Weber 2020-10-26 21:50:49 +01:00
parent 6a9a8d409d
commit 3a10f42019
11 changed files with 704 additions and 1 deletions

View file

@ -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

View file

@ -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<String> 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<String> getExtraArguments() {
return List.copyOf(extraArguments);
}
@Override
public void setExtraArguments(List<String> extraArguments) {
this.extraArguments = extraArguments;
}
}

View file

@ -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<String> 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<String> getExtraArguments() {
return List.copyOf(extraArguments);
}
@Override
public void setExtraArguments(List<String> 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();
}
}
}

View file

@ -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() {
}
}

View file

@ -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);
}
}

View file

@ -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;
}
}

View file

@ -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 <code>null</code> 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 <code>null</code> 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<String> getExtraArguments();
/**
* Sets the list of extra arguments to pass on the cmake command-line.
*/
void setExtraArguments(List<String> 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 <code>null</code> 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 <code>null</code> or {@link String#isBlank() blank}.
* @see #getCacheFile()
*/
void setCacheFile(String cacheFile);
/** Gets whether to clear the cmake-cache before build. If set to <code>true</code>, 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.<br>
*
* @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, <code>false</code>
* should be specified.
*/
void reset(boolean resetOsOverrides);
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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 <code>false</code>.
*/
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<String> getExtraArguments();
/**
* Sets the list of extra arguments to pass on the cmake command-line.
*/
void setExtraArguments(List<String> extraArguments);
}

View file

@ -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;