Merge pull request #776 from Blizzard/dialect-language

[core] Use 'cdialect' and 'cppdialect' instead of 'language'.
This commit is contained in:
Tom van Dijck 2017-05-25 08:43:53 -07:00 committed by GitHub
commit c5c3cd5b2c
21 changed files with 243 additions and 162 deletions

View File

@ -22,13 +22,10 @@
-- The capabilities of this action
valid_kinds = { "ConsoleApp", "WindowedApp", "Makefile", "SharedLib", "StaticLib", "Utility" },
valid_languages = { "C", "C++" },
valid_tools = {
cc = { "gcc", "clang", "msc" }
},
supports_language = function(lang)
return p.languages.isc(lang) or
p.languages.iscpp(lang)
end,
-- Workspace and project generation logic

View File

@ -355,11 +355,11 @@
end
function m.isCpp11(cfg)
return (cfg.language == 'gnu++11') or (cfg.language == 'C++11') or cfg.flags["C++11"]
return (cfg.cppdialect == 'gnu++11') or (cfg.cppdialect == 'C++11')
end
function m.isCpp14(cfg)
return (cfg.language == 'gnu++14') or (cfg.language == 'C++14') or cfg.flags["C++14"]
return (cfg.cppdialect == 'gnu++14') or (cfg.cppdialect == 'C++14')
end
function m.completion(cfg)

View File

@ -41,13 +41,14 @@
rtti "Off"
pic "On"
symbols "On"
language "C++11"
language "C++"
cppdialect "C++11"
flags { "NoBufferSecurityCheck" }
buildoptions { "-opt1", "-opt2" }
prepare()
codelite.project.compiler(cfg)
test.capture [[
<Compiler Options="-O0;-fPIC;-g;-fno-exceptions;-fno-stack-protector;-std=c++11;-fno-rtti;-opt1;-opt2" C_Options="-O0;-fPIC;-g;-opt1;-opt2" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" UseDifferentPCHFlags="no" PCHFlags="">
<Compiler Options="-O0;-fPIC;-g;-std=c++11;-fno-exceptions;-fno-stack-protector;-fno-rtti;-opt1;-opt2" C_Options="-O0;-fPIC;-g;-opt1;-opt2" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" UseDifferentPCHFlags="no" PCHFlags="">
</Compiler>
]]
end
@ -219,7 +220,8 @@ cmd2</StartupCommands>
end
function suite.OnProject_Completion()
language "C++11"
language "C++"
cppdialect "C++11"
prepare()
codelite.project.completion(prj)
test.capture [[

View File

@ -19,8 +19,6 @@
--
p.D = "D"
table.insert(p.languages.all, p.D)
api.addAllowed("language", p.D)
api.addAllowed("floatingpoint", "None")

View File

@ -28,12 +28,9 @@
--
-- Patch the gmake action with the allowed tools...
--
gmake.valid_languages = table.join(gmake.valid_languages, { p.D } )
gmake.valid_tools.dc = { "dmd", "gdc", "ldc" }
p.override(gmake, "supports_language", function(oldfn, lang)
return oldfn(lang) or lang == p.D;
end)
function m.make.separateCompilation(prj)
local some = false
local all = true

View File

@ -19,12 +19,10 @@
-- Patch the vstudio actions with D support...
--
for k,v in pairs({ "vs2005", "vs2008", "vs2010", "vs2012", "vs2013", "vs2015" }) do
for k,v in pairs({ "vs2005", "vs2008", "vs2010", "vs2012", "vs2013", "vs2015", "vs2017" }) do
local vs = p.action.get(v)
if vs ~= nil then
p.override(vs, "supports_language", function(oldfn, lang)
return oldfn(lang) or lang == p.D;
end)
table.insert( vs.valid_languages, p.D )
vs.valid_tools.dc = { "dmd", "gdc", "ldc" }
p.override(vs, "onProject", function(oldfn, prj)

View File

@ -40,13 +40,11 @@
-- The capabilities of this action
valid_kinds = { "ConsoleApp", "WindowedApp", "SharedLib", "StaticLib", "Makefile", "None" },
valid_languages = { "C", "C++" },
valid_tools = {
cc = { "gcc", "clang" },
},
supports_language = function(lang)
return p.languages.isc(lang) or
p.languages.iscpp(lang)
end,
-- Workspace and project generation logic

View File

@ -960,18 +960,8 @@
function xcode.XCBuildConfiguration_CLanguageStandard(settings, cfg)
if (p.languages.isc(cfg.language)) then
if cfg.language ~= "C" then
settings['GCC_C_LANGUAGE_STANDARD'] = cfg.language:lower()
else
if cfg.flags['C99'] then
settings['GCC_C_LANGUAGE_STANDARD'] = 'C99'
elseif cfg.flags['C11'] then
settings['GCC_C_LANGUAGE_STANDARD'] = 'C11'
else
settings['GCC_C_LANGUAGE_STANDARD'] = 'C90'
end
end
if cfg.cdialect and cfg.cdialect ~= "Default" then
settings['GCC_C_LANGUAGE_STANDARD'] = cfg.cdialect
else
settings['GCC_C_LANGUAGE_STANDARD'] = 'gnu99'
end
@ -979,16 +969,8 @@
function xcode.XCBuildConfiguration_CppLanguageStandard(settings, cfg)
if (p.languages.iscpp(cfg.language)) then
if cfg.language ~= "C++" then
settings['CLANG_CXX_LANGUAGE_STANDARD'] = cfg.language:lower()
else
if cfg.flags['C++11'] then
settings['CLANG_CXX_LANGUAGE_STANDARD'] = 'c++11'
elseif cfg.flags['C++14'] then
settings['CLANG_CXX_LANGUAGE_STANDARD'] = 'c++14'
end
end
if cfg.cppdialect and cfg.cppdialect ~= "Default" then
settings['CLANG_CXX_LANGUAGE_STANDARD'] = cfg.cppdialect
end
end

View File

@ -707,9 +707,47 @@
api.register {
name = "language",
scope = "project",
kind = "string",
allowed = {
"C",
"C++",
"C#"
}
}
api.register {
name = "cdialect",
scope = "config",
kind = "string",
allowed = p.languages.all
allowed = {
"Default",
"C89",
"C90",
"C99",
"C11",
"gnu89",
"gnu90",
"gnu99",
"gnu11",
}
}
api.register {
name = "cppdialect",
scope = "config",
kind = "string",
allowed = {
"Default",
"C++98",
"C++11",
"C++14",
"C++17",
"gnu++98",
"gnu++11",
"gnu++14",
"gnu++17",
}
}
api.register {
@ -1385,11 +1423,45 @@
-- 31 January 2017
api.deprecateValue("flags", "C++11", 'Use `language "C++11"` instead', function(value) end, function(value) end)
api.deprecateValue("flags", "C++14", 'Use `language "C++14"` instead', function(value) end, function(value) end)
api.deprecateValue("flags", "C90", 'Use `language "C90"` instead', function(value) end, function(value) end)
api.deprecateValue("flags", "C99", 'Use `language "C99"` instead', function(value) end, function(value) end)
api.deprecateValue("flags", "C11", 'Use `language "C11"` instead', function(value) end, function(value) end)
api.deprecateValue("flags", "C++11", 'Use `cppdialect "C++11"` instead',
function(value)
cppdialect "C++11"
end,
function(value)
cppdialect "Default"
end)
api.deprecateValue("flags", "C++14", 'Use `cppdialect "C++14"` instead',
function(value)
cppdialect "C++14"
end,
function(value)
cppdialect "Default"
end)
api.deprecateValue("flags", "C90", 'Use `cdialect "gnu90"` instead',
function(value)
cdialect "gnu90"
end,
function(value)
cdialect "Default"
end)
api.deprecateValue("flags", "C99", 'Use `cdialect "gnu99"` instead',
function(value)
cdialect "gnu99"
end,
function(value)
cdialect "Default"
end)
api.deprecateValue("flags", "C11", 'Use `cdialect "gnu11"` instead',
function(value)
cdialect "gnu11"
end,
function(value)
cdialect "Default"
end)
-- 13 April 2017

View File

@ -21,18 +21,12 @@
description = "Generate GNU makefiles for POSIX, MinGW, and Cygwin",
valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Utility", "Makefile" },
valid_languages = { "C", "C++", "C#" },
valid_tools = {
cc = { "clang", "gcc" },
dotnet = { "mono", "msnet", "pnet" }
},
supports_language = function(lang)
return p.languages.isc(lang) or
p.languages.iscpp(lang) or
p.languages.isdotnet(lang)
end,
onWorkspace = function(wks)
p.escaper(make.esc)
p.generate(wks, make.getmakefilename(wks, false), make.generate_workspace)

View File

@ -86,15 +86,11 @@
-- The capabilities of this action
valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Makefile", "None" },
valid_languages = { "C", "C++", "C#" },
valid_tools = {
cc = { "msc" },
dotnet = { "msnet" },
},
supports_language = function(lang)
return p.languages.isc(lang) or
p.languages.iscpp(lang) or
p.languages.isdotnet(lang)
end,
-- Workspace and project generation logic

View File

@ -28,15 +28,11 @@
-- The capabilities of this action
valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Makefile", "None" },
valid_languages = { "C", "C++", "C#" },
valid_tools = {
cc = { "msc" },
dotnet = { "msnet" },
},
supports_language = function(lang)
return p.languages.isc(lang) or
p.languages.iscpp(lang) or
p.languages.isdotnet(lang)
end,
-- Workspace and project generation logic

View File

@ -135,15 +135,11 @@
-- The capabilities of this action
valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Makefile", "None", "Utility" },
valid_languages = { "C", "C++", "C#" },
valid_tools = {
cc = { "msc" },
dotnet = { "msnet" },
},
supports_language = function(lang)
return p.languages.isc(lang) or
p.languages.iscpp(lang) or
p.languages.isdotnet(lang)
end,
-- Workspace and project generation logic

View File

@ -28,15 +28,11 @@
-- The capabilities of this action
valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Makefile", "None", "Utility" },
valid_languages = { "C", "C++", "C#" },
valid_tools = {
cc = { "msc" },
dotnet = { "msnet" },
},
supports_language = function(lang)
return p.languages.isc(lang) or
p.languages.iscpp(lang) or
p.languages.isdotnet(lang)
end,
-- Workspace and project generation logic

View File

@ -31,15 +31,11 @@
-- The capabilities of this action
valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Makefile", "None", "Utility" },
valid_languages = { "C", "C++", "C#" },
valid_tools = {
cc = { "msc" },
dotnet = { "msnet" },
},
supports_language = function(lang)
return p.languages.isc(lang) or
p.languages.iscpp(lang) or
p.languages.isdotnet(lang)
end,
-- Workspace and project generation logic

View File

@ -31,15 +31,11 @@
-- The capabilities of this action
valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Makefile", "None", "Utility" },
valid_languages = { "C", "C++", "C#" },
valid_tools = {
cc = { "msc" },
dotnet = { "msnet" },
},
supports_language = function(lang)
return p.languages.isc(lang) or
p.languages.iscpp(lang) or
p.languages.isdotnet(lang)
end,
-- Workspace and project generation logic

View File

@ -31,15 +31,11 @@
-- The capabilities of this action
valid_kinds = { "ConsoleApp", "WindowedApp", "StaticLib", "SharedLib", "Makefile", "None", "Utility", "Installer" },
valid_languages = { "C", "C++", "C#" },
valid_tools = {
cc = { "msc" },
dotnet = { "msnet" },
},
supports_language = function(lang)
return p.languages.isc(lang) or
p.languages.iscpp(lang) or
p.languages.isdotnet(lang)
end,
-- Workspace and project generation logic

View File

@ -246,7 +246,7 @@
return false
end
if not self.valid_languages and not self.valid_kinds and not self.supports_language then
if not self.valid_languages and not self.valid_kinds then
return true
end
@ -258,11 +258,6 @@
return true
end
if self.supports_language and self.supports_language(feature) then
return true
end
return false
end

View File

@ -6,63 +6,15 @@
local p = premake
p.languages = {}
local languages = p.languages
---
-- List of supported C languages.
---
languages.c = {
"C",
"C89",
"C90",
"C99",
"C11",
"gnu89",
"gnu90",
"gnu99",
"gnu11",
}
function languages.isc(value)
return table.contains(languages.c, value)
function p.languages.isc(value)
return value == "C";
end
---
-- List of supported C++ languages.
---
languages.cpp = {
"C++",
"C++98",
"C++11",
"C++14",
"C++17",
"gnu++98",
"gnu++11",
"gnu++14",
"gnu++17",
}
function languages.iscpp(value)
return table.contains(languages.cpp, value)
function p.languages.iscpp(value)
return value == "C++";
end
---
-- List of supported dotnet languages.
---
languages.dotnet = {
"C#"
}
function languages.isdotnet(value)
return table.contains(languages.dotnet, value)
function p.languages.isdotnet(value)
return value == "C#";
end
---
-- Combined list of all supported languages.
---
languages.all = table.join(
languages.c,
languages.cpp,
languages.dotnet
)

View File

@ -86,12 +86,7 @@
}
gcc.cflags = {
flags = {
["C90"] = "-std=gnu90",
["C99"] = "-std=gnu99",
["C11"] = "-std=gnu11",
},
language = {
cdialect = {
["C89"] = "-std=c89",
["C90"] = "-std=c90",
["C99"] = "-std=c99",
@ -136,10 +131,8 @@
},
flags = {
NoBufferSecurityCheck = "-fno-stack-protector",
["C++11"] = "-std=c++11",
["C++14"] = "-std=c++14",
},
language = {
cppdialect = {
["C++98"] = "-std=c++98",
["C++11"] = "-std=c++11",
["C++14"] = "-std=c++14",

View File

@ -555,3 +555,134 @@
prepare()
test.excludes({ "-Wl,-Bstatic" }, gcc.getlinks(cfg))
end
--
-- Test language flags are added properly.
--
function suite.cflags_onCDefault()
cdialect "Default"
prepare()
test.contains({ }, gcc.getcflags(cfg))
test.contains({ }, gcc.getcxxflags(cfg))
end
function suite.cflags_onC89()
cdialect "C89"
prepare()
test.contains({ "-std=c89" }, gcc.getcflags(cfg))
test.contains({ }, gcc.getcxxflags(cfg))
end
function suite.cflags_onC90()
cdialect "C90"
prepare()
test.contains({ "-std=c90" }, gcc.getcflags(cfg))
test.contains({ }, gcc.getcxxflags(cfg))
end
function suite.cflags_onC99()
cdialect "C99"
prepare()
test.contains({ "-std=c99" }, gcc.getcflags(cfg))
test.contains({ }, gcc.getcxxflags(cfg))
end
function suite.cflags_onC11()
cdialect "C11"
prepare()
test.contains({ "-std=c11" }, gcc.getcflags(cfg))
test.contains({ }, gcc.getcxxflags(cfg))
end
function suite.cflags_ongnu89()
cdialect "gnu89"
prepare()
test.contains({ "-std=gnu89" }, gcc.getcflags(cfg))
test.contains({ }, gcc.getcxxflags(cfg))
end
function suite.cflags_ongnu90()
cdialect "gnu90"
prepare()
test.contains({ "-std=gnu90" }, gcc.getcflags(cfg))
test.contains({ }, gcc.getcxxflags(cfg))
end
function suite.cflags_ongnu99()
cdialect "gnu99"
prepare()
test.contains({ "-std=gnu99" }, gcc.getcflags(cfg))
test.contains({ }, gcc.getcxxflags(cfg))
end
function suite.cflags_ongnu11()
cdialect "gnu11"
prepare()
test.contains({ "-std=gnu11" }, gcc.getcflags(cfg))
test.contains({ }, gcc.getcxxflags(cfg))
end
function suite.cxxflags_onCppDefault()
cppdialect "Default"
prepare()
test.contains({ }, gcc.getcxxflags(cfg))
test.contains({ }, gcc.getcflags(cfg))
end
function suite.cxxflags_onCpp98()
cppdialect "C++98"
prepare()
test.contains({ "-std=c++98" }, gcc.getcxxflags(cfg))
test.contains({ }, gcc.getcflags(cfg))
end
function suite.cxxflags_onCpp11()
cppdialect "C++11"
prepare()
test.contains({ "-std=c++11" }, gcc.getcxxflags(cfg))
test.contains({ }, gcc.getcflags(cfg))
end
function suite.cxxflags_onCpp14()
cppdialect "C++14"
prepare()
test.contains({ "-std=c++14" }, gcc.getcxxflags(cfg))
test.contains({ }, gcc.getcflags(cfg))
end
function suite.cxxflags_onCpp17()
cppdialect "C++17"
prepare()
test.contains({ "-std=c++17" }, gcc.getcxxflags(cfg))
test.contains({ }, gcc.getcflags(cfg))
end
function suite.cxxflags_onCppGnu98()
cppdialect "gnu++98"
prepare()
test.contains({ "-std=gnu++98" }, gcc.getcxxflags(cfg))
test.contains({ }, gcc.getcflags(cfg))
end
function suite.cxxflags_onCppGnu11()
cppdialect "gnu++11"
prepare()
test.contains({ "-std=gnu++11" }, gcc.getcxxflags(cfg))
test.contains({ }, gcc.getcflags(cfg))
end
function suite.cxxflags_onCppGnu14()
cppdialect "gnu++14"
prepare()
test.contains({ "-std=gnu++14" }, gcc.getcxxflags(cfg))
test.contains({ }, gcc.getcflags(cfg))
end
function suite.cxxflags_onCppGnu17()
cppdialect "gnu++17"
prepare()
test.contains({ "-std=gnu++17" }, gcc.getcxxflags(cfg))
test.contains({ }, gcc.getcflags(cfg))
end