module c_compiler_options
import c
+import cpp
redef class ToolContext
var c_compiler_options_phase: Phase = new CCompilerOptionsPhase(self, null)
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
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
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
redef class AModule
private var cpp_file: nullable CPPCompilationUnit = null
+ var cpp_compiler_options writable = ""
end
class CPPLanguage
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