CMAKE add_custom_command:如何使用我的原始命令 [英] CMAKE add_custom_command: How to use my raw commands

查看:1159
本文介绍了CMAKE add_custom_command:如何使用我的原始命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 ADD_CUSTOM_COMMAND 向我的 vc2010 项目添加一些自定义生成命令。但是:



[1] 我只是发现CMAKE会自动插入比我预期的更多的代码。



例如,我想要的命令是:

  c:\Some Folder\MyTool.exe-arg0 -arg1 

CMakeLists.txt如下:

  add_custom_command(OUTPUT $ {outfile} 
COMMANDc:\Some Folder\\ \\ MyTool.exeARGS-arg0 -arg1
#COMMAND\c:\一个文件夹\MyTool.exe \将失败,将被解析!
MAIN_DEPENDENCY $ { infile}
VERBATIM)

但实际上我有:

  setlocal 
c:\Some Folder\MyTool.exe-arg0 -arg1
如果%errorlevel%neq 0 goto:cmEnd
:cmEnd
endloca& call:cmErrorLevel%errorlevel%& goto:cmDone
:cmErrorLevel
退出/ b%1
:cmDone
如果%errorlevel%neq 0 goto:VCEnd
pre>

这不是我想要的。我也试过字符串: COMMAND\$ {MYTOOL_PATH} \-arg0 -arg1,但是CMake刚刚无法解析它,因为有一个报价在字符串前面。
所以很不好我不能引用命令字符串,因为路径 c:\Some Folder\MyTool.exe 包含空格。



[2] 我也注意到CMake会自动扩展我的依赖项。



如果我添加到命令 DEPENS$(PATH_MACRO),我将最终自动获得依赖关系路径由CMake扩展: C:\MySolutionDir\ $(PATH_MACRO);但我只想要 $(PATH_MACRO),因为我会确保visual studio理解 $(PATH_MACRO)



> CMake如何才能接受我的原始输入,而不自动扩展路径或插入代码我不期望?我将确保我的输入将有效的视觉工作室。谢谢!



PS。我的CMake版本:2.8.10.2。 VS版本:visual studio 2010 Ultimate

解决方案

对于问题1,请尝试c:\\一些文件夹\\MyTool.exe-arg0 -arg1 。不需要 ARGS 参数,但要点是省略 -arg0 -arg1 周围的引号。 / p>

对于问题2,由于 $(PATH_MACRO)不是绝对路径,CMake将其视为相对于您的源目录。解决这个问题的最好方法可能是使用生成器表达式,但没有关于您的具体情况的进一步信息,我无法提供更好的答案。



有关信息on generator expression,see the docs for add_custom_command 的文档。


I am trying to add some custom build commands to my vc2010 project by using ADD_CUSTOM_COMMAND. But:

[1] I just find that CMAKE will automatically insert much more code than I hvae expected.

For example, I want the command exactly to be:

"c:\Some Folder\MyTool.exe" -arg0 -arg1

The corresponding code in CMakeLists.txt is like:

add_custom_command( OUTPUT ${outfile}
                  COMMAND "c:\Some Folder\MyTool.exe" ARGS "-arg0 -arg1"
                  # COMMAND "\"c:\Some Folder\MyTool.exe\"" will FAIL to be parsed!
                  MAIN_DEPENDENCY ${infile}
                  VERBATIM)

but actually I got:

setlocal
c:\Some Folder\MyTool.exe "-arg0 -arg1"
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd

This is not what I want. I have also tried the string: COMMAND "\"${MYTOOL_PATH}\" -arg0 -arg1", but CMake just failed to parse it because there is a quote in front of the string. So it's bad I can't quote the command string because the path c:\Some Folder\MyTool.exe contains spaces.

[2] I also notice CMake will automatically expand my dependency pathes.

If I add to the command DEPENS "$(PATH_MACRO)", I will eventually get the dependency path automatically expanded by CMake: C:\MySolutionDir\$(PATH_MACRO); But I only want $(PATH_MACRO), because I will make sure visual studio understands what $(PATH_MACRO) refers to.

So here is my question:

How can CMake only accept my raw inputs, without auto expanding the path or inserting code I don't expect? I will make sure my inputs will be valid for visual studio. Thanks!

PS. My CMake version: 2.8.10.2. VS version: visual studio 2010 Ultimate

解决方案

For issue 1, try "c:\\Some Folder\\MyTool.exe" -arg0 -arg1. The ARGS parameter isn't required, but the point is to omit the quotes around the -arg0 -arg1.

For issue 2, since $(PATH_MACRO) is not an absolute path, CMake sees it as a path relative to your source directory. The best way to resolve this is probably to use "generator expressions", but without further info on your exact case, I can't provide a better answer.

For info on generator expressions, see the docs for add_custom_command.

这篇关于CMAKE add_custom_command:如何使用我的原始命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆