summaryrefslogtreecommitdiff
path: root/tools/build/scripts/force_compile_as_c.lua
blob: 30de988e9b938e989a4689617b6782134d83f4d9 (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
29
30
31
32
if premake.override then
  local forced_c_files = {}

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

  -- for gmake
  premake.override(path, "iscfile", function(base, fname)
    if table.contains(forced_c_files, fname) then
      return true
    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_c_files, cfg.abspath) then
      if condition == nil or condition == '' then
        _p(3,'<CompileAs>CompileAsC</CompileAs>')
      else
        _p(3,'<CompileAs Condition="\'$(Configuration)|$(Platform)\'==\'%s\'">CompileAsC</CompileAs>', condition)
      end
    end
    return base(cfg, condition)
  end)
end