我在Eclipse C++項目中添加了一個test
目標到makefile.targets
。現在,我希望將它作爲我的調試和發佈版本配置的一部分進行構建,以便我的單元測試可以作爲正常構建過程的一部分運行。如何在Eclipse中將構建目標添加到構建配置中?
我該如何做,因爲我無法編輯自動生成的Debug/makefile
和Release/makefile
?
我在Eclipse C++項目中添加了一個test
目標到makefile.targets
。現在,我希望將它作爲我的調試和發佈版本配置的一部分進行構建,以便我的單元測試可以作爲正常構建過程的一部分運行。如何在Eclipse中將構建目標添加到構建配置中?
我該如何做,因爲我無法編輯自動生成的Debug/makefile
和Release/makefile
?
如果它尚未打開,請打開Make Target
視圖。它有一個New Make Target
按鈕。
或者,在生成文件中突出顯示目標名稱,單擊鼠標右鍵,然後轉到Make Targets -> Create...
。
編輯:我可能誤解了你的問題。如果您想要構建目標,那麼當您單擊構建時,請轉至構建首選項並將其添加到那裏。
下面的僞代碼有望回答有關目標添加的問題,並且還解決了如何在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
OK,我不希望引起我加入到'makefile.targets'被列入我的構建配置的目標。我會清理問題並嘗試您的建議。 :) – 2011-04-12 08:13:28
Hrm,編輯構建配置似乎對我來說是禁用的,至少從Projects> Build Configurations菜單 - Manage Build Configurations是灰色的。有什麼建議? – 2011-04-13 08:26:26
@Josh:對不起,我自己不使用自動生成的makefiles,所以我無法幫助你。我認爲它會類似於使用手動makefile,但沒有。 – eriktous 2011-04-13 10:22:33