Skip to content

Commit

Permalink
Merge pull request #2358 from lf-lang/cpp-docker-cmake-fix
Browse files Browse the repository at this point in the history
Fixed C++ docker generation for when cmake is not installed
  • Loading branch information
lhstrh authored Jul 12, 2024
2 parents 862e8de + 79cfa7e commit bc52337
Showing 1 changed file with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,44 @@ class CppStandaloneGenerator(generator: CppGenerator) :
return 0
}

private fun createMakeCommand(buildPath: Path, parallelize: Boolean, target: String): LFCommand {
private fun getMakeArgs(buildPath: Path, parallelize: Boolean, target: String): List<String> {
val cmakeConfig = buildTypeToCmakeConfig(targetConfig.get(BuildTypeProperty.INSTANCE))
val makeArgs: MutableList<String> = listOf(
val makeArgs = mutableListOf(
"--build",
buildPath.fileName.toString(),
"--target",
target,
"--config",
cmakeConfig
).toMutableList()
)

if (parallelize) {
makeArgs.addAll(listOf("--parallel", Runtime.getRuntime().availableProcessors().toString()))
}

return makeArgs
}


private fun createMakeCommand(buildPath: Path, parallelize: Boolean, target: String): LFCommand {
val makeArgs = getMakeArgs(buildPath, parallelize, target)
return commandFactory.createCommand("cmake", makeArgs, buildPath.parent)
}

private fun getCmakeArgs(
buildPath: Path,
outPath: Path,
additionalCmakeArgs: List<String> = listOf(),
sourcesRoot: String? = null
) = cmakeArgs + additionalCmakeArgs + listOf(
"-DCMAKE_INSTALL_PREFIX=${outPath.toUnixString()}",
"-DCMAKE_INSTALL_BINDIR=$relativeBinDir",
"-S",
sourcesRoot ?: fileConfig.srcGenBasePath.toUnixString(),
"-B",
buildPath.fileName.toString()
)

private fun createCmakeCommand(
buildPath: Path,
outPath: Path,
Expand All @@ -176,14 +196,7 @@ class CppStandaloneGenerator(generator: CppGenerator) :
): LFCommand {
val cmd = commandFactory.createCommand(
"cmake",
cmakeArgs + additionalCmakeArgs + listOf(
"-DCMAKE_INSTALL_PREFIX=${outPath.toUnixString()}",
"-DCMAKE_INSTALL_BINDIR=$relativeBinDir",
"-S",
sourcesRoot ?: fileConfig.srcGenBasePath.toUnixString(),
"-B",
buildPath.fileName.toString()
),
getCmakeArgs(buildPath, outPath, additionalCmakeArgs, sourcesRoot),
buildPath.parent
)

Expand Down Expand Up @@ -230,14 +243,14 @@ class CppStandaloneGenerator(generator: CppGenerator) :
val mkdirCommand = listOf("mkdir", "-p", "build")
val commands = listOf(
mkdirCommand,
createCmakeCommand(
listOf("cmake") + getCmakeArgs(
Path.of("./build"),
Path.of("."),
listOf("-DREACTOR_CPP_LINK_EXECINFO=ON"),
"src-gen"
).command(),
createMakeCommand(fileConfig.buildPath, true, fileConfig.name).command(),
createMakeCommand(Path.of("./build"), true, "install").command()
),
listOf("cmake") + getMakeArgs(fileConfig.buildPath, true, fileConfig.name),
listOf("cmake") + getMakeArgs(Path.of("./build"), true, "install")
)
return commands.map { argListToCommand(it) }
}
Expand Down

0 comments on commit bc52337

Please sign in to comment.