2012-06-19 19:58:16 +00:00
|
|
|
--
|
|
|
|
-- tests/actions/make/cpp/test_file_rules.lua
|
|
|
|
-- Validate the makefile source building rules.
|
2014-04-25 15:53:01 +00:00
|
|
|
-- Copyright (c) 2009-2014 Jason Perkins and the Premake project
|
2012-06-19 19:58:16 +00:00
|
|
|
--
|
|
|
|
|
2013-08-11 18:22:24 +00:00
|
|
|
local suite = test.declare("make_cpp_file_rules")
|
|
|
|
local make = premake.make
|
2013-09-13 15:15:36 +00:00
|
|
|
local project = premake.project
|
2012-06-19 19:58:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
--
|
2013-01-23 16:50:54 +00:00
|
|
|
-- Setup
|
2012-06-19 19:58:16 +00:00
|
|
|
--
|
|
|
|
|
|
|
|
local sln, prj
|
2013-01-23 16:50:54 +00:00
|
|
|
|
2012-06-19 19:58:16 +00:00
|
|
|
function suite.setup()
|
2014-12-08 17:44:51 +00:00
|
|
|
premake.escaper(make.esc)
|
2012-06-19 19:58:16 +00:00
|
|
|
sln = test.createsolution()
|
|
|
|
end
|
2013-01-23 16:50:54 +00:00
|
|
|
|
2012-06-19 19:58:16 +00:00
|
|
|
local function prepare()
|
2013-09-13 15:52:00 +00:00
|
|
|
prj = premake.solution.getproject(sln, 1)
|
2013-08-11 18:22:24 +00:00
|
|
|
make.cppFileRules(prj)
|
2012-06-19 19:58:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--
|
|
|
|
-- 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 [[
|
|
|
|
$(OBJDIR)/hello.o: src/greetings/hello.cpp
|
2012-06-22 21:15:17 +00:00
|
|
|
@echo $(notdir $<)
|
2014-12-08 17:44:51 +00:00
|
|
|
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
2012-06-19 19:58:16 +00:00
|
|
|
$(OBJDIR)/hello1.o: src/hello.cpp
|
2012-06-22 21:15:17 +00:00
|
|
|
@echo $(notdir $<)
|
2014-12-08 17:44:51 +00:00
|
|
|
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
2012-06-19 19:58:16 +00:00
|
|
|
|
|
|
|
]]
|
|
|
|
end
|
2012-06-29 13:05:20 +00:00
|
|
|
|
|
|
|
|
2013-05-02 12:36:11 +00:00
|
|
|
--
|
|
|
|
-- C files in C++ projects should been compiled as c
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.cFilesGetsCompiledWithCCWhileInCppProject()
|
|
|
|
files { "src/hello.c", "src/test.cpp" }
|
|
|
|
prepare()
|
|
|
|
test.capture [[
|
|
|
|
$(OBJDIR)/hello.o: src/hello.c
|
|
|
|
@echo $(notdir $<)
|
2014-12-08 17:44:51 +00:00
|
|
|
$(SILENT) $(CC) $(ALL_CFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
2013-05-02 12:36:11 +00:00
|
|
|
$(OBJDIR)/test.o: src/test.cpp
|
|
|
|
@echo $(notdir $<)
|
2014-12-08 17:44:51 +00:00
|
|
|
$(SILENT) $(CXX) $(ALL_CXXFLAGS) $(FORCE_INCLUDE) -o "$@" -MF "$(@:%.o=%.d)" -c "$<"
|
2013-05-02 12:36:11 +00:00
|
|
|
|
|
|
|
]]
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-06-29 13:05:20 +00:00
|
|
|
--
|
|
|
|
-- If a custom build rule is supplied, it should be used.
|
|
|
|
--
|
|
|
|
|
|
|
|
function suite.customBuildRule()
|
|
|
|
files { "hello.x" }
|
2014-04-25 15:53:01 +00:00
|
|
|
filter "files:**.x"
|
2013-04-09 19:12:04 +00:00
|
|
|
buildmessage "Compiling %{file.name}"
|
|
|
|
buildcommands {
|
|
|
|
'cxc -c "%{file.path}" -o "%{cfg.objdir}/%{file.basename}.xo"',
|
|
|
|
'c2o -c "%{cfg.objdir}/%{file.basename}.xo" -o "%{cfg.objdir}/%{file.basename}.obj"'
|
2012-06-29 13:05:20 +00:00
|
|
|
}
|
2013-04-09 19:12:04 +00:00
|
|
|
buildoutputs { "%{cfg.objdir}/%{file.basename}.obj" }
|
2012-06-29 13:05:20 +00:00
|
|
|
prepare()
|
|
|
|
test.capture [[
|
|
|
|
ifeq ($(config),debug)
|
|
|
|
obj/Debug/hello.obj: hello.x
|
|
|
|
@echo "Compiling hello.x"
|
|
|
|
$(SILENT) cxc -c "hello.x" -o "obj/Debug/hello.xo"
|
|
|
|
$(SILENT) c2o -c "obj/Debug/hello.xo" -o "obj/Debug/hello.obj"
|
|
|
|
endif
|
|
|
|
ifeq ($(config),release)
|
|
|
|
obj/Release/hello.obj: hello.x
|
|
|
|
@echo "Compiling hello.x"
|
|
|
|
$(SILENT) cxc -c "hello.x" -o "obj/Release/hello.xo"
|
|
|
|
$(SILENT) c2o -c "obj/Release/hello.xo" -o "obj/Release/hello.obj"
|
|
|
|
endif
|
|
|
|
]]
|
|
|
|
end
|
2014-09-26 13:24:23 +00:00
|
|
|
|
|
|
|
function suite.customBuildRuleWithAdditionalInputs()
|
|
|
|
files { "hello.x" }
|
|
|
|
filter "files:**.x"
|
|
|
|
buildmessage "Compiling %{file.name}"
|
|
|
|
buildcommands {
|
|
|
|
'cxc -c "%{file.path}" -o "%{cfg.objdir}/%{file.basename}.xo"',
|
|
|
|
'c2o -c "%{cfg.objdir}/%{file.basename}.xo" -o "%{cfg.objdir}/%{file.basename}.obj"'
|
|
|
|
}
|
|
|
|
buildoutputs { "%{cfg.objdir}/%{file.basename}.obj" }
|
|
|
|
buildinputs { "%{file.path}.inc", "%{file.path}.inc2" }
|
|
|
|
prepare()
|
|
|
|
test.capture [[
|
|
|
|
ifeq ($(config),debug)
|
|
|
|
obj/Debug/hello.obj: hello.x hello.x.inc hello.x.inc2
|
|
|
|
@echo "Compiling hello.x"
|
|
|
|
$(SILENT) cxc -c "hello.x" -o "obj/Debug/hello.xo"
|
|
|
|
$(SILENT) c2o -c "obj/Debug/hello.xo" -o "obj/Debug/hello.obj"
|
|
|
|
endif
|
|
|
|
ifeq ($(config),release)
|
|
|
|
obj/Release/hello.obj: hello.x hello.x.inc hello.x.inc2
|
|
|
|
@echo "Compiling hello.x"
|
|
|
|
$(SILENT) cxc -c "hello.x" -o "obj/Release/hello.xo"
|
|
|
|
$(SILENT) c2o -c "obj/Release/hello.xo" -o "obj/Release/hello.obj"
|
|
|
|
endif
|
|
|
|
]]
|
|
|
|
end
|