Skip to content

Commit

Permalink
Add GNU C++ linker library grouping option to MBS
Browse files Browse the repository at this point in the history
  • Loading branch information
jld01 committed Nov 12, 2023
1 parent e318152 commit f39707a
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 4 deletions.
10 changes: 9 additions & 1 deletion build/org.eclipse.cdt.managedbuilder.gnu.ui/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
name="%Option.Posix.Libs"
category="gnu.c.link.category.libs"
command="-l"
commandGenerator="org.eclipse.cdt.managedbuilder.gnu.ui.LibrariesCommandGenerator"
commandGenerator="org.eclipse.cdt.managedbuilder.gnu.ui.GnuCLibrariesCommandGenerator"
id="gnu.c.link.option.libs"
browseType="none"
valueType="libs">
Expand Down Expand Up @@ -300,6 +300,7 @@
name="%Option.Posix.Libs"
category="gnu.cpp.link.category.libs"
command="-l"
commandGenerator="org.eclipse.cdt.managedbuilder.gnu.ui.GnuCppLibrariesCommandGenerator"
id="gnu.cpp.link.option.libs"
browseType="none"
valueType="libs">
Expand All @@ -312,6 +313,13 @@
browseType="directory"
valueType="libPaths">
</option>
<option
defaultValue="false"
name="%Option.Posix.Linker.GroupLibs"
category="gnu.cpp.link.category.libs"
id="gnu.cpp.link.option.group"
valueType="boolean">
</option>
<optionCategory
owner="cdt.managedbuild.tool.gnu.cpp.linker"
name="%OptionCategory.Misc"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*******************************************************************************
* Copyright (c) 2023 John Dallaway and others.
*
* 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
*
* Contributors:
* John Dallaway - initial implementation (#608)
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.gnu.ui;

/**
* A libraries command generator for GNU C projects.
* @noextend This class is not intended to be subclassed by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
* @since 8.6
*/
public class GnuCLibrariesCommandGenerator extends LibrariesCommandGenerator {

public GnuCLibrariesCommandGenerator() {
super("gnu.c.link.option.group"); //$NON-NLS-1$
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*******************************************************************************
* Copyright (c) 2023 John Dallaway and others.
*
* 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
*
* Contributors:
* John Dallaway - initial implementation (#608)
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.gnu.ui;

/**
* A libraries command generator for GNU C++ projects.
* @noextend This class is not intended to be subclassed by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
* @since 8.6
*/
public class GnuCppLibrariesCommandGenerator extends LibrariesCommandGenerator {

public GnuCppLibrariesCommandGenerator() {
super("gnu.cpp.link.option.group"); //$NON-NLS-1$
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,25 @@

/**
* An option command generator to group libraries on the GNU linker command line
* @noextend This class is not intended to be subclassed by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
* @since 8.6
*/
public class LibrariesCommandGenerator implements IOptionCommandGenerator {

private static final String GROUP_LIBRARIES_COMMAND_FORMAT = "-Wl,--start-group %s -Wl,--end-group"; //$NON-NLS-1$
private static final String GROUP_LIBRARIES_OPTION_ID = "gnu.c.link.option.group"; //$NON-NLS-1$

private final String fGroupLibrariesOptionId;

/**
* @param groupLibrariesOptionId the ID of the IOption controlling library grouping
*/
protected LibrariesCommandGenerator(String groupLibrariesOptionId) {
fGroupLibrariesOptionId = groupLibrariesOptionId;
}

@Override
public String generateCommand(IOption option, IVariableSubstitutor macroSubstitutor) {
IOption groupOption = option.getOptionHolder().getOptionBySuperClassId(GROUP_LIBRARIES_OPTION_ID);
IOption groupOption = option.getOptionHolder().getOptionBySuperClassId(fGroupLibrariesOptionId);
try {
if ((groupOption != null) && groupOption.getBooleanValue()) { // if library grouping enabled
String command = option.getCommand();
Expand Down

0 comments on commit f39707a

Please sign in to comment.