我在Eclipse C ++项目中向test
添加了makefile.targets
目标。现在,我希望它是作为我的Debug和Release构建配置的一部分构建的,所以我可以将我的单元测试作为正常构建过程的一部分运行。
我是如何做到这一点的,因为我无法修改自动生成的Debug/makefile
和Release/makefile
?
答案 0 :(得分:2)
下面的伪代码有望回答关于目标添加的问题,另外还讨论了如何在makefile和源代码中使用变量。
我花了一天时间才使用网络资源来解决这个问题,特别是stackoverflow.com和eclipse.org论坛。 CDT的Eclipse文档在某些方面有点模糊。
// pseudo-code for Eclipse version Kepler
if ("Project.Properties.C/C++ Build.Generate Makefiles automatically" == true) {
// when using the automatically generated makefiles,
// use the -include's in the generated Debug/makefile
cp <your makefile init statements> $(ProjDirPath)/makefile.init
cp <your makefile definitions> $(ProjDirPath)/makefile.defs
cp <your makefile targets> $(ProjDirPath)/makefile.targets
} else {
// when using a makefile that you maintain, alter your own makefile
cp <your makefile targets> <your makefile>
}
// Additionally, you may want to provide variables for use in the makefile
// commands, whether it's your own makefile or the generated one:
// Note that:
// - "Preferences.C/C++.Build.Build Variables" and
// "Project.Properties.C/C++ Build.Build Variables"
// are *NOT directly available* to the makefile commands.
// - "Preferences.C/C++.Build.Environment" variables and
// "Project.Properties.C/C++ Build.Environment" variables
// *ARE available* to the makefile commands.
// - To make "Build Variables" available to the makefile and source files,
// add an environment variable as shown below. Especially useful are the
// built-in ones visible when "Show system variables" is checked.
// assign the build system variable "ProjDirPath" as a *user preference*
"Preferences.C/C++.Build.Environment".AddKeyValue("ProjDirPath",
"${ProjDirPath}"}
// assign the build system variable "ProjDirPath" as a *project property*
"Project.Properties.C/C++ Build.Environment".AddKeyValue("ProjDirPath",
${ProjDirPath}")
示例“makefile.init”:
GREP := /bin/grep
示例“makefile.defs”:
ifndef ProjDirPath
$(error "ProjDirPath" undefined as a "make variable" or "environment variable".)
endif
生成的makefile Debug / src / subdir.mk将依赖项提取到 文件$ {ProjDirPath} / Debug / src / $ {ProjName} .d,但是您需要为初始生成依赖项添加额外的目标。您可以为:
添加目标#include "automated_headers.h"
将目标添加到$ {ProjDirPath} /makefile.targets。
示例“makefile.targets”:
# targets to generate a header file
%/src/automated_headers.h: %/src/generate_headers.py $(external_library_info)
@echo "Generating $@"
%/src/generate_headers.py $(extrnal_library_info) $@
src/$(ProjName).o: $(ProjDirPath)/src/automated_headers.h
答案 1 :(得分:0)
如果Make Target
视图尚未打开,请将其打开。它有一个New Make Target
按钮。
或者,在makefile中突出显示目标的名称,右键单击,然后转到Make Targets -> Create...
。
编辑:我可能误解了你的问题。如果您希望构建目标,则在单击构建时,转到构建首选项并将其添加到那里。