diff --git a/modules/codelite/_preload.lua b/modules/codelite/_preload.lua index e62002c2..f9284635 100644 --- a/modules/codelite/_preload.lua +++ b/modules/codelite/_preload.lua @@ -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 diff --git a/modules/codelite/codelite_project.lua b/modules/codelite/codelite_project.lua index 102ca1ee..8c5af032 100755 --- a/modules/codelite/codelite_project.lua +++ b/modules/codelite/codelite_project.lua @@ -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) diff --git a/modules/codelite/tests/test_codelite_config.lua b/modules/codelite/tests/test_codelite_config.lua index 0719d771..421b2155 100644 --- a/modules/codelite/tests/test_codelite_config.lua +++ b/modules/codelite/tests/test_codelite_config.lua @@ -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 [[ - + ]] end @@ -219,7 +220,8 @@ cmd2 end function suite.OnProject_Completion() - language "C++11" + language "C++" + cppdialect "C++11" prepare() codelite.project.completion(prj) test.capture [[ diff --git a/modules/d/_preload.lua b/modules/d/_preload.lua index 58c5a581..39afb1cc 100644 --- a/modules/d/_preload.lua +++ b/modules/d/_preload.lua @@ -19,8 +19,6 @@ -- p.D = "D" - - table.insert(p.languages.all, p.D) api.addAllowed("language", p.D) api.addAllowed("floatingpoint", "None") diff --git a/modules/d/actions/gmake.lua b/modules/d/actions/gmake.lua index 020ba547..4f2b1cda 100644 --- a/modules/d/actions/gmake.lua +++ b/modules/d/actions/gmake.lua @@ -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 diff --git a/modules/d/actions/vstudio.lua b/modules/d/actions/vstudio.lua index 2106f29f..e2746ee6 100644 --- a/modules/d/actions/vstudio.lua +++ b/modules/d/actions/vstudio.lua @@ -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) diff --git a/modules/xcode/_preload.lua b/modules/xcode/_preload.lua index 3ab136a4..7c811077 100644 --- a/modules/xcode/_preload.lua +++ b/modules/xcode/_preload.lua @@ -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 diff --git a/modules/xcode/xcode_common.lua b/modules/xcode/xcode_common.lua index 3670ebb6..a95b3177 100644 --- a/modules/xcode/xcode_common.lua +++ b/modules/xcode/xcode_common.lua @@ -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 diff --git a/src/_premake_init.lua b/src/_premake_init.lua index f2f91c4d..26cc84a5 100644 --- a/src/_premake_init.lua +++ b/src/_premake_init.lua @@ -696,9 +696,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 { @@ -1368,11 +1406,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 diff --git a/src/actions/make/_make.lua b/src/actions/make/_make.lua index d9c5d85b..1806c121 100644 --- a/src/actions/make/_make.lua +++ b/src/actions/make/_make.lua @@ -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) diff --git a/src/actions/vstudio/vs2005.lua b/src/actions/vstudio/vs2005.lua index 0d8b6695..28a88cca 100644 --- a/src/actions/vstudio/vs2005.lua +++ b/src/actions/vstudio/vs2005.lua @@ -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 diff --git a/src/actions/vstudio/vs2008.lua b/src/actions/vstudio/vs2008.lua index 5da95b9f..81c0d745 100644 --- a/src/actions/vstudio/vs2008.lua +++ b/src/actions/vstudio/vs2008.lua @@ -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 diff --git a/src/actions/vstudio/vs2010.lua b/src/actions/vstudio/vs2010.lua index 4ad01840..2dd5116f 100644 --- a/src/actions/vstudio/vs2010.lua +++ b/src/actions/vstudio/vs2010.lua @@ -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 diff --git a/src/actions/vstudio/vs2012.lua b/src/actions/vstudio/vs2012.lua index abdba2c3..c38075db 100644 --- a/src/actions/vstudio/vs2012.lua +++ b/src/actions/vstudio/vs2012.lua @@ -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 diff --git a/src/actions/vstudio/vs2013.lua b/src/actions/vstudio/vs2013.lua index 086f4e76..60d7adf9 100644 --- a/src/actions/vstudio/vs2013.lua +++ b/src/actions/vstudio/vs2013.lua @@ -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 diff --git a/src/actions/vstudio/vs2015.lua b/src/actions/vstudio/vs2015.lua index 7413401b..1d1d4b6f 100644 --- a/src/actions/vstudio/vs2015.lua +++ b/src/actions/vstudio/vs2015.lua @@ -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 diff --git a/src/actions/vstudio/vs2017.lua b/src/actions/vstudio/vs2017.lua index 95caa77b..260396a9 100644 --- a/src/actions/vstudio/vs2017.lua +++ b/src/actions/vstudio/vs2017.lua @@ -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 diff --git a/src/base/action.lua b/src/base/action.lua index 3820911b..45ae9505 100644 --- a/src/base/action.lua +++ b/src/base/action.lua @@ -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 diff --git a/src/base/languages.lua b/src/base/languages.lua index 156be43a..38592a3e 100644 --- a/src/base/languages.lua +++ b/src/base/languages.lua @@ -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 - ) diff --git a/src/tools/gcc.lua b/src/tools/gcc.lua index 615c65b2..f80535af 100644 --- a/src/tools/gcc.lua +++ b/src/tools/gcc.lua @@ -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", diff --git a/tests/tools/test_gcc.lua b/tests/tools/test_gcc.lua index 06f6d812..bd3a9f60 100644 --- a/tests/tools/test_gcc.lua +++ b/tests/tools/test_gcc.lua @@ -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