for example:
code
{.backend:cpp.}
config
compileTo:cpp
Interestingly, you cannot do that for now. All you can do is to do something like
when not defined(cpp):
{.error: "compile via the 'cpp' command".}
With a sufficiently ugly hack, all things are possible... :P
import strutils
static:
proc getNimCompilerCmdLine(): string =
return staticRead("/proc/self/cmdline").replace('\0', ' ')
const nimCompilerCmdLine = getNimCompilerCmdLine()
proc getNimCompilerBackend(): string =
result = nimCompilerCmdLine.split(' ')[1].toLowerAscii()
if result == "compile": result = "c"
proc forceNimCompilerBackend(newBackend: string) =
let currentBackend = getNimCompilerBackend()
if currentBackend == newBackend.toLowerAscii(): return
var splitRestartCmdLine = nimCompilerCmdLine.split(' ')
splitRestartCmdLine[1] = newBackend & " --forceBuild"
let restartCmdLine = splitRestartCmdLine.join(" ")
echo "Restarting the compiler with: `" & restartCmdLine & "`"
echo '{'
let restartEx = gorgeEx(restartCmdLine)
echo restartEx.output
echo '}'
quit restartEx.exitCode
forceNimCompilerBackend("js")
echo "This is printed at run-time."