如何将 make 目标添加到 Eclipse 中的构建配置?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5577008/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 16:07:23  来源:igfitidea点击:

How do I add a make target to a build configuration in Eclipse?

eclipsemakefileeclipse-cdt

提问by Josh Glover

I've added a testtarget to makefile.targetsin an Eclipse C++ project. Now, I want it to be built as part of my Debug and Release build configurations so I can have my unit tests run as part of the normal build process.

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

How do I do this, given that I cannot edit the auto-generated Debug/makefileand Release/makefile?

鉴于我无法编辑自动生成的Debug/makefile和,我该怎么做Release/makefile

回答by Greg

The pseudo-code below hopefully answers the question about target addition, and additionally addresses how to use variables in the makefile and source code.

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

It took me a day to figure this out using web resources, especially stackoverflow.com and eclipse.org forums. The Eclipse documentation for CDT is a bit vague on some points.

我花了一天的时间使用网络资源,尤其是 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}")

An example "makefile.init":

一个例子“makefile.init”:

GREP := /bin/grep

An example "makefile.defs":

一个例子“makefile.defs”:

ifndef ProjDirPath
  $(error "ProjDirPath" undefined as a "make variable" or "environment variable".)
endif

The generated makefile Debug/src/subdir.mk extracts dependencies into the file ${ProjDirPath}/Debug/src/${ProjName}.d, but you need to add an extra target for initial generation of a dependency. You could add a target for an:

生成的makefile Debug/src/subdir.mk 将依赖提取到文件${ProjDirPath}/Debug/src/${ProjName}.d 中,但是您需要为初始生成依赖添加一个额外的目标。您可以为以下对象添加目标:

#include "automated_headers.h"

by adding targets to ${ProjDirPath}/makefile.targets.

通过向 ${ProjDirPath}/makefile.targets 添加目标。

An example "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

回答by eriktous

Open the Make Targetview if it's not already open. It has a New Make Targetbutton.

打开Make Target查看,如果它不是已经打开。它有一个New Make Target按钮。

Alternatively, highlight the name of the target in the makefile, right click, and go to Make Targets -> Create....

或者,在 makefile 中突出显示目标的名称,右键单击,然后转到Make Targets -> Create...

Edit: I may have misunderstood your question. If you want the target to be built, when you click build, go to the build preferences and add it there.

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