diff --git a/core/src/main/java/org/lflang/federated/generator/FederationFileConfig.java b/core/src/main/java/org/lflang/federated/generator/FederationFileConfig.java index c714c0586a..85b5af44ab 100644 --- a/core/src/main/java/org/lflang/federated/generator/FederationFileConfig.java +++ b/core/src/main/java/org/lflang/federated/generator/FederationFileConfig.java @@ -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; @@ -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)) { diff --git a/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java b/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java index 5931399052..d308856784 100644 --- a/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CCmakeGenerator.java @@ -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; @@ -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: diff --git a/core/src/main/java/org/lflang/generator/c/CCompiler.java b/core/src/main/java/org/lflang/generator/c/CCompiler.java index 12de4474dc..9150e1b6b9 100644 --- a/core/src/main/java/org/lflang/generator/c/CCompiler.java +++ b/core/src/main/java/org/lflang/generator/c/CCompiler.java @@ -244,9 +244,9 @@ private static List 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())); diff --git a/core/src/main/java/org/lflang/generator/c/CGenerator.java b/core/src/main/java/org/lflang/generator/c/CGenerator.java index dda5c06d89..b08d269370 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -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; @@ -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) { diff --git a/core/src/main/java/org/lflang/target/Target.java b/core/src/main/java/org/lflang/target/Target.java index 30048f5a58..def719da17 100644 --- a/core/src/main/java/org/lflang/target/Target.java +++ b/core/src/main/java/org/lflang/target/Target.java @@ -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; @@ -589,6 +590,7 @@ public void initialize(TargetConfig config) { ClockSyncModeProperty.INSTANCE, ClockSyncOptionsProperty.INSTANCE, CmakeIncludeProperty.INSTANCE, + CmakeInitIncludeProperty.INSTANCE, CompileDefinitionsProperty.INSTANCE, CompilerProperty.INSTANCE, CoordinationOptionsProperty.INSTANCE, @@ -608,6 +610,7 @@ public void initialize(TargetConfig config) { case CPP -> config.register( BuildTypeProperty.INSTANCE, + CmakeInitIncludeProperty.INSTANCE, CmakeIncludeProperty.INSTANCE, CompilerProperty.INSTANCE, DockerProperty.INSTANCE, diff --git a/core/src/main/java/org/lflang/target/property/CmakeInitIncludeProperty.java b/core/src/main/java/org/lflang/target/property/CmakeInitIncludeProperty.java new file mode 100644 index 0000000000..a6964cabbe --- /dev/null +++ b/core/src/main/java/org/lflang/target/property/CmakeInitIncludeProperty.java @@ -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 fromAst(Element node, MessageReporter reporter) { + return ASTUtils.elementToListOfStrings(node); + } + + @Override + protected List fromString(String string, MessageReporter reporter) { + throw new UnsupportedOperationException("Not supported yet."); + } + + @Override + public Element toAstElement(List value) { + return ASTUtils.toElement(value); + } + + @Override + public String name() { + return "cmake-init-include"; + } + + @Override + public boolean loadFromFederate() { + return true; + } +} diff --git a/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2PackageGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2PackageGenerator.kt index c3ce84c747..29bc4d83a3 100644 --- a/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2PackageGenerator.kt +++ b/core/src/main/kotlin/org/lflang/generator/cpp/CppRos2PackageGenerator.kt @@ -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 @@ -52,7 +53,7 @@ class CppRos2PackageGenerator(generator: CppGenerator, private val nodeName: Str fun generatePackageCmake(sources: List): 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) { diff --git a/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt b/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt index 2c041fe6d2..8428493377 100644 --- a/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt +++ b/core/src/main/kotlin/org/lflang/generator/cpp/CppStandaloneCmakeGenerator.kt @@ -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 @@ -140,7 +137,7 @@ class CppStandaloneCmakeGenerator(private val targetConfig: TargetConfig, privat fun generateCmake(sources: List): 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" diff --git a/core/src/main/resources/lib/c/reactor-c b/core/src/main/resources/lib/c/reactor-c index 3d7715c39f..e0724b7cf2 160000 --- a/core/src/main/resources/lib/c/reactor-c +++ b/core/src/main/resources/lib/c/reactor-c @@ -1 +1 @@ -Subproject commit 3d7715c39fc40ad3c4c29918e724dc5b96738ca5 +Subproject commit e0724b7cf21f4b68ee02153a99f692d60a06aebe