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
index 051c3762e5b..97e293f82bb 100644
--- 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
@@ -35,6 +35,7 @@ import org.eclipse.cdt.utils.CommandLineUtil;
import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
import org.junit.jupiter.api.BeforeEach;
@@ -91,6 +92,106 @@ public class CMakeBuildConfigurationTests extends BaseTestCase5 {
assertThat(cMakeProperties.getGenerator(), is(CMakeGenerator.WatcomWMake));
}
+ /**
+ * Test for IDE_82683_REQ_013 part of #1000
+ *
+ * Testing {@link ICMakeProperties#getBuildType()}
+ *
+ * This test verify default build type is used in case:
+ * {@link ICMakeBuildConfiguration#CMAKE_USE_DEFAULT_CMAKE_SETTINGS} is true
+ */
+ @Test
+ public void getCMakePropertiesTestGetDefaultBuildType() {
+ // CMAKE_USE_DEFAULT_CMAKE_SETTINGS = "true"
+ CMakeBuildConfiguration cmBuildConfig;
+ ICMakeProperties cMakeProperties;
+ // Test for ILaunchManager.RUN_MODE
+ cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName", mockToolchain, null,
+ ILaunchManager.RUN_MODE, LOCAL_LAUNCH_TARGET);
+ cMakeProperties = cmBuildConfig.getCMakeProperties();
+ assertThat(cMakeProperties.getBuildType(), is("Release"));
+
+ // Test for ILaunchManager.DEBUG_MODE
+ cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName", mockToolchain, null,
+ ILaunchManager.DEBUG_MODE, LOCAL_LAUNCH_TARGET);
+ cMakeProperties = cmBuildConfig.getCMakeProperties();
+ assertThat(cMakeProperties.getBuildType(), is("Debug"));
+
+ // Test for ILaunchManager.PROFILE_MODE
+ cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName", mockToolchain, null,
+ ILaunchManager.PROFILE_MODE, LOCAL_LAUNCH_TARGET);
+ cMakeProperties = cmBuildConfig.getCMakeProperties();
+ assertThat(cMakeProperties.getBuildType(), is("Release"));
+ }
+
+ /**
+ * Test for IDE_82683_REQ_013 part of #1000
+ *
+ * This test verify default build type is used in case:
+ * {@link ICMakeBuildConfiguration#CMAKE_USE_DEFAULT_CMAKE_SETTINGS} is true
+ */
+ @Test
+ public void getCMakePropertiesLoadISVSelectBuildType_UseDefaultBuildType_1() {
+ ICMakeProperties cMakeProperties;
+ CMakeBuildConfiguration cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName",
+ mockToolchain, null, ILaunchManager.RUN_MODE, LOCAL_LAUNCH_TARGET);
+ // Setup ISV properties for CMakeBuildConfiguration
+ // CMAKE_USE_DEFAULT_CMAKE_SETTINGS = "true"
+ // CMAKE_BUILD_TYPE = "RelWithDebInfo"
+ cmBuildConfig.removeProperty(CMakeBuildConfiguration.CMAKE_BUILD_TYPE);
+ cmBuildConfig.setProperty(CMakeBuildConfiguration.CMAKE_USE_DEFAULT_CMAKE_SETTINGS, "true");
+ cmBuildConfig.setProperty(CMakeBuildConfiguration.CMAKE_BUILD_TYPE, "RelWithDebInfo");
+ // Expected: default build type is used (in this case: "Release" for ILaunchManager.RUN_MODE)
+ cMakeProperties = cmBuildConfig.getCMakeProperties();
+ assertThat(cMakeProperties.getBuildType(), is("Release"));
+ }
+
+ /**
+ * Test for IDE_82683_REQ_013 part of #1000
+ *
+ * This test verify default build type is used in case ISV build type is blank:
+ * {@link ICMakeBuildConfiguration#CMAKE_USE_DEFAULT_CMAKE_SETTINGS} is false and
+ * {@link ICMakeBuildConfiguration#CMAKE_BUILD_TYPE} is blank
+ */
+ @Test
+ public void getCMakePropertiesLoadISVSelectBuildType_ISVBuildTypeIsBlank() {
+ ICMakeProperties cMakeProperties;
+ CMakeBuildConfiguration cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName",
+ mockToolchain, null, ILaunchManager.RUN_MODE, LOCAL_LAUNCH_TARGET);
+ // Setup ISV properties for CMakeBuildConfiguration
+ // CMAKE_USE_DEFAULT_CMAKE_SETTINGS = "false"
+ // CMAKE_BUILD_TYPE = ""
+ cmBuildConfig.removeProperty(CMakeBuildConfiguration.CMAKE_BUILD_TYPE);
+ cmBuildConfig.setProperty(CMakeBuildConfiguration.CMAKE_USE_DEFAULT_CMAKE_SETTINGS, "false");
+ cmBuildConfig.setProperty(CMakeBuildConfiguration.CMAKE_BUILD_TYPE, "");
+ // Expected: "Release" build type is used (in this case: "Release" for ILaunchManager.RUN_MODE)
+ cMakeProperties = cmBuildConfig.getCMakeProperties();
+ assertThat(cMakeProperties.getBuildType(), is("Release"));
+ }
+
+ /**
+ * Test for IDE_82683_REQ_013 part of #1000
+ *
+ * This test verify ISV's selected build type is used in case:
+ * {@link ICMakeBuildConfiguration#CMAKE_USE_DEFAULT_CMAKE_SETTINGS} is false and
+ * {@link ICMakeBuildConfiguration#CMAKE_BUILD_TYPE} is NOT blank
+ */
+ @Test
+ public void getCMakePropertiesLoadISVSelectBuildType_UseISVBuildTypeNotBlank() {
+ ICMakeProperties cMakeProperties;
+ CMakeBuildConfiguration cmBuildConfig = new CMakeBuildConfiguration(buildConfig, "cmBuildConfigName",
+ mockToolchain, null, ILaunchManager.RUN_MODE, LOCAL_LAUNCH_TARGET);
+ // Setup ISV properties for CMakeBuildConfiguration
+ // CMAKE_USE_DEFAULT_CMAKE_SETTINGS = "false"
+ // CMAKE_BUILD_TYPE = "RelWithDebInfo"
+ cmBuildConfig.removeProperty(CMakeBuildConfiguration.CMAKE_BUILD_TYPE);
+ cmBuildConfig.setProperty(CMakeBuildConfiguration.CMAKE_USE_DEFAULT_CMAKE_SETTINGS, "false");
+ cmBuildConfig.setProperty(CMakeBuildConfiguration.CMAKE_BUILD_TYPE, "RelWithDebInfo");
+ // Expected: "RelWithDebInfo" build type is used
+ cMakeProperties = cmBuildConfig.getCMakeProperties();
+ assertThat(cMakeProperties.getBuildType(), is("RelWithDebInfo"));
+ }
+
/**
* Test for {@link ICMakeProperties#setExtraArguments()}
*
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 7a4d63a5322..c2ee6a5fc70 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
@@ -139,6 +139,12 @@ public class CMakeBuildConfiguration extends CBuildConfiguration implements ICMa
cmakeProperties.setAllTarget(allTarget);
}
+ String buildType = properties.get(CMAKE_BUILD_TYPE);
+ if (buildType == null || buildType.isBlank()) {
+ buildType = getDefaultProperties().get(CMAKE_BUILD_TYPE);
+ }
+ cmakeProperties.setBuildType(buildType);
+
return cmakeProperties;
}
@@ -178,13 +184,6 @@ public class CMakeBuildConfiguration extends CBuildConfiguration implements ICMa
runCMake |= !Files.exists(buildDir.resolve("CMakeCache.txt")); //$NON-NLS-1$
- // Causes CMAKE_BUILD_TYPE to be set according to the launch mode
- if (ILaunchManager.DEBUG_MODE.equals(getLaunchMode())) {
- cmakeProperties.setBuildType("Debug"); //$NON-NLS-1$
- } else {
- cmakeProperties.setBuildType("Release"); //$NON-NLS-1$
- }
-
if (!runCMake) {
ICMakeGenerator generator = cmakeProperties.getGenerator();
String makefileName = generator.getMakefileName();
@@ -571,7 +570,8 @@ public class CMakeBuildConfiguration extends CBuildConfiguration implements ICMa
CMAKE_ARGUMENTS, CMAKE_ARGUMENTS_DEFAULT, //
CMAKE_BUILD_COMMAND, CMAKE_BUILD_COMMAND_DEFAULT, //
CMAKE_ALL_TARGET, CMAKE_ALL_TARGET_DEFAULT, //
- CMAKE_CLEAN_TARGET, CMAKE_CLEAN_TARGET_DEFAULT //
+ CMAKE_CLEAN_TARGET, CMAKE_CLEAN_TARGET_DEFAULT, //
+ CMAKE_BUILD_TYPE, ILaunchManager.DEBUG_MODE.equals(getLaunchMode()) ? "Debug" : "Release" //$NON-NLS-1$ //$NON-NLS-2$
);
}
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
index d52dffff37a..6004e433c55 100644
--- 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
@@ -70,6 +70,12 @@ public interface ICMakeBuildConfiguration {
public static final String CMAKE_CLEAN_TARGET = "cmake.target.clean"; //$NON-NLS-1$
public static final String CMAKE_CLEAN_TARGET_DEFAULT = "clean"; //$NON-NLS-1$
+ /**
+ * Name of the build type set by user. Default of this value will be set based on Launch Mode
+ * (i.e. Debug for Debug launch mode, Release for Run and other launch modes)
+ */
+ public static final String CMAKE_BUILD_TYPE = "cmake.build.type"; //$NON-NLS-1$
+
/**
* Converts the {@link ICBuildConfiguration}'s properties, using the keys defined above
* into an {@link ICMakeProperties} that configures the CMake build processes.
diff --git a/cmake/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/CMakeBuildTab.java b/cmake/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/CMakeBuildTab.java
index 55d54e2c8ad..eb61d63aa86 100644
--- a/cmake/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/CMakeBuildTab.java
+++ b/cmake/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/CMakeBuildTab.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.cdt.cmake.ui.internal;
+import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Map;
@@ -18,8 +19,11 @@ import org.eclipse.cdt.cmake.core.CMakeBuildConfigurationProvider;
import org.eclipse.cdt.cmake.core.properties.CMakeGenerator;
import org.eclipse.cdt.core.build.ICBuildConfiguration;
import org.eclipse.cdt.launch.ui.corebuild.CommonBuildTab;
+import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
@@ -35,6 +39,8 @@ import org.eclipse.swt.widgets.Text;
public class CMakeBuildTab extends CommonBuildTab {
+ private static final String[] buildTypes = { "Debug", "Release", "RelWithDebInfo", "MinSizeRel" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+
private Button useDefaultCmakeSettings;
private Combo generatorCombo;
private Text cmakeArgsText;
@@ -46,6 +52,9 @@ public class CMakeBuildTab extends CommonBuildTab {
private Label buildCommandLabel;
private Label allTargetLabel;
private Label cleanTargetLabel;
+ private Combo buildTypeCombo;
+ private Label buildTypeLabel;
+ private Label usedForLaunchModeLabel;
@Override
protected String getBuildConfigProviderId() {
@@ -121,6 +130,25 @@ public class CMakeBuildTab extends CommonBuildTab {
cleanTargetText = new Text(cmakeGroup, SWT.BORDER);
cleanTargetText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
cleanTargetText.addModifyListener(e -> updateLaunchConfigurationDialog());
+
+ Composite buildTypeComp = new Composite(cmakeGroup, SWT.NONE);
+ buildTypeComp.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
+ buildTypeComp.setLayout(new GridLayout(3, false));
+
+ buildTypeLabel = new Label(buildTypeComp, SWT.NONE);
+ buildTypeLabel.setText(Messages.CMakeBuildTab_BuildType);
+ buildTypeLabel.setToolTipText(Messages.CMakeBuildTab_BuildType_Tooltip);
+
+ buildTypeCombo = new Combo(buildTypeComp, SWT.DROP_DOWN);
+ buildTypeCombo.setItems(buildTypes);
+ buildTypeCombo.setToolTipText(Messages.CMakeBuildTab_BuildTypeCombo_Tooltip);
+ buildTypeCombo.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ updateLaunchConfigurationDialog();
+ }
+ });
+ usedForLaunchModeLabel = new Label(buildTypeComp, SWT.NONE);
}
/**
@@ -148,6 +176,9 @@ public class CMakeBuildTab extends CommonBuildTab {
allTargetText.setEnabled(enabled);
cleanTargetLabel.setEnabled(enabled);
cleanTargetText.setEnabled(enabled);
+ buildTypeLabel.setEnabled(enabled);
+ buildTypeCombo.setEnabled(enabled);
+ usedForLaunchModeLabel.setEnabled(enabled);
}
@Override
@@ -217,6 +248,13 @@ public class CMakeBuildTab extends CommonBuildTab {
boolean isDefaultCMakeProperties = useDefaultCmakeSettings.getSelection();
buildConfig.setProperty(CMakeBuildConfiguration.CMAKE_USE_DEFAULT_CMAKE_SETTINGS,
Boolean.toString(isDefaultCMakeProperties));
+
+ String buildType = buildTypeCombo.getText().trim();
+ if (!(buildType.isBlank() || isDefaultCMakeProperties)) {
+ buildConfig.setProperty(CMakeBuildConfiguration.CMAKE_BUILD_TYPE, buildType);
+ } else {
+ buildConfig.removeProperty(CMakeBuildConfiguration.CMAKE_BUILD_TYPE);
+ }
}
@Override
@@ -227,6 +265,7 @@ public class CMakeBuildTab extends CommonBuildTab {
properties.put(CMakeBuildConfiguration.CMAKE_BUILD_COMMAND, buildCommandText.getText().trim());
properties.put(CMakeBuildConfiguration.CMAKE_ALL_TARGET, allTargetText.getText().trim());
properties.put(CMakeBuildConfiguration.CMAKE_CLEAN_TARGET, cleanTargetText.getText().trim());
+ properties.put(CMakeBuildConfiguration.CMAKE_BUILD_TYPE, buildTypeCombo.getText().trim());
}
@Override
@@ -252,6 +291,16 @@ public class CMakeBuildTab extends CommonBuildTab {
String cleanTarget = properties.getOrDefault(CMakeBuildConfiguration.CMAKE_CLEAN_TARGET,
CMakeBuildConfiguration.CMAKE_CLEAN_TARGET_DEFAULT);
cleanTargetText.setText(cleanTarget);
+
+ // Default build type: Debug for Debug launch mode, Release for Run and other launch modes.
+ String defaultBuildType = getDefaultBuildType();
+ String buildType = properties.getOrDefault(CMakeBuildConfiguration.CMAKE_BUILD_TYPE, defaultBuildType);
+ buildTypeCombo.setText(buildType);
+
+ ILaunchMode launchMode = DebugPlugin.getDefault().getLaunchManager()
+ .getLaunchMode(getBuildConfiguration().getLaunchMode());
+ String launchModeLabel = launchMode != null ? launchMode.getLabel() : getBuildConfiguration().getLaunchMode();
+ usedForLaunchModeLabel.setText(MessageFormat.format(Messages.CMakeBuildTab_UsedForLaunchMode, launchModeLabel));
}
@Override
@@ -259,4 +308,9 @@ public class CMakeBuildTab extends CommonBuildTab {
return Messages.CMakeBuildTab_Cmake;
}
+ private String getDefaultBuildType() {
+ return ILaunchManager.DEBUG_MODE.equals(getBuildConfiguration().getLaunchMode()) ? buildTypes[0]
+ : buildTypes[1];
+ }
+
}
diff --git a/cmake/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/Messages.java b/cmake/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/Messages.java
index 579ed81e76b..d5c2263626f 100644
--- a/cmake/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/Messages.java
+++ b/cmake/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/Messages.java
@@ -15,6 +15,9 @@ import org.eclipse.osgi.util.NLS;
public class Messages extends NLS {
public static String CMakeBuildTab_BuildCommand;
+ public static String CMakeBuildTab_BuildType;
+ public static String CMakeBuildTab_BuildType_Tooltip;
+ public static String CMakeBuildTab_BuildTypeCombo_Tooltip;
public static String CMakeBuildTab_AllTarget;
public static String CMakeBuildTab_CleanTarget;
public static String CMakeBuildTab_Cmake;
@@ -25,6 +28,7 @@ public class Messages extends NLS {
public static String CMakeBuildTab_Toolchain;
public static String CMakeBuildTab_useDefaultCmakeSettings;
public static String CMakeBuildTab_useDefaultCmakeSettingsTip;
+ public static String CMakeBuildTab_UsedForLaunchMode;
public static String CMakePreferencePage_Add;
public static String CMakePreferencePage_ConfirmRemoveDesc;
public static String CMakePreferencePage_ConfirmRemoveTitle;
diff --git a/cmake/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/messages.properties b/cmake/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/messages.properties
index 674bd2205ae..bd5f7e8ebd8 100644
--- a/cmake/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/messages.properties
+++ b/cmake/org.eclipse.cdt.cmake.ui/src/org/eclipse/cdt/cmake/ui/internal/messages.properties
@@ -1,4 +1,7 @@
CMakeBuildTab_BuildCommand=Build command
+CMakeBuildTab_BuildType=Build type:
+CMakeBuildTab_BuildType_Tooltip=The build type (CMAKE_BUILD_TYPE) used by the generator.
+CMakeBuildTab_BuildTypeCombo_Tooltip=Typical build types (CMAKE_BUILD_TYPE) are listed. A custom build type can be entered.
CMakeBuildTab_AllTarget=Build all target
CMakeBuildTab_CleanTarget=Clean target
CMakeBuildTab_Cmake=CMake
@@ -9,6 +12,7 @@ CMakeBuildTab_Settings=CMake Settings
CMakeBuildTab_Toolchain=Toolchain
CMakeBuildTab_useDefaultCmakeSettings=Use default CMake settings
CMakeBuildTab_useDefaultCmakeSettingsTip=Use the default CMake settings that are provided by the toolchain and Core Build System
+CMakeBuildTab_UsedForLaunchMode=used for launch mode: {0}
CMakePreferencePage_Add=Add...
CMakePreferencePage_ConfirmRemoveDesc=Do you wish to deregister the selected files?
CMakePreferencePage_ConfirmRemoveTitle=Deregister CMake ToolChain File