Fix #1599
Compiler-specific options are now read with the '{compiler}.cpp' prefix in C++ mode.
GCC C++ mode is fixed.
This commit is contained in:
parent
a639824e5e
commit
3939e674d0
2 changed files with 35 additions and 17 deletions
|
|
@ -7,8 +7,10 @@
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
#
|
#
|
||||||
|
|
||||||
# module for calling the different external C compilers
|
# Module providing functions for calling the different external C compilers
|
||||||
# some things are read in from the configuration file
|
# Uses some hard-wired facts about each C/C++ compiler, plus options read
|
||||||
|
# from a configuration file, to provide generalized procedures to compile
|
||||||
|
# nim files.
|
||||||
|
|
||||||
import
|
import
|
||||||
lists, ropes, os, strutils, osproc, platform, condsyms, options, msgs, crc
|
lists, ropes, os, strutils, osproc, platform, condsyms, options, msgs, crc
|
||||||
|
|
@ -59,6 +61,7 @@ type
|
||||||
template compiler(name: expr, settings: stmt): stmt {.immediate.} =
|
template compiler(name: expr, settings: stmt): stmt {.immediate.} =
|
||||||
proc name: TInfoCC {.compileTime.} = settings
|
proc name: TInfoCC {.compileTime.} = settings
|
||||||
|
|
||||||
|
# GNU C and C++ Compiler
|
||||||
compiler gcc:
|
compiler gcc:
|
||||||
result = (
|
result = (
|
||||||
name: "gcc",
|
name: "gcc",
|
||||||
|
|
@ -84,21 +87,24 @@ compiler gcc:
|
||||||
props: {hasSwitchRange, hasComputedGoto, hasCpp, hasGcGuard, hasGnuAsm,
|
props: {hasSwitchRange, hasComputedGoto, hasCpp, hasGcGuard, hasGnuAsm,
|
||||||
hasNakedAttribute})
|
hasNakedAttribute})
|
||||||
|
|
||||||
|
# LLVM Frontend for GCC/G++
|
||||||
compiler llvmGcc:
|
compiler llvmGcc:
|
||||||
result = gcc()
|
result = gcc() # Uses settings from GCC
|
||||||
|
|
||||||
result.name = "llvm_gcc"
|
result.name = "llvm_gcc"
|
||||||
result.compilerExe = "llvm-gcc"
|
result.compilerExe = "llvm-gcc"
|
||||||
result.cppCompiler = "llvm-g++"
|
result.cppCompiler = "llvm-g++"
|
||||||
result.buildLib = "llvm-ar rcs $libfile $objfiles"
|
result.buildLib = "llvm-ar rcs $libfile $objfiles"
|
||||||
|
|
||||||
|
# Clang (LLVM) C/C++ Compiler
|
||||||
compiler clang:
|
compiler clang:
|
||||||
result = llvmGcc()
|
result = llvmGcc() # Uses settings from llvmGcc
|
||||||
|
|
||||||
result.name = "clang"
|
result.name = "clang"
|
||||||
result.compilerExe = "clang"
|
result.compilerExe = "clang"
|
||||||
result.cppCompiler = "clang++"
|
result.cppCompiler = "clang++"
|
||||||
|
|
||||||
|
# Microsoft Visual C/C++ Compiler
|
||||||
compiler vcc:
|
compiler vcc:
|
||||||
result = (
|
result = (
|
||||||
name: "vcc",
|
name: "vcc",
|
||||||
|
|
@ -123,6 +129,7 @@ compiler vcc:
|
||||||
packedPragma: "#pragma pack(1)",
|
packedPragma: "#pragma pack(1)",
|
||||||
props: {hasCpp, hasAssume, hasNakedDeclspec})
|
props: {hasCpp, hasAssume, hasNakedDeclspec})
|
||||||
|
|
||||||
|
# Intel C/C++ Compiler
|
||||||
compiler icl:
|
compiler icl:
|
||||||
# Intel compilers try to imitate the native ones (gcc and msvc)
|
# Intel compilers try to imitate the native ones (gcc and msvc)
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
|
|
@ -134,6 +141,7 @@ compiler icl:
|
||||||
result.compilerExe = "icl"
|
result.compilerExe = "icl"
|
||||||
result.linkerExe = "icl"
|
result.linkerExe = "icl"
|
||||||
|
|
||||||
|
# Local C Compiler
|
||||||
compiler lcc:
|
compiler lcc:
|
||||||
result = (
|
result = (
|
||||||
name: "lcc",
|
name: "lcc",
|
||||||
|
|
@ -158,6 +166,7 @@ compiler lcc:
|
||||||
packedPragma: "", # XXX: not supported yet
|
packedPragma: "", # XXX: not supported yet
|
||||||
props: {})
|
props: {})
|
||||||
|
|
||||||
|
# Borland C Compiler
|
||||||
compiler bcc:
|
compiler bcc:
|
||||||
result = (
|
result = (
|
||||||
name: "bcc",
|
name: "bcc",
|
||||||
|
|
@ -182,6 +191,7 @@ compiler bcc:
|
||||||
packedPragma: "", # XXX: not supported yet
|
packedPragma: "", # XXX: not supported yet
|
||||||
props: {hasCpp})
|
props: {hasCpp})
|
||||||
|
|
||||||
|
# Digital Mars C Compiler
|
||||||
compiler dmc:
|
compiler dmc:
|
||||||
result = (
|
result = (
|
||||||
name: "dmc",
|
name: "dmc",
|
||||||
|
|
@ -206,6 +216,7 @@ compiler dmc:
|
||||||
packedPragma: "#pragma pack(1)",
|
packedPragma: "#pragma pack(1)",
|
||||||
props: {hasCpp})
|
props: {hasCpp})
|
||||||
|
|
||||||
|
# Watcom C Compiler
|
||||||
compiler wcc:
|
compiler wcc:
|
||||||
result = (
|
result = (
|
||||||
name: "wcc",
|
name: "wcc",
|
||||||
|
|
@ -230,6 +241,7 @@ compiler wcc:
|
||||||
packedPragma: "", # XXX: not supported yet
|
packedPragma: "", # XXX: not supported yet
|
||||||
props: {hasCpp})
|
props: {hasCpp})
|
||||||
|
|
||||||
|
# Tiny C Compiler
|
||||||
compiler tcc:
|
compiler tcc:
|
||||||
result = (
|
result = (
|
||||||
name: "tcc",
|
name: "tcc",
|
||||||
|
|
@ -254,6 +266,7 @@ compiler tcc:
|
||||||
packedPragma: "", # XXX: not supported yet
|
packedPragma: "", # XXX: not supported yet
|
||||||
props: {hasSwitchRange, hasComputedGoto})
|
props: {hasSwitchRange, hasComputedGoto})
|
||||||
|
|
||||||
|
# Pelles C Compiler
|
||||||
compiler pcc:
|
compiler pcc:
|
||||||
# Pelles C
|
# Pelles C
|
||||||
result = (
|
result = (
|
||||||
|
|
@ -279,6 +292,7 @@ compiler pcc:
|
||||||
packedPragma: "", # XXX: not supported yet
|
packedPragma: "", # XXX: not supported yet
|
||||||
props: {})
|
props: {})
|
||||||
|
|
||||||
|
# Your C Compiler
|
||||||
compiler ucc:
|
compiler ucc:
|
||||||
result = (
|
result = (
|
||||||
name: "ucc",
|
name: "ucc",
|
||||||
|
|
@ -339,7 +353,9 @@ var
|
||||||
compileOptions: string = ""
|
compileOptions: string = ""
|
||||||
ccompilerpath: string = ""
|
ccompilerpath: string = ""
|
||||||
|
|
||||||
proc nameToCC*(name: string): TSystemCC =
|
proc nameToCC*(name: string): TSystemCC =
|
||||||
|
## Returns the kind of compiler referred to by `name`, or ccNone
|
||||||
|
## if the name doesn't refer to any known compiler.
|
||||||
for i in countup(succ(ccNone), high(TSystemCC)):
|
for i in countup(succ(ccNone), high(TSystemCC)):
|
||||||
if cmpIgnoreStyle(name, CC[i].name) == 0:
|
if cmpIgnoreStyle(name, CC[i].name) == 0:
|
||||||
return i
|
return i
|
||||||
|
|
@ -348,17 +364,18 @@ proc nameToCC*(name: string): TSystemCC =
|
||||||
proc getConfigVar(c: TSystemCC, suffix: string): string =
|
proc getConfigVar(c: TSystemCC, suffix: string): string =
|
||||||
# use ``cpu.os.cc`` for cross compilation, unless ``--compileOnly`` is given
|
# use ``cpu.os.cc`` for cross compilation, unless ``--compileOnly`` is given
|
||||||
# for niminst support
|
# for niminst support
|
||||||
|
let fullSuffix = (if gCmd == cmdCompileToCpp: ".cpp" & suffix else: suffix)
|
||||||
if (platform.hostOS != targetOS or platform.hostCPU != targetCPU) and
|
if (platform.hostOS != targetOS or platform.hostCPU != targetCPU) and
|
||||||
optCompileOnly notin gGlobalOptions:
|
optCompileOnly notin gGlobalOptions:
|
||||||
let fullCCname = platform.CPU[targetCPU].name & '.' &
|
let fullCCname = platform.CPU[targetCPU].name & '.' &
|
||||||
platform.OS[targetOS].name & '.' &
|
platform.OS[targetOS].name & '.' &
|
||||||
CC[c].name & suffix
|
CC[c].name & fullSuffix
|
||||||
result = getConfigVar(fullCCname)
|
result = getConfigVar(fullCCname)
|
||||||
if result.len == 0:
|
if result.len == 0:
|
||||||
# not overriden for this cross compilation setting?
|
# not overriden for this cross compilation setting?
|
||||||
result = getConfigVar(CC[c].name & suffix)
|
result = getConfigVar(CC[c].name & fullSuffix)
|
||||||
else:
|
else:
|
||||||
result = getConfigVar(CC[c].name & suffix)
|
result = getConfigVar(CC[c].name & fullSuffix)
|
||||||
|
|
||||||
proc setCC*(ccname: string) =
|
proc setCC*(ccname: string) =
|
||||||
cCompiler = nameToCC(ccname)
|
cCompiler = nameToCC(ccname)
|
||||||
|
|
@ -482,7 +499,7 @@ proc getLinkOptions: string =
|
||||||
|
|
||||||
proc needsExeExt(): bool {.inline.} =
|
proc needsExeExt(): bool {.inline.} =
|
||||||
result = (optGenScript in gGlobalOptions and targetOS == osWindows) or
|
result = (optGenScript in gGlobalOptions and targetOS == osWindows) or
|
||||||
(platform.hostOS == osWindows)
|
(platform.hostOS == osWindows)
|
||||||
|
|
||||||
proc getCompilerExe(compiler: TSystemCC): string =
|
proc getCompilerExe(compiler: TSystemCC): string =
|
||||||
result = if gCmd == cmdCompileToCpp: CC[compiler].cppCompiler
|
result = if gCmd == cmdCompileToCpp: CC[compiler].cppCompiler
|
||||||
|
|
@ -539,6 +556,7 @@ proc getCompileCFileCmd*(cfilename: string, isExternal = false): string =
|
||||||
"lib", quoteShell(libpath)])
|
"lib", quoteShell(libpath)])
|
||||||
|
|
||||||
proc footprint(filename: string): TCrc32 =
|
proc footprint(filename: string): TCrc32 =
|
||||||
|
# note, '><' further modifies a crc value with a string.
|
||||||
result = crcFromFile(filename) ><
|
result = crcFromFile(filename) ><
|
||||||
platform.OS[targetOS].name ><
|
platform.OS[targetOS].name ><
|
||||||
platform.CPU[targetCPU].name ><
|
platform.CPU[targetCPU].name ><
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ hint[LineTooLong]=off
|
||||||
@if not bsd:
|
@if not bsd:
|
||||||
# -fopenmp
|
# -fopenmp
|
||||||
gcc.options.linker = "-ldl"
|
gcc.options.linker = "-ldl"
|
||||||
gpp.options.linker = "-ldl"
|
gcc.cpp.options.linker = "-ldl"
|
||||||
clang.options.linker = "-ldl"
|
clang.options.linker = "-ldl"
|
||||||
tcc.options.linker = "-ldl"
|
tcc.options.linker = "-ldl"
|
||||||
@end
|
@end
|
||||||
|
|
@ -101,19 +101,19 @@ hint[LineTooLong]=off
|
||||||
cc = clang
|
cc = clang
|
||||||
tlsEmulation:on
|
tlsEmulation:on
|
||||||
gcc.options.always = "-w -fasm-blocks"
|
gcc.options.always = "-w -fasm-blocks"
|
||||||
gpp.options.always = "-w -fasm-blocks -fpermissive"
|
gcc.cpp.options.always = "-w -fasm-blocks -fpermissive"
|
||||||
@else:
|
@else:
|
||||||
gcc.options.always = "-w"
|
gcc.options.always = "-w"
|
||||||
gpp.options.always = "-w -fpermissive"
|
gcc.cpp.options.always = "-w -fpermissive"
|
||||||
@end
|
@end
|
||||||
|
|
||||||
gcc.options.speed = "-O3 -fno-strict-aliasing"
|
gcc.options.speed = "-O3 -fno-strict-aliasing"
|
||||||
gcc.options.size = "-Os"
|
gcc.options.size = "-Os"
|
||||||
gcc.options.debug = "-g3 -O0"
|
gcc.options.debug = "-g3 -O0"
|
||||||
|
|
||||||
gpp.options.speed = "-O3 -fno-strict-aliasing"
|
gcc.cpp.options.speed = "-O3 -fno-strict-aliasing"
|
||||||
gpp.options.size = "-Os"
|
gcc.cpp.options.size = "-Os"
|
||||||
gpp.options.debug = "-g3 -O0"
|
gcc.cpp.options.debug = "-g3 -O0"
|
||||||
#passl = "-pg"
|
#passl = "-pg"
|
||||||
|
|
||||||
# Configuration for the LLVM GCC compiler:
|
# Configuration for the LLVM GCC compiler:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue