Add --genCDeps for better integration with CMake (#20950)
* add gencdeps option * add case statement * Update compiler/main.nim * Update compiler/main.nim * Apply suggestions from code review Fixes Co-authored-by: Andreas Rumpf <rumpf_a@web.de> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
parent
77a337a39a
commit
5658e8e5c5
3 changed files with 26 additions and 0 deletions
|
|
@ -326,6 +326,7 @@ proc testCompileOption*(conf: ConfigRef; switch: string, info: TLineInfo): bool
|
||||||
of "run", "r": result = contains(conf.globalOptions, optRun)
|
of "run", "r": result = contains(conf.globalOptions, optRun)
|
||||||
of "symbolfiles": result = conf.symbolFiles != disabledSf
|
of "symbolfiles": result = conf.symbolFiles != disabledSf
|
||||||
of "genscript": result = contains(conf.globalOptions, optGenScript)
|
of "genscript": result = contains(conf.globalOptions, optGenScript)
|
||||||
|
of "gencdeps": result = contains(conf.globalOptions, optGenCDeps)
|
||||||
of "threads": result = contains(conf.globalOptions, optThreads)
|
of "threads": result = contains(conf.globalOptions, optThreads)
|
||||||
of "tlsemulation": result = contains(conf.globalOptions, optTlsEmulation)
|
of "tlsemulation": result = contains(conf.globalOptions, optTlsEmulation)
|
||||||
of "implicitstatic": result = contains(conf.options, optImplicitStatic)
|
of "implicitstatic": result = contains(conf.options, optImplicitStatic)
|
||||||
|
|
@ -914,6 +915,8 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
|
||||||
if switch.normalize == "gendeps": deprecatedAlias(switch, "genscript")
|
if switch.normalize == "gendeps": deprecatedAlias(switch, "genscript")
|
||||||
processOnOffSwitchG(conf, {optGenScript}, arg, pass, info)
|
processOnOffSwitchG(conf, {optGenScript}, arg, pass, info)
|
||||||
processOnOffSwitchG(conf, {optCompileOnly}, arg, pass, info)
|
processOnOffSwitchG(conf, {optCompileOnly}, arg, pass, info)
|
||||||
|
of "gencdeps":
|
||||||
|
processOnOffSwitchG(conf, {optGenCDeps}, arg, pass, info)
|
||||||
of "colors": processOnOffSwitchG(conf, {optUseColors}, arg, pass, info)
|
of "colors": processOnOffSwitchG(conf, {optUseColors}, arg, pass, info)
|
||||||
of "lib":
|
of "lib":
|
||||||
expectArg(conf, switch, arg, pass, info)
|
expectArg(conf, switch, arg, pass, info)
|
||||||
|
|
|
||||||
|
|
@ -47,6 +47,26 @@ proc writeDepsFile(g: ModuleGraph) =
|
||||||
f.writeLine(toFullPath(g.config, k))
|
f.writeLine(toFullPath(g.config, k))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
proc writeCMakeDepsFile(conf: ConfigRef) =
|
||||||
|
## write a list of C files for build systems like CMake.
|
||||||
|
## only updated when the C file list changes.
|
||||||
|
let fname = getNimcacheDir(conf) / conf.outFile.changeFileExt("cdeps")
|
||||||
|
# generate output files list
|
||||||
|
var cfiles: seq[string] = @[]
|
||||||
|
for it in conf.toCompile: cfiles.add(it.cname.string)
|
||||||
|
let fileset = cfiles.toCountTable()
|
||||||
|
# read old cfiles list
|
||||||
|
var fl: File
|
||||||
|
var prevset = initCountTable[string]()
|
||||||
|
if open(fl, fname.string, fmRead):
|
||||||
|
for line in fl.lines: prevset.inc(line)
|
||||||
|
fl.close()
|
||||||
|
# write cfiles out
|
||||||
|
if fileset != prevset:
|
||||||
|
fl = open(fname.string, fmWrite)
|
||||||
|
for line in cfiles: fl.writeLine(line)
|
||||||
|
fl.close()
|
||||||
|
|
||||||
proc commandGenDepend(graph: ModuleGraph) =
|
proc commandGenDepend(graph: ModuleGraph) =
|
||||||
semanticPasses(graph)
|
semanticPasses(graph)
|
||||||
registerPass(graph, gendependPass)
|
registerPass(graph, gendependPass)
|
||||||
|
|
@ -126,6 +146,8 @@ proc commandCompileToC(graph: ModuleGraph) =
|
||||||
extccomp.writeJsonBuildInstructions(conf)
|
extccomp.writeJsonBuildInstructions(conf)
|
||||||
if optGenScript in graph.config.globalOptions:
|
if optGenScript in graph.config.globalOptions:
|
||||||
writeDepsFile(graph)
|
writeDepsFile(graph)
|
||||||
|
if optGenCDeps in graph.config.globalOptions:
|
||||||
|
writeCMakeDepsFile(conf)
|
||||||
|
|
||||||
proc commandJsonScript(graph: ModuleGraph) =
|
proc commandJsonScript(graph: ModuleGraph) =
|
||||||
extccomp.runJsonBuildInstructions(graph.config, graph.config.jsonBuildInstructionsFile)
|
extccomp.runJsonBuildInstructions(graph.config, graph.config.jsonBuildInstructionsFile)
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,7 @@ type # please make sure we have under 32 options
|
||||||
optGenStaticLib, # generate a static library
|
optGenStaticLib, # generate a static library
|
||||||
optGenGuiApp, # generate a GUI application
|
optGenGuiApp, # generate a GUI application
|
||||||
optGenScript, # generate a script file to compile the *.c files
|
optGenScript, # generate a script file to compile the *.c files
|
||||||
|
optGenCDeps, # generate a list of *.c files to be read by CMake
|
||||||
optGenMapping, # generate a mapping file
|
optGenMapping, # generate a mapping file
|
||||||
optRun, # run the compiled project
|
optRun, # run the compiled project
|
||||||
optUseNimcache, # save artifacts (including binary) in $nimcache
|
optUseNimcache, # save artifacts (including binary) in $nimcache
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue