From: Alexis Laferrière Date: Sun, 8 Dec 2013 02:42:25 +0000 (-0500) Subject: nitg/ffi: adds support for the cpp_compiler_options X-Git-Tag: v0.6.4~5^2~2 X-Git-Url: http://nitlanguage.org?ds=sidebyside nitg/ffi: adds support for the cpp_compiler_options Signed-off-by: Alexis Laferrière --- diff --git a/src/common_ffi/c_compiler_options.nit b/src/common_ffi/c_compiler_options.nit index 7733990..b596a8a 100644 --- a/src/common_ffi/c_compiler_options.nit +++ b/src/common_ffi/c_compiler_options.nit @@ -20,6 +20,7 @@ module c_compiler_options import c +import cpp redef class ToolContext var c_compiler_options_phase: Phase = new CCompilerOptionsPhase(self, null) @@ -30,13 +31,15 @@ private class CCompilerOptionsPhase fun compiler_annotation_name: String do return "c_compiler_option" fun linker_annotation_name: String do return "c_linker_option" + fun cpp_compiler_annotation_name: String do return "cpp_compiler_option" redef fun process_annotated_node(nmoduledecl, nat) do # Skip if we are not interested var annotation_name = nat.n_atid.n_id.text if annotation_name != compiler_annotation_name and - annotation_name != linker_annotation_name then return + annotation_name != linker_annotation_name and + annotation_name != cpp_compiler_annotation_name then return # Do some validity checks and print errors if the annotation is used incorrectly var modelbuilder = toolcontext.modelbuilder @@ -139,6 +142,8 @@ private class CCompilerOptionsPhase process_c_compiler_annotation(nmodule, cmd) else if annotation_name == linker_annotation_name then process_c_linker_annotation(nmodule, cmd) + else if annotation_name == cpp_compiler_annotation_name then + process_cpp_compiler_annotation(nmodule, cmd) else abort end end @@ -152,6 +157,11 @@ private class CCompilerOptionsPhase do nmodule.c_linker_options = "{nmodule.c_linker_options} {opt}" end + + fun process_cpp_compiler_annotation(nmodule: AModule, opt: String) + do + nmodule.cpp_compiler_options = "{nmodule.cpp_compiler_options} {opt}" + end end abstract class CCompilerOption diff --git a/src/common_ffi/cpp.nit b/src/common_ffi/cpp.nit index e06d53e..3af6d1a 100644 --- a/src/common_ffi/cpp.nit +++ b/src/common_ffi/cpp.nit @@ -26,6 +26,7 @@ end redef class AModule private var cpp_file: nullable CPPCompilationUnit = null + var cpp_compiler_options writable = "" end class CPPLanguage @@ -169,15 +170,22 @@ class CPPCompilationUnit files.add("{compdir}/{c_file}") - return new ExternCppFile("{compdir}/{c_file}") + return new ExternCppFile("{compdir}/{c_file}", amodule) end end class ExternCppFile super ExternFile + var amodule: AModule + init(path: String, amodule: AModule) + do + super + self.amodule = amodule + end + redef fun makefile_rule_name do return "{filename.basename("")}.o" - redef fun makefile_rule_content do return "g++ -c {filename.basename("")} -o {filename.basename("")}.o" + redef fun makefile_rule_content do return "g++ {amodule.cpp_compiler_options} -c {filename.basename("")} -o {filename.basename("")}.o" end class ForeignCppType