2012-06-15 22:42:10 +00:00
|
|
|
--
|
|
|
|
-- tests/actions/make/cpp/test_objects.lua
|
|
|
|
-- Validate the list of objects for a makefile.
|
2013-02-07 15:58:31 +00:00
|
|
|
-- Copyright (c) 2009-2013 Jason Perkins and the Premake project
|
2012-06-15 22:42:10 +00:00
|
|
|
--
|
|
|
|
|
2013-02-07 15:58:31 +00:00
|
|
|
local suite = test.declare("make_cpp_objects")
|
2012-06-15 22:42:10 +00:00
|
|
|
local cpp = premake.make.cpp
|
|
|
|
local project = premake5.project
|
|
|
|
|
|
|
|
|
|
|
|
--
|
2013-02-07 15:58:31 +00:00
|
|
|
-- Setup
|
2012-06-15 22:42:10 +00:00
|
|
|
--
|
|
|
|
|
|
|
|
local sln, prj
|
2013-02-07 15:58:31 +00:00
|
|
|
|
2012-06-15 22:42:10 +00:00
|
|
|
function suite.setup()
|
|
|
|
sln = test.createsolution()
|
|
|
|
end
|
2013-02-07 15:58:31 +00:00
|
|
|
|
2012-06-15 22:42:10 +00:00
|
|
|
local function prepare()
|
|
|
|
prj = premake.solution.getproject_ng(sln, 1)
|
|
|
|
cpp.objects(prj)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- If a file is listed at the project level, it should get listed in
|
|
|
|
-- the project level objects list.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.listFileInProjectObjects()
|
|
|
|
files { "src/hello.cpp" }
|
|
|
|
prepare()
|
|
|
|
test.capture [[
|
|
|
|
OBJECTS := \
|
|
|
|
$(OBJDIR)/hello.o \
|
|
|
|
|
|
|
|
]]
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- Only buildable files should be listed.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.onlyListBuildableFiles()
|
|
|
|
files { "include/gl.h", "src/hello.cpp" }
|
|
|
|
prepare()
|
|
|
|
test.capture [[
|
|
|
|
OBJECTS := \
|
|
|
|
$(OBJDIR)/hello.o \
|
|
|
|
|
|
|
|
]]
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- A file should only be listed in the configurations to which it belongs.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.configFilesAreConditioned()
|
|
|
|
configuration "Debug"
|
2012-07-04 16:52:25 +00:00
|
|
|
files { "src/hello_debug.cpp" }
|
|
|
|
configuration "Release"
|
|
|
|
files { "src/hello_release.cpp" }
|
2012-06-15 22:42:10 +00:00
|
|
|
prepare()
|
|
|
|
test.capture [[
|
|
|
|
OBJECTS := \
|
|
|
|
|
2012-06-22 13:27:03 +00:00
|
|
|
RESOURCES := \
|
|
|
|
|
2012-06-15 22:42:10 +00:00
|
|
|
ifeq ($(config),debug)
|
|
|
|
OBJECTS += \
|
2012-07-04 16:52:25 +00:00
|
|
|
$(OBJDIR)/hello_debug.o \
|
|
|
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(config),release)
|
|
|
|
OBJECTS += \
|
|
|
|
$(OBJDIR)/hello_release.o \
|
2012-06-15 22:42:10 +00:00
|
|
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
]]
|
|
|
|
end
|
|
|
|
|
2012-06-19 19:58:16 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- Two files with the same base name should have different object files.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.uniqueObjNames_onBaseNameCollision()
|
|
|
|
files { "src/hello.cpp", "src/greetings/hello.cpp" }
|
|
|
|
prepare()
|
|
|
|
test.capture [[
|
|
|
|
OBJECTS := \
|
|
|
|
$(OBJDIR)/hello.o \
|
|
|
|
$(OBJDIR)/hello1.o \
|
|
|
|
|
|
|
|
]]
|
|
|
|
end
|
|
|
|
|
2012-06-22 13:27:03 +00:00
|
|
|
|
|
|
|
--
|
|
|
|
-- Check handling of Windows resource files.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.compilesWindowsResourceFiles()
|
|
|
|
files { "src/hello.rc", "src/greetings/hello.rc" }
|
|
|
|
prepare()
|
|
|
|
test.capture [[
|
|
|
|
OBJECTS := \
|
|
|
|
|
|
|
|
RESOURCES := \
|
|
|
|
$(OBJDIR)/hello.res \
|
|
|
|
$(OBJDIR)/hello1.res \
|
|
|
|
|
|
|
|
]]
|
|
|
|
end
|
2012-06-29 13:05:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- If a custom rule builds to an object file, include it in the
|
|
|
|
-- link automatically to match the behavior of Visual Studio
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.customBuildRule()
|
|
|
|
files { "hello.x" }
|
|
|
|
configuration "**.x"
|
|
|
|
buildrule {
|
|
|
|
description = "Compiling %{file.name}",
|
2013-02-07 15:58:31 +00:00
|
|
|
commands = {
|
|
|
|
'cxc -c "%{file.path}" -o "%{cfg.objdir}/%{file.basename}.xo"',
|
2012-06-29 13:05:20 +00:00
|
|
|
'c2o -c "%{cfg.objdir}/%{file.basename}.xo" -o "%{cfg.objdir}/%{file.basename}.obj"'
|
|
|
|
},
|
|
|
|
outputs = { "%{cfg.objdir}/%{file.basename}.obj" }
|
|
|
|
}
|
|
|
|
prepare()
|
|
|
|
test.capture [[
|
|
|
|
OBJECTS := \
|
|
|
|
|
|
|
|
RESOURCES := \
|
|
|
|
|
|
|
|
ifeq ($(config),debug)
|
|
|
|
OBJECTS += \
|
|
|
|
obj/Debug/hello.obj \
|
|
|
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
]]
|
|
|
|
end
|
2013-02-07 15:58:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- If a file is excluded from a configuration, it should not be listed.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.excludedFromBuild_onExcludedFile()
|
|
|
|
files { "hello.cpp" }
|
|
|
|
configuration "Debug"
|
|
|
|
removefiles { "hello.cpp" }
|
|
|
|
prepare()
|
|
|
|
test.capture [[
|
|
|
|
OBJECTS := \
|
|
|
|
|
|
|
|
RESOURCES := \
|
|
|
|
|
|
|
|
ifeq ($(config),release)
|
|
|
|
OBJECTS += \
|
|
|
|
$(OBJDIR)/hello.o \
|
|
|
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
]]
|
|
|
|
end
|
|
|
|
|
|
|
|
function suite.excludedFromBuild_onExcludeFlag()
|
|
|
|
files { "hello.cpp" }
|
|
|
|
configuration { "Debug", "hello.cpp" }
|
|
|
|
flags { "ExcludeFromBuild" }
|
|
|
|
prepare()
|
|
|
|
test.capture [[
|
|
|
|
OBJECTS := \
|
|
|
|
|
|
|
|
RESOURCES := \
|
|
|
|
|
|
|
|
ifeq ($(config),release)
|
|
|
|
OBJECTS += \
|
|
|
|
$(OBJDIR)/hello.o \
|
|
|
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
]]
|
|
|
|
end
|