summaryrefslogtreecommitdiff
path: root/tools/build/scripts/force_compile_as_cc.lua
blob: 16c68047683e5c46c9734d6430a926be3c3c2620 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
if premake.override then
  local forced_cc_files = {}

  -- Forces all of the given .c files to be compiled as if they were C++.
  function force_compile_as_cc(files)
    for _, val in ipairs(files) do
      for _, fname in ipairs(os.matchfiles(val)) do
        table.insert(forced_cc_files, path.getabsolute(fname))
      end
    end
  end

  -- for gmake
  premake.override(path, "iscfile", function(base, fname)
    if table.contains(forced_cc_files, fname) then
      return false
    else
      return base(fname)
    end
  end)
  -- for msvc
  premake.override(premake.vstudio.vc2010, "additionalCompileOptions", function(base, cfg, condition)
    if cfg.abspath and table.contains(forced_cc_files, cfg.abspath) then
      _p(3,'<CompileAs %s>CompileAsCpp</CompileAs>', condition)
    end
    return base(cfg, condition)
  end)
end