diff --git a/compiler/cgen.nim b/compiler/cgen.nim index e79081dc6d..0450625fcd 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -935,7 +935,9 @@ proc cgsymValue(m: BModule, name: string): Rope = result.addActualSuffixForHCR(m.module, sym) proc generateHeaders(m: BModule) = - m.s[cfsHeaders].add("\L#include \"nimbase.h\"\L") + var nimbase = m.config.nimbasePattern + if nimbase == "": nimbase = "nimbase.h" + m.s[cfsHeaders].addf("\L#include \"$1\"\L", [nimbase]) for it in m.headerFiles: if it[0] == '#': diff --git a/compiler/commands.nim b/compiler/commands.nim index cb9a12cbb3..333a0f0d03 100644 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -829,6 +829,8 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo; of "header": if conf != nil: conf.headerFile = arg incl(conf.globalOptions, optGenIndex) + of "nimbasepattern": + if conf != nil: conf.nimbasePattern = arg of "index": case arg.normalize of "", "on": conf.globalOptions.incl {optGenIndex} diff --git a/compiler/options.nim b/compiler/options.nim index 082caedf18..d3cf71d4f6 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -333,6 +333,7 @@ type cppDefines*: HashSet[string] # (*) headerFile*: string + nimbasePattern*: string # pattern to find nimbase.h features*: set[Feature] legacyFeatures*: set[LegacyFeature] arguments*: string ## the arguments to be passed to the program that diff --git a/tests/options/tnimbasepattern.nim b/tests/options/tnimbasepattern.nim new file mode 100644 index 0000000000..1237af5c59 --- /dev/null +++ b/tests/options/tnimbasepattern.nim @@ -0,0 +1,26 @@ +discard """ + cmd: "nim cpp --nimbasepattern:test.h --cincludes:./tests/options $file " + output:''' +(a: 1) +''' +""" +const header = """ +#pragma once +#include "nimbase.h" +struct Foo { + int a; +}; +""" + +import os +static: + const dir = "./tests/options/" + createDir(dir) + writeFile(dir / "test.h", header) + +type + Foo {.importc.} = object + a: int32 = 1 + + +echo $Foo() \ No newline at end of file