Skip to content

Commit

Permalink
Added support for Objective-C and Objective-C++ in xcode and gmake2
Browse files Browse the repository at this point in the history
- Added unit tests for Objective-C and Objective-C++
  • Loading branch information
samsinsane committed Mar 31, 2020
1 parent c4f3603 commit a4bba42
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 6 deletions.
4 changes: 2 additions & 2 deletions modules/gmake/gmake_cpp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions modules/gmake2/tests/test_gmake2_perfile_flags.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 7 additions & 1 deletion modules/xcode/tests/test_xcode_project.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<group>"; };
C8C6CC62F1018514D89D12A2 /* objsource.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; name = objsource.cpp; path = objsource.cpp; sourceTree = "<group>"; };
E4BF12E20AE5429471EC3922 /* objsource.c */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.objc; name = objsource.c; path = objsource.c; sourceTree = "<group>"; };
]]
end

Expand Down
4 changes: 2 additions & 2 deletions modules/xcode/xcode_common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/_premake_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@
"Default",
"C",
"C++",
"Objective-C",
"Objective-C++",
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/base/_foundation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion src/tools/clang.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
4 changes: 4 additions & 0 deletions src/tools/gcc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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++",
}
}

Expand Down

0 comments on commit a4bba42

Please sign in to comment.