Skip to content

Provide an example of extending CMake project type in Core Build #1052

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions NewAndNoteworthy/CDT-12.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ Starting in CDT 12, the Terminal will now default to UTF-8.

# API Changes, current and planned

## CMake Support easier for extenders and ISVs

Improvements to the API for CMake has made it easier to extend and specialize CMake for ISVs.
A fully worked example demonstrating the support is now provided in the CDT source in [org.eclipse.cdt.cmake.example](https://github.com/eclipse-cdt/cdt/tree/main/cmake/org.eclipse.cdt.cmake.example).
This example demonstrates the API, and how to contribute a new project wizard to make such a project.

<p align="center"><img src="images/CDT-12.0-cmake-example-project-for-isvs.png"></p>

## Breaking API changes

Please see [CHANGELOG-API](CHANGELOG-API.md) for details on the breaking API changes in this release as well as future planned API changes.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@
import org.eclipse.core.runtime.Platform;

/**
* A ICBuildConfigurationProvider specialized for CMake
*
* Extenders can provide their own specialised CMakeConfiguration by extending this class and {@link CMakeBuildConfiguration}.
* Extenders need to override at least {@link #getId()}, and the various createCMakeBuildConfiguration methods.
* See the example project <a href="https://github.com/eclipse-cdt/cdt/tree/main/cmake/org.eclipse.cdt.cmake.example">
* org.eclipse.cdt.cmake.example</a> for a full example.
*
* @since 1.6
*/
public class CMakeBuildConfigurationProvider implements ICBuildConfigurationProvider {
Expand All @@ -41,6 +48,30 @@ public String getId() {
return ID;
}

/**
* Extenders should override this method to construct their specialized build configuration.
*/
protected CMakeBuildConfiguration createCMakeBuildConfiguration(IBuildConfiguration config, String name)
throws CoreException {
return new CMakeBuildConfiguration(config, name);
}

/**
* Extenders should override this method to construct their specialized build configuration.
*/
protected CMakeBuildConfiguration createCMakeBuildConfiguration(IBuildConfiguration config, String name,
IToolChain toolChain) {
return new CMakeBuildConfiguration(config, name, toolChain);
}

/**
* Extenders should override this method to construct their specialized build configuration.
*/
protected CMakeBuildConfiguration createCMakeBuildConfiguration(IBuildConfiguration config, String name,
IToolChain toolChain, ICMakeToolChainFile toolChainFile, String launchMode) {
return new CMakeBuildConfiguration(config, name, toolChain, toolChainFile, launchMode);
}

@Override
public synchronized ICBuildConfiguration getCBuildConfiguration(IBuildConfiguration config, String name)
throws CoreException {
Expand All @@ -66,13 +97,13 @@ public synchronized ICBuildConfiguration getCBuildConfiguration(IBuildConfigurat
}

if (toolChain != null) {
return new CMakeBuildConfiguration(config, name, toolChain);
return createCMakeBuildConfiguration(config, name, toolChain);
} else {
// No valid combinations
return null;
}
}
CMakeBuildConfiguration cmakeConfig = new CMakeBuildConfiguration(config, name);
CMakeBuildConfiguration cmakeConfig = createCMakeBuildConfiguration(config, name);
ICMakeToolChainFile tcFile = cmakeConfig.getToolChainFile();
IToolChain toolChain = cmakeConfig.getToolChain();
if (toolChain == null) {
Expand All @@ -81,7 +112,7 @@ public synchronized ICBuildConfiguration getCBuildConfiguration(IBuildConfigurat
}
if (tcFile != null && !toolChain.equals(tcFile.getToolChain())) {
// toolchain changed
return new CMakeBuildConfiguration(config, name, tcFile.getToolChain(), tcFile,
return createCMakeBuildConfiguration(config, name, tcFile.getToolChain(), tcFile,
cmakeConfig.getLaunchMode());
} else {
return cmakeConfig;
Expand Down Expand Up @@ -136,7 +167,7 @@ public ICBuildConfiguration createBuildConfiguration(IProject project, IToolChai
config = configManager.createBuildConfiguration(this, project, name, monitor);
}

CMakeBuildConfiguration cmakeConfig = new CMakeBuildConfiguration(config, name, toolChain, file, launchMode);
CMakeBuildConfiguration cmakeConfig = createCMakeBuildConfiguration(config, name, toolChain, file, launchMode);
configManager.addBuildConfiguration(config, cmakeConfig);
return cmakeConfig;
}
Expand Down
7 changes: 7 additions & 0 deletions cmake/org.eclipse.cdt.cmake.example/.classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="bin"/>
</classpath>
28 changes: 28 additions & 0 deletions cmake/org.eclipse.cdt.cmake.example/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.cdt.cmake.example</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
Loading
Loading