module Rmk::CCFlags
Meta-compiler flags
Constants
- CCFLAGS
- STD
Public Class Methods
# File lib/ccflags.rb, line 32 def self.get_vendor(cmd) case cmd.to_s when /clang/ then :clang when /g(cc|\+\+)/ then :gcc # Mind order! 'g++' suffix of 'clang++'! else :cc end end
Public Instance Methods
synonym for #optimize
# File lib/ccflags.rb, line 90 def _O(*args,**kwars) optimize(*args,**kwargs) end
synonym for #warnings
# File lib/ccflags.rb, line 206 def _W(*args) warnings(*args) end
synonym for #debug
# File lib/ccflags.rb, line 119 def _g(*args) debug(*args) end
synonym for #emit
# File lib/ccflags.rb, line 101 def _march(what) emit(_what) end
synonym for #standard
# File lib/ccflags.rb, line 130 def _std=(std = STD) standard(std) end
# File lib/ccflags.rb, line 210 def add_warning_flag(*what) what.flatten.each do |w| w = warning_flag(w) flags.add w unless flags.include?(w) end end
# File lib/ccflags.rb, line 41 def cc_or_cxx :cc end
# File lib/ccflags.rb, line 177 def check_ld comp = cc_or_cxx ocomp = comp == :cc ? :cxx : :cc other = Rmk.send(ocomp) if self.vendor != other.vendor warn "WARN: Using different compilers: CXX='#{self.send(comp)}' "\ "and CC='#{other.send(ocomp)}'!" end end
Instrument code for #coverage analysis.
# File lib/ccflags.rb, line 152 def coverage(yes=true) flags.remove /^-f(profile-arcs|test-coverage)/ ld.flags.remove('--coverage') if yes flags.add ['-fprofile-arcs','-ftest-coverage' ] ld.flags.add('--coverage') check_ld end end
Include #debug information?
# File lib/ccflags.rb, line 111 def debug(yes=true) flags.remove(/^-g/) flags.add('-g') if yes ld.debug(yes) end
#emit code for arch,
+arch=:default+ removes setting
# File lib/ccflags.rb, line 95 def emit(arch=:default) flags.remove(/^-m(arch|tune)=/) flags.add("-march=#{arch}") if arch && arch != :default end
+emit(:native)+ or +emit(:default)+
# File lib/ccflags.rb, line 106 def emit_native(yes) emit(yes ? :native : :default) end
# File lib/ccflags.rb, line 236 def fast_math(yes=true) flags.remove %r{^-f(fast-math| no-trapping-math| unsafe-math-optimizations| finite-math-only| no-errno-math| no-signaling-nans| no-rounding-math| cx-limited-range| no-signed-zeros)}x if yes flags.add '-ffast-math' warn "WARN Enabled -ffast-math!" end end
Don't omit frame pointer (due to optimization).
# File lib/ccflags.rb, line 146 def frame_pointer(yes=true) flags.remove /^-fno-omit-frame-pointer/ flags.add('-fno-omit-frame-pointer') if yes end
Set optimizer's inline limit to n (there is no meaningful
unit!).
# File lib/ccflags.rb, line 135 def inline_limit(n) flags.remove /^-(mllvm|inline-threshold|finline-limit)/ return if n.nil? || n==0 limit = Integer(n) f = CCFLAGS[vendor][:inline_limit] flags.add f.call(n) if f rescue warn "WARN Invalid inline_limit '#{n}'!" end
Enable OpenMP.
# File lib/ccflags.rb, line 164 def openmp(yes=true) flags.remove /^-fopenmp/ ld.remove_library /^g?omp$/ if yes flags.add CCFLAGS[vendor][:openmp] lib = CCFLAGS[vendor][:openmp_library] ld.add_library lib unless ld.libraries.include?(lib) check_ld end end
Set optimization level:
level is one of
:false-
or
:none ::debug- +1+_
-
or
:some 2-
or
true 3-
or
:max :fast-
The
nativeoption is passed to #emit_native : +:native=true+ is applied only when optimizing, and +:native=:force+ is always applied.
# File lib/ccflags.rb, line 59 def optimize(level,native=true) flags.remove(/^-O/) flags.remove(/^-DNDEBUG=?/) undefine('NDEBUG') case level when false, :none native = false unless native == :force when :debug flags.add CCFLAGS[vendor][:optimize_debug] native = false unless native == :force when 1, :some flags.add '-O1' when 2, true flags.add '-O2' define 'NDEBUG' when 3, :max flags.add '-O3' define 'NDEBUG' when :fast warn "WARN Enabled -ffast-math by -Ofast!" flags.add '-Ofast' define 'NDEBUG' else raise "Unknown optimization level '#{level}'." end emit_native(native) end
Set language #standard to
std.
# File lib/ccflags.rb, line 124 def standard(std = STD) flags.remove(/^-std=/) flags.add "-std=#{std}" if std && std != :default end
# File lib/ccflags.rb, line 28 def vendor @vendor ||= CCFlags.get_vendor(self.send(cc_or_cxx)) end
# File lib/ccflags.rb, line 217 def warning_flag(what) case what when :default, true '-Wall -pedantic -Wno-uninitialized' when :extra "#{warning_flag(:default)} -Wextra" when :error '-Werror' when :no_unused_but_set_variable CCFLAGS[vendor][:warn_no_unused_but_set_variable] when :no_unused CCFLAGS[vendor][:warn_no_unused] when :no_unknown_pragmas '-Wno-unknown-pragmas' else warn "Invalid warning '#{what}'!" end end
Enable/disable #warnings.
Recognized #warnings/warning levels
-
:default (a reasonably high warning level!)
-
:extra
-
:no_unused_but_set_variable (disable if available)
-
:no_unused disables some “unused …” #warnings (e.g., for :max)
# File lib/ccflags.rb, line 199 def warnings(what,*args) flags.remove(/^-(W[a-z]|pedantic)/) add_warning_flag(what) args.each { |w| add_warning_flag(w) } end