How do I make sure that a directory name is quoted in OMake?

228 Views Asked by At

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 = $`(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)?

2

There are 2 best solutions below

0
On

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"))
0
On

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.