如何确保 OMake 中引用了目录名称?

发布于 2024-10-28 10:22:40 字数 800 浏览 6 评论 0原文

我有一套相对复杂的 OMake 文件,专为在特定平台上进行交叉编译而设计。我的源代码是C++。

我是从 Windows 构建的,需要将包含名称中包含空格的目录传递给编译器。插入到命令行中以编译文件的包含字符串的创建方式是通过以下行创建的:

public.PREFIXED_INCLUDES = $`(addprefix $(INCLUDES_OPT), $(set $(absname $(INCLUDES))))

在 OMake 文件中的其他点上,我有一行类似:

INCLUDES += $(dir "$(LIBRARY_LOCATION)/Path with spaces/include")

在命令行中间,它扩展为:

-IC:\Library location with spaces\Path with spaces\include

我想要它将扩展为:

-I"C:\Library location with spaces\Path with spaces\include"

如果可能的话,除了“INCLUDES += ...”行之外,我不想更改任何内容,尽管修改该文件中的其他内容也可以。我不想做一些事情,比如更改 PREFIXED_INCLUDES 的定义,因为它位于一套 OMake 文件中,这些文件是 SDK 的一部分,可能会在我下面发生变化。这可能吗?如果是这样,我该怎么办?如果不是,我可以通过什么方式确保通过修改少量 makefile 代码(希望是一行)来引用包含空格的内容?

I have a relatively complicated suite of OMake files designed for cross-compiling on a specific platform. My source is in C++.

I'm building from Windows and I need to pass to the compiler include directories which have spaces in their names. The way that the includes string which is inserted in the command line to compile files is created is by the line:

public.PREFIXED_INCLUDES = 

I have a relatively complicated suite of OMake files designed for cross-compiling on a specific platform. My source is in C++.

I'm building from Windows and I need to pass to the compiler include directories which have spaces in their names. The way that the includes string which is inserted in the command line to compile files is created is by the line:

(addprefix $(INCLUDES_OPT), $(set $(absname $(INCLUDES))))

At some other point in the OMake files I have a line like:

INCLUDES += $(dir "$(LIBRARY_LOCATION)/Path with spaces/include")

In the middle of the command line this expands to:

-IC:\Library location with spaces\Path with spaces\include

I want it to expand to:

-I"C:\Library location with spaces\Path with spaces\include"

I don't want to change anything but the "INCLUDES += ..." line if possible, although modifying something else in that file is also fine. I don't want to have to do something like change the definition of PREFIXED_INCLUDES, as that's in a suite of OMake files which are part of an SDK which may change beneath me. Is this possible? If so, how can I do it? If not, in what ways can I make sure that includes with spaces in them are quoted by modifying little makefile code (hopefully one line)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

双马尾 2024-11-04 10:22:40

标准库函数 quote 在其参数周围添加转义引号,因此它应该完成这项工作:

INCLUDES += $(quote $(dir "$(LIBRARY_LOCATION)/Path with spaces/include"))

如果需要,请参阅 Omake 手册中的引用

The standard library function quote adds escaped quotes around its argument, so it should do the job:

INCLUDES += $(quote $(dir "$(LIBRARY_LOCATION)/Path with spaces/include"))

If needed, see quote in Omake manual.

好多鱼好多余 2024-11-04 10:22:40

如果其他人遇到同样的问题,我想我会分享我最终采用的解决方案,但从未弄清楚如何用引号引起来。我最终没有将带有空格的名称加上引号,而是将路径转换为短(8.3)版本。我通过一个名为 Short.js 的简单 JScript 文件和一个单行 OMake 函数来完成此操作。

脚本:

// Get Access to the file system.
var FileSystemObject = WScript.CreateObject("Scripting.FileSystemObject");

// Get the short path.
var shortPath = FileSystemObject.GetFolder(WScript.Arguments(0)).ShortPath;

// Output short path.
WScript.StdOut.Write(shortPath);

函数:

ShortDirectoryPath(longPath) =
    return $(dir $(shell cscript /Nologo $(dir ./tools/shorten.js) "$(absname $(longPath))"))

所以现在我只使用如下所示的行来包含:

INCLUDES += $(ShortDirectoryPath $(dir "$(LIBRARY_LOCATION)/Path with spaces/include"))

In case someone else is having the same problem, I thought I'd share the solution I eventually went with, having never figured out how to surround with quotes. Instead of putting quotes around a name with spaces in it I ended up converting the path to the short (8.3) version. I did this via a a simple JScript file called shorten.js and a one line OMake function.

The script:

// Get Access to the file system.
var FileSystemObject = WScript.CreateObject("Scripting.FileSystemObject");

// Get the short path.
var shortPath = FileSystemObject.GetFolder(WScript.Arguments(0)).ShortPath;

// Output short path.
WScript.StdOut.Write(shortPath);

The function:

ShortDirectoryPath(longPath) =
    return $(dir $(shell cscript /Nologo $(dir ./tools/shorten.js) "$(absname $(longPath))"))

So now I just use a line like the following for includes:

INCLUDES += $(ShortDirectoryPath $(dir "$(LIBRARY_LOCATION)/Path with spaces/include"))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文