2011-04-07 40 views
1

我在Eclipse C++项目中添加了一个test目标到makefile.targets。现在,我希望将它作为我的调试和发布版本配置的一部分进行构建,以便我的单元测试可以作为正常构建过程的一部分运行。如何在Eclipse中将构建目标添加到构建配置中?

我该如何做,因为我无法编辑自动生成的Debug/makefileRelease/makefile

回答

0

如果它尚未打开,请打开Make Target视图。它有一个New Make Target按钮。

或者,在生成文件中突出显示目标名称,单击鼠标右键,然后转到Make Targets -> Create...

编辑:我可能误解了你的问题。如果您想要构建目标,那么当您单击构建时,请转至构建首选项并将其添加到那里。

+0

OK,我不希望引起我加入到'makefile.targets'被列入我的构建配置的目标。我会清理问题并尝试您的建议。 :) – 2011-04-12 08:13:28

+0

Hrm,编辑构建配置似乎对我来说是禁用的,至少从Projects> Build Configurations菜单 - Manage Build Configurations是灰色的。有什么建议? – 2011-04-13 08:26:26

+0

@Josh:对不起,我自己不使用自动生成的makefiles,所以我无法帮助你。我认为它会类似于使用手动makefile,但没有。 – eriktous 2011-04-13 10:22:33

2

下面的伪代码有望回答有关目标添加的问题,并且还解决了如何在makefile和源代码中使用变量。

我花了一天的时间来弄清楚使用web资源,特别是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 

所生成的生成文件调试/ SRC/subdir.mk提取的依赖关系成 文件$ {ProjDirPath}/Debug/src/$ {ProjName} .d,但是您需要为初始生成一个依赖项添加一个额外的目标。你可以添加一个目标为:通过增加目标为$ {} ProjDirPath /makefile.targets

#include "automated_headers.h" 

一个例子“makefile.targets”:

# targets to generate a header file 
%/src/automated_headers.h: %/src/generate_headers.py $(external_library_info) 
    @echo "Generating [email protected]" 
    %/src/generate_headers.py $(extrnal_library_info) [email protected] 

src/$(ProjName).o: $(ProjDirPath)/src/automated_headers.h 
相关问题