From a4bba42013ab4b34f4c232cd4ab8113879f84f8c Mon Sep 17 00:00:00 2001 From: Sam Surtees Date: Mon, 14 May 2018 20:19:16 +1000 Subject: [PATCH] Added support for Objective-C and Objective-C++ in xcode and gmake2 - Added unit tests for Objective-C and Objective-C++ --- modules/gmake/gmake_cpp.lua | 4 ++-- .../gmake2/tests/test_gmake2_perfile_flags.lua | 18 ++++++++++++++++++ modules/xcode/tests/test_xcode_project.lua | 8 +++++++- modules/xcode/xcode_common.lua | 4 ++-- src/_premake_init.lua | 2 ++ src/base/_foundation.lua | 2 ++ src/tools/clang.lua | 3 ++- src/tools/gcc.lua | 4 ++++ 8 files changed, 39 insertions(+), 6 deletions(-) diff --git a/modules/gmake/gmake_cpp.lua b/modules/gmake/gmake_cpp.lua index ab09397b..9358a376 100644 --- a/modules/gmake/gmake_cpp.lua +++ b/modules/gmake/gmake_cpp.lua @@ -164,9 +164,9 @@ function cpp.compileas(prj, node) local result if node["compileas"] then - if p.languages.isc(node.compileas) then + if p.languages.isc(node.compileas) or node.compileas == p.OBJECTIVEC then result = '$(CC) $(ALL_CFLAGS)' - elseif p.languages.iscpp(node.compileas) then + elseif p.languages.iscpp(node.compileas) or node.compileas == p.OBJECTIVECPP then result = '$(CXX) $(ALL_CXXFLAGS)' end end diff --git a/modules/gmake2/tests/test_gmake2_perfile_flags.lua b/modules/gmake2/tests/test_gmake2_perfile_flags.lua index 78d111c2..89b88962 100644 --- a/modules/gmake2/tests/test_gmake2_perfile_flags.lua +++ b/modules/gmake2/tests/test_gmake2_perfile_flags.lua @@ -90,3 +90,21 @@ PERFILE_FLAGS_2 = $(ALL_CFLAGS) -msse -msse2 -mfpmath=sse,387 -msse3 -mssse3 -ms PERFILE_FLAGS_0 = $(ALL_CXXFLAGS) -fvisibility=protected ]] end + + function suite.perfile_compileas() + files { 'a.c', 'b.cpp' } + + filter { 'files:a.c' } + compileas "Objective-C" + filter { 'files:b.cpp' } + compileas "Objective-C++" + + prepare() + test.capture [[ +# Per File Configurations +# ############################################# + +PERFILE_FLAGS_0 = $(ALL_CFLAGS) -x objective-c +PERFILE_FLAGS_1 = $(ALL_CXXFLAGS) -x objective-c++ + ]] + end diff --git a/modules/xcode/tests/test_xcode_project.lua b/modules/xcode/tests/test_xcode_project.lua index 7d80846f..243126a8 100644 --- a/modules/xcode/tests/test_xcode_project.lua +++ b/modules/xcode/tests/test_xcode_project.lua @@ -298,15 +298,21 @@ end function suite.PBXFileReference_ListsSourceFilesCompileAs() - files { "source.c" } + files { "source.c", "objsource.c", "objsource.cpp" } filter { "files:source.c" } compileas "C++" + filter { "files:objsource.c" } + compileas "Objective-C" + filter { "files:objsource.cpp" } + compileas "Objective-C++" prepare() xcode.PBXFileReference(tr) test.capture [[ /* Begin PBXFileReference section */ 19A5C4E61D1697189E833B26 /* MyProject */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; name = MyProject; path = MyProject; sourceTree = BUILT_PRODUCTS_DIR; }; 7DC6D30C8137A53E02A4494C /* source.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.cpp; name = source.c; path = source.c; sourceTree = ""; }; + C8C6CC62F1018514D89D12A2 /* objsource.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; name = objsource.cpp; path = objsource.cpp; sourceTree = ""; }; + E4BF12E20AE5429471EC3922 /* objsource.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; name = objsource.c; path = objsource.c; sourceTree = ""; }; ]] end diff --git a/modules/xcode/xcode_common.lua b/modules/xcode/xcode_common.lua index c2c69d50..9081fdc0 100644 --- a/modules/xcode/xcode_common.lua +++ b/modules/xcode/xcode_common.lua @@ -106,9 +106,9 @@ return "sourcecode.c.c" elseif p.languages.iscpp(filecfg.compileas) then return "sourcecode.cpp.cpp" - elseif filecfg.language == "ObjC" then + elseif filecfg.compileas == p.OBJECTIVEC then return "sourcecode.c.objc" - elseif filecfg.language == "ObjCpp" then + elseif filecfg.compileas == p.OBJECTIVECPP then return "sourcecode.cpp.objcpp" end end diff --git a/src/_premake_init.lua b/src/_premake_init.lua index 8dfb1143..584593f4 100644 --- a/src/_premake_init.lua +++ b/src/_premake_init.lua @@ -182,6 +182,8 @@ "Default", "C", "C++", + "Objective-C", + "Objective-C++", } } diff --git a/src/base/_foundation.lua b/src/base/_foundation.lua index 7be869eb..ae4102ef 100644 --- a/src/base/_foundation.lua +++ b/src/base/_foundation.lua @@ -42,6 +42,8 @@ premake.MBCS = "MBCS" premake.NONE = "None" premake.DEFAULT = "Default" + premake.OBJECTIVEC = "Objective-C" + premake.OBJECTIVECPP = "Objective-C++" premake.ON = "On" premake.OFF = "Off" premake.POSIX = "posix" diff --git a/src/tools/clang.lua b/src/tools/clang.lua index 064a27c6..032b7f30 100644 --- a/src/tools/clang.lua +++ b/src/tools/clang.lua @@ -63,7 +63,8 @@ warnings = gcc.shared.warnings, symbols = gcc.shared.symbols, unsignedchar = gcc.shared.unsignedchar, - omitframepointer = gcc.shared.omitframepointer + omitframepointer = gcc.shared.omitframepointer, + compileas = gcc.shared.compileas } clang.cflags = table.merge(gcc.cflags, { diff --git a/src/tools/gcc.lua b/src/tools/gcc.lua index f9dab594..abd4c556 100644 --- a/src/tools/gcc.lua +++ b/src/tools/gcc.lua @@ -121,6 +121,10 @@ omitframepointer = { On = "-fomit-frame-pointer", Off = "-fno-omit-frame-pointer" + }, + compileas = { + ["Objective-C"] = "-x objective-c", + ["Objective-C++"] = "-x objective-c++", } }