Better handling of native platform during configuration building stage
This commit is contained in:
parent
a1e313089f
commit
27d248c2d1
@ -2,8 +2,9 @@
|
|||||||
4.1 (in progress)
|
4.1 (in progress)
|
||||||
-----
|
-----
|
||||||
|
|
||||||
- Added support for multiple target platforms
|
- Added support for cross-compiling target platforms
|
||||||
- Added Xbox 360 support to Visual Studio 2005/2008
|
- Added Xbox 360 support to Visual Studio 2005/2008
|
||||||
|
- Added Mac OS X universal binary support
|
||||||
- Bug 2564404: FatalWarnings has no effect with gmake target
|
- Bug 2564404: FatalWarnings has no effect with gmake target
|
||||||
- Bug 2550759: pchheader option has wrong type
|
- Bug 2550759: pchheader option has wrong type
|
||||||
- Support links and libdirs for Visual Studio static libraries
|
- Support links and libdirs for Visual Studio static libraries
|
||||||
|
@ -186,3 +186,56 @@
|
|||||||
-- include the dependencies, built by GCC (with the -MMD flag)
|
-- include the dependencies, built by GCC (with the -MMD flag)
|
||||||
_p('-include $(OBJECTS:%%.o=%%.d)')
|
_p('-include $(OBJECTS:%%.o=%%.d)')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Write a block of configuration settings.
|
||||||
|
--
|
||||||
|
|
||||||
|
function premake.gmake_cpp_config(cfg)
|
||||||
|
local cc = premake[_OPTIONS.cc]
|
||||||
|
local platform = cc.platforms[cfg.platform or "Native"].suffix
|
||||||
|
|
||||||
|
_p('ifeq ($(config),%s%s)', _MAKE.esc(cfg.name:lower()), platform)
|
||||||
|
_p(' TARGETDIR = %s', _MAKE.esc(cfg.buildtarget.directory))
|
||||||
|
_p(' TARGET = $(TARGETDIR)/%s', _MAKE.esc(cfg.buildtarget.name))
|
||||||
|
_p(' OBJDIR = %s', _MAKE.esc(cfg.objectsdir))
|
||||||
|
_p(' DEFINES += %s', table.concat(cc.getdefines(cfg.defines), " "))
|
||||||
|
_p(' INCLUDES += %s', table.concat(cc.getincludedirs(cfg.includedirs), " "))
|
||||||
|
_p(' CPPFLAGS += %s $(DEFINES) $(INCLUDES)', cc.getcppflags(cfg))
|
||||||
|
_p(' CFLAGS += $(CPPFLAGS) $(ARCH) %s', table.concat(table.join(cc.getcflags(cfg), cfg.buildoptions), " "))
|
||||||
|
_p(' CXXFLAGS += $(CFLAGS) %s', table.concat(cc.getcxxflags(cfg), " "))
|
||||||
|
_p(' LDFLAGS += %s', table.concat(table.join(cc.getldflags(cfg), cc.getlinkflags(cfg), cfg.linkoptions), " "))
|
||||||
|
_p(' RESFLAGS += $(DEFINES) $(INCLUDES) %s', table.concat(table.join(cc.getdefines(cfg.resdefines), cc.getincludedirs(cfg.resincludedirs), cfg.resoptions), " "))
|
||||||
|
_p(' LDDEPS += %s', table.concat(_MAKE.esc(premake.getlinks(cfg, "siblings", "fullpath")), " "))
|
||||||
|
|
||||||
|
if cfg.kind == "StaticLib" then
|
||||||
|
_p(' LINKCMD = ar -rcs $(TARGET) $(OBJECTS)')
|
||||||
|
else
|
||||||
|
_p(' LINKCMD = $(%s) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(ARCH)', iif(cfg.language == "C", "CC", "CXX"))
|
||||||
|
end
|
||||||
|
|
||||||
|
_p(' define PREBUILDCMDS')
|
||||||
|
if #cfg.prebuildcommands > 0 then
|
||||||
|
_p('\t@echo Running pre-build commands')
|
||||||
|
_p('\t%s', table.implode(cfg.prebuildcommands, "", "", "\n\t"))
|
||||||
|
end
|
||||||
|
_p(' endef')
|
||||||
|
|
||||||
|
_p(' define PRELINKCMDS')
|
||||||
|
if #cfg.prelinkcommands > 0 then
|
||||||
|
_p('\t@echo Running pre-link commands')
|
||||||
|
_p('\t%s', table.implode(cfg.prelinkcommands, "", "", "\n\t"))
|
||||||
|
end
|
||||||
|
_p(' endef')
|
||||||
|
|
||||||
|
_p(' define POSTBUILDCMDS')
|
||||||
|
if #cfg.postbuildcommands > 0 then
|
||||||
|
_p('\t@echo Running post-build commands')
|
||||||
|
_p('\t%s', table.implode(cfg.postbuildcommands, "", "", "\n\t"))
|
||||||
|
end
|
||||||
|
_p(' endef')
|
||||||
|
|
||||||
|
_p('endif')
|
||||||
|
_p('')
|
||||||
|
end
|
||||||
|
@ -189,10 +189,12 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
local function buildprojectconfig(prj, cfgname, pltname)
|
local function buildprojectconfig(prj, cfgname, pltname)
|
||||||
|
pltname = pltname or "Native"
|
||||||
|
|
||||||
-- create the base configuration, flattening the list of objects and
|
-- create the base configuration, flattening the list of objects and
|
||||||
-- filtering out settings which do not match the current environment
|
-- filtering out settings which do not match the current environment
|
||||||
local terms = premake.getactiveterms()
|
local terms = premake.getactiveterms()
|
||||||
terms.platform = (pltname or ""):lower()
|
terms.platform = pltname:lower()
|
||||||
terms.config = (cfgname or ""):lower()
|
terms.config = (cfgname or ""):lower()
|
||||||
|
|
||||||
local cfg = buildconfig(prj, terms)
|
local cfg = buildconfig(prj, terms)
|
||||||
@ -276,7 +278,7 @@
|
|||||||
-- build a unique objects directory
|
-- build a unique objects directory
|
||||||
local function buildpath(cfg, variant)
|
local function buildpath(cfg, variant)
|
||||||
local dir = path.getabsolute(path.join(cfg.location, cfg.objdir or cfg.project.objdir or "obj"))
|
local dir = path.getabsolute(path.join(cfg.location, cfg.objdir or cfg.project.objdir or "obj"))
|
||||||
if variant > 1 then
|
if variant > 1 and cfg.platform ~= "Native" then
|
||||||
dir = path.join(dir, cfg.platform)
|
dir = path.join(dir, cfg.platform)
|
||||||
end
|
end
|
||||||
if variant > 2 then
|
if variant > 2 then
|
||||||
@ -341,17 +343,21 @@
|
|||||||
for _, prj in ipairs(sln.projects) do
|
for _, prj in ipairs(sln.projects) do
|
||||||
prj.__configs = { }
|
prj.__configs = { }
|
||||||
|
|
||||||
-- create a "root" config for project-wide settings
|
-- create a project-wide "root" config
|
||||||
prj.__configs[""] = buildprojectconfig(prj)
|
prj.__configs[""] = buildprojectconfig(prj)
|
||||||
|
|
||||||
-- then one per build configuration
|
-- then one per build configuration
|
||||||
for _, cfgname in ipairs(sln.configurations) do
|
for _, cfgname in ipairs(sln.configurations) do
|
||||||
|
-- build a platform independent config
|
||||||
prj.__configs[cfgname] = buildprojectconfig(prj, cfgname)
|
prj.__configs[cfgname] = buildprojectconfig(prj, cfgname)
|
||||||
|
|
||||||
-- then one per build configuration/platform pair
|
-- then one per build configuration/platform pair. Skip the native build
|
||||||
|
-- since it is the same as the platform independent config built above
|
||||||
if sln.platforms then
|
if sln.platforms then
|
||||||
for _, pltname in ipairs(sln.platforms) do
|
for _, pltname in ipairs(sln.platforms) do
|
||||||
prj.__configs[cfgname..":"..pltname] = buildprojectconfig(prj, cfgname, pltname)
|
if pltname ~= "Native" then
|
||||||
|
prj.__configs[cfgname .. ":" .. pltname] = buildprojectconfig(prj, cfgname, pltname)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -176,14 +176,12 @@
|
|||||||
if prj.project then prj = prj.project end
|
if prj.project then prj = prj.project end
|
||||||
|
|
||||||
-- if platform is not included in the solution, use general settings instead
|
-- if platform is not included in the solution, use general settings instead
|
||||||
if not table.contains(prj.solution.platforms or {}, pltname) then
|
if pltname == "Native" or not table.contains(prj.solution.platforms or {}, pltname) then
|
||||||
pltname = nil
|
pltname = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- build a cache key
|
local key = (cfgname or "")
|
||||||
local key = cfgname or ""
|
|
||||||
if pltname then key = key .. ":" .. pltname end
|
if pltname then key = key .. ":" .. pltname end
|
||||||
|
|
||||||
return prj.__configs[key]
|
return prj.__configs[key]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -90,9 +90,7 @@
|
|||||||
if (cfg.kind == "SharedLib" and not os.is("windows")) then
|
if (cfg.kind == "SharedLib" and not os.is("windows")) then
|
||||||
table.insert(result, "-fPIC")
|
table.insert(result, "-fPIC")
|
||||||
end
|
end
|
||||||
if cfg.platform then
|
table.insert(result, premake.gcc.platforms[cfg.platform].flags)
|
||||||
table.insert(result, premake.gcc.platforms[cfg.platform].flags)
|
|
||||||
end
|
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -136,10 +134,8 @@
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if cfg.platform then
|
table.insert(result, premake.gcc.platforms[cfg.platform].flags)
|
||||||
table.insert(result, premake.gcc.platforms[cfg.platform].flags)
|
table.insert(result, premake.gcc.platforms[cfg.platform].ldflags)
|
||||||
table.insert(result, premake.gcc.platforms[cfg.platform].ldflags)
|
|
||||||
end
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
dofile("test_vs2005_sln.lua")
|
dofile("test_vs2005_sln.lua")
|
||||||
dofile("test_vs2008_sln.lua")
|
dofile("test_vs2008_sln.lua")
|
||||||
dofile("test_vs200x_vcproj.lua")
|
dofile("test_vs200x_vcproj.lua")
|
||||||
|
dofile("test_gmake_cpp.lua")
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
|
@ -56,4 +56,11 @@
|
|||||||
local r = premake.getconfig(prj, "Debug", "Xbox360").defines
|
local r = premake.getconfig(prj, "Debug", "Xbox360").defines
|
||||||
test.isequal("GLOBAL:DEBUG", table.concat(r, ":"))
|
test.isequal("GLOBAL:DEBUG", table.concat(r, ":"))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function T.configs.DefaultToNativePlatform()
|
||||||
|
local r = premake.getconfig(prj, "Debug").platform
|
||||||
|
test.isequal("Native", r)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
91
tests/test_gmake_cpp.lua
Normal file
91
tests/test_gmake_cpp.lua
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
--
|
||||||
|
-- tests/test_gmake_cpp.lua
|
||||||
|
-- Automated test suite for GNU Make C/C++ project generation.
|
||||||
|
-- Copyright (c) 2009 Jason Perkins and the Premake project
|
||||||
|
--
|
||||||
|
|
||||||
|
T.gmake_cpp = { }
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Configure a solution for testing
|
||||||
|
--
|
||||||
|
|
||||||
|
local sln, prj
|
||||||
|
function T.gmake_cpp.setup()
|
||||||
|
sln = solution "MySolution"
|
||||||
|
configurations { "Debug", "Release" }
|
||||||
|
platforms { "native", "x64" }
|
||||||
|
|
||||||
|
prj = project "MyProject"
|
||||||
|
language "C++"
|
||||||
|
kind "ConsoleApp"
|
||||||
|
|
||||||
|
_ACTION = "gmake"
|
||||||
|
_OPTIONS.cc = "gcc"
|
||||||
|
_OPTIONS.os = "linux"
|
||||||
|
end
|
||||||
|
|
||||||
|
local function prepare()
|
||||||
|
io.capture()
|
||||||
|
premake.buildconfigs()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function T.gmake_cpp.BasicCfgBlock()
|
||||||
|
prepare()
|
||||||
|
local cfg = premake.getconfig(prj, "Debug")
|
||||||
|
premake.gmake_cpp_config(cfg)
|
||||||
|
test.capture [[
|
||||||
|
ifeq ($(config),debug)
|
||||||
|
TARGETDIR = .
|
||||||
|
TARGET = $(TARGETDIR)/MyProject
|
||||||
|
OBJDIR = obj/Debug
|
||||||
|
DEFINES +=
|
||||||
|
INCLUDES +=
|
||||||
|
CPPFLAGS += -MMD $(DEFINES) $(INCLUDES)
|
||||||
|
CFLAGS += $(CPPFLAGS) $(ARCH)
|
||||||
|
CXXFLAGS += $(CFLAGS)
|
||||||
|
LDFLAGS += -s
|
||||||
|
RESFLAGS += $(DEFINES) $(INCLUDES)
|
||||||
|
LDDEPS +=
|
||||||
|
LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(ARCH)
|
||||||
|
define PREBUILDCMDS
|
||||||
|
endef
|
||||||
|
define PRELINKCMDS
|
||||||
|
endef
|
||||||
|
define POSTBUILDCMDS
|
||||||
|
endef
|
||||||
|
endif
|
||||||
|
]]
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function T.gmake_cpp.PlatformSpecificBlock()
|
||||||
|
prepare()
|
||||||
|
local cfg = premake.getconfig(prj, "Debug", "x64")
|
||||||
|
premake.gmake_cpp_config(cfg)
|
||||||
|
test.capture [[
|
||||||
|
ifeq ($(config),debug64)
|
||||||
|
TARGETDIR = .
|
||||||
|
TARGET = $(TARGETDIR)/MyProject
|
||||||
|
OBJDIR = obj/x64/Debug
|
||||||
|
DEFINES +=
|
||||||
|
INCLUDES +=
|
||||||
|
CPPFLAGS += -MMD $(DEFINES) $(INCLUDES)
|
||||||
|
CFLAGS += $(CPPFLAGS) $(ARCH) -m64
|
||||||
|
CXXFLAGS += $(CFLAGS)
|
||||||
|
LDFLAGS += -s -m64 -L/usr/lib64
|
||||||
|
RESFLAGS += $(DEFINES) $(INCLUDES)
|
||||||
|
LDDEPS +=
|
||||||
|
LINKCMD = $(CXX) -o $(TARGET) $(OBJECTS) $(LDFLAGS) $(RESOURCES) $(ARCH)
|
||||||
|
define PREBUILDCMDS
|
||||||
|
endef
|
||||||
|
define PRELINKCMDS
|
||||||
|
endef
|
||||||
|
define POSTBUILDCMDS
|
||||||
|
endef
|
||||||
|
endif
|
||||||
|
]]
|
||||||
|
end
|
Reference in New Issue
Block a user