Skip to content
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

Add cmake-init-include target property #2432

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.emf.ecore.resource.Resource;
import org.lflang.FileConfig;
import org.lflang.target.property.CmakeIncludeProperty;
import org.lflang.target.property.CmakeInitIncludeProperty;
import org.lflang.target.property.FilesProperty;
import org.lflang.target.property.ProtobufsProperty;
import org.lflang.util.FileUtil;
Expand Down Expand Up @@ -102,7 +103,11 @@ public void doClean() throws IOException {
* the generated .lf file for the federate.
*/
public void relativizePaths(FederateTargetConfig targetConfig) {
List.of(ProtobufsProperty.INSTANCE, FilesProperty.INSTANCE, CmakeIncludeProperty.INSTANCE)
List.of(
ProtobufsProperty.INSTANCE,
FilesProperty.INSTANCE,
CmakeIncludeProperty.INSTANCE,
CmakeInitIncludeProperty.INSTANCE)
.forEach(
p -> {
if (targetConfig.isSet(p)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.lflang.target.property.AuthProperty;
import org.lflang.target.property.BuildTypeProperty;
import org.lflang.target.property.CmakeIncludeProperty;
import org.lflang.target.property.CmakeInitIncludeProperty;
import org.lflang.target.property.CompileDefinitionsProperty;
import org.lflang.target.property.CompilerProperty;
import org.lflang.target.property.PlatformProperty;
Expand Down Expand Up @@ -142,6 +143,11 @@ CodeBuilder generateCMakeCode(

cMakeCode.pr("cmake_minimum_required(VERSION " + MIN_CMAKE_VERSION + ")");

// Add the cmake-init-include files
for (String includeFile : targetConfig.getOrDefault(CmakeInitIncludeProperty.INSTANCE)) {
cMakeCode.pr("include(\"" + Path.of(includeFile).getFileName() + "\")");
}

// Setup the project header for different platforms
switch (platformOptions.platform()) {
case ZEPHYR:
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/org/lflang/generator/c/CCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,9 @@ private static List<String> cmakeOptions(TargetConfig targetConfig, FileConfig f
// into the cmake file (and fileConfig.srcPath is the wrong directory anyway).
if (!fileConfig.srcPath.toString().contains("fed-gen")) {
// Do not convert to Unix path
arguments.add("-DLF_SOURCE_DIRECTORY='" + quote + srcPath + quote + "'");
arguments.add("-DLF_PACKAGE_DIRECTORY='" + quote + rootPath + quote + "'");
arguments.add("-DLF_SOURCE_GEN_DIRECTORY='" + quote + srcGenPath + quote + "'");
arguments.add("-DLF_SOURCE_DIRECTORY=" + srcPath);
arguments.add("-DLF_PACKAGE_DIRECTORY=" + rootPath);
arguments.add("-DLF_SOURCE_GEN_DIRECTORY=" + srcGenPath);
}
arguments.add(FileUtil.toUnixString(fileConfig.getSrcGenPath()));

Expand Down
10 changes: 10 additions & 0 deletions core/src/main/java/org/lflang/generator/c/CGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
import org.lflang.target.TargetConfig;
import org.lflang.target.property.BuildCommandsProperty;
import org.lflang.target.property.CmakeIncludeProperty;
import org.lflang.target.property.CmakeInitIncludeProperty;
import org.lflang.target.property.CompileDefinitionsProperty;
import org.lflang.target.property.DockerProperty;
import org.lflang.target.property.FedSetupProperty;
Expand Down Expand Up @@ -788,6 +789,15 @@ protected void copyUserFiles(TargetConfig targetConfig, FileConfig fileConfig) {
true);
}

if (targetConfig.isSet(CmakeInitIncludeProperty.INSTANCE)) {
FileUtil.copyFilesOrDirectories(
targetConfig.get(CmakeInitIncludeProperty.INSTANCE),
destination,
fileConfig,
messageReporter,
true);
}

try {
var file = targetConfig.get(FedSetupProperty.INSTANCE);
if (file != null) {
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/org/lflang/target/Target.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.lflang.target.property.ClockSyncModeProperty;
import org.lflang.target.property.ClockSyncOptionsProperty;
import org.lflang.target.property.CmakeIncludeProperty;
import org.lflang.target.property.CmakeInitIncludeProperty;
import org.lflang.target.property.CompileDefinitionsProperty;
import org.lflang.target.property.CompilerProperty;
import org.lflang.target.property.CoordinationOptionsProperty;
Expand Down Expand Up @@ -589,6 +590,7 @@ public void initialize(TargetConfig config) {
ClockSyncModeProperty.INSTANCE,
ClockSyncOptionsProperty.INSTANCE,
CmakeIncludeProperty.INSTANCE,
CmakeInitIncludeProperty.INSTANCE,
CompileDefinitionsProperty.INSTANCE,
CompilerProperty.INSTANCE,
CoordinationOptionsProperty.INSTANCE,
Expand All @@ -608,6 +610,7 @@ public void initialize(TargetConfig config) {
case CPP ->
config.register(
BuildTypeProperty.INSTANCE,
CmakeInitIncludeProperty.INSTANCE,
CmakeIncludeProperty.INSTANCE,
CompilerProperty.INSTANCE,
DockerProperty.INSTANCE,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.lflang.target.property;

import java.util.List;
import org.lflang.MessageReporter;
import org.lflang.ast.ASTUtils;
import org.lflang.lf.Element;

/**
* Directive to specify cmake initialize files to be included at the very beginning of the generated
* CMakeLists.txt. Here the user can override things like the toolchain file
*/
public final class CmakeInitIncludeProperty extends FileListProperty {

/** Singleton target property instance. */
public static final CmakeInitIncludeProperty INSTANCE = new CmakeInitIncludeProperty();

private CmakeInitIncludeProperty() {
super();
}

@Override
protected List<String> fromAst(Element node, MessageReporter reporter) {
return ASTUtils.elementToListOfStrings(node);
}

@Override
protected List<String> fromString(String string, MessageReporter reporter) {
throw new UnsupportedOperationException("Not supported yet.");
}

@Override
public Element toAstElement(List<String> value) {
return ASTUtils.toElement(value);
}

@Override
public String name() {
return "cmake-init-include";
}

@Override
public boolean loadFromFederate() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import org.lflang.generator.PrependOperator
import org.lflang.joinWithLn
import org.lflang.target.property.BuildTypeProperty
import org.lflang.target.property.CmakeIncludeProperty
import org.lflang.target.property.CmakeInitIncludeProperty
import org.lflang.target.property.Ros2DependenciesProperty
import org.lflang.target.property.RuntimeVersionProperty
import org.lflang.toUnixString
Expand Down Expand Up @@ -52,7 +53,7 @@ class CppRos2PackageGenerator(generator: CppGenerator, private val nodeName: Str

fun generatePackageCmake(sources: List<Path>): String {
// Resolve path to the cmake include files if any was provided
val includeFiles = targetConfig.get(CmakeIncludeProperty.INSTANCE)?.map { fileConfig.srcPath.resolve(it).toUnixString() }
val includeFiles = (targetConfig.get(CmakeIncludeProperty.INSTANCE) + targetConfig.get(CmakeInitIncludeProperty.INSTANCE))?.map { fileConfig.srcPath.resolve(it).toUnixString() }

return with(PrependOperator) {
with(CppGenerator) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,7 @@ import org.lflang.FileConfig
import org.lflang.target.TargetConfig
import org.lflang.generator.PrependOperator
import org.lflang.joinWithLn
import org.lflang.target.property.BuildTypeProperty
import org.lflang.target.property.CmakeIncludeProperty
import org.lflang.target.property.ExternalRuntimePathProperty
import org.lflang.target.property.RuntimeVersionProperty
import org.lflang.target.property.*
import org.lflang.toUnixString
import java.nio.file.Path

Expand Down Expand Up @@ -140,7 +137,7 @@ class CppStandaloneCmakeGenerator(private val targetConfig: TargetConfig, privat

fun generateCmake(sources: List<Path>): String {
// Resolve path to the cmake include files if any was provided
val includeFiles = targetConfig.get(CmakeIncludeProperty.INSTANCE)?.map { fileConfig.srcPath.resolve(it).toUnixString() }
val includeFiles = (targetConfig.get(CmakeIncludeProperty.INSTANCE) + targetConfig.get(CmakeInitIncludeProperty.INSTANCE))?.map { fileConfig.srcPath.resolve(it).toUnixString() }

val reactorCppTarget = when {
targetConfig.isSet(ExternalRuntimePathProperty.INSTANCE) -> "reactor-cpp"
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/resources/lib/c/reactor-c
Loading