[CMake] Backslashes in path names on Windows?

Sascha Cunz sascha-ml at babbelbox.org
Fri Jan 25 14:23:15 EST 2013


Am Freitag, 25. Januar 2013, 12:52:07 schrieb Kent Williams:
> I am testing a ITK patch I'm working on in Windows.  That involves entering
> a path in cmake-gui or ccmake.  The first time I tried it, I entered the
> path 'windows-wise' with backslashes as path separators.
> 
> That caused a syntax error at the point where that variable is used.  When
> I re-entered the path with unix-style forward slashes, the CMake
> configure/generate succeeded.
> 
> Is one supposed to always use Unix forward slashes when specifying paths to
> CMake?  If so is it documented to do that?

As almost all[1] of the Windows API actually supports forward-slashes, I'd 
personally recommend using them whenever cross-platformity is desired.

However, I never had any problems with using forward-slashes on windows in
general and esp. not in cmake. i.e. i also use to specifiy file names in
CMakeLists files like:

	SET( SRC_FILES
		foo/bar.c
		bar/foo.c
		${INSERT_VAR_FROM_CACHE_HERE} # <-- to connect to your question again
	)

This feels way more natural as it is also the way that C/C++ compilers expect
path names (even cl.exe).

Sascha

[1] An exception to this rule is: APIs that expect Unicode path names _and_
the value's content begins with L"\\?\". These don't do the automatic
forward-to-backward-slash conversion.

see also: (Section 'Maximum Path Length Limitation')
http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247%28v=vs.85%29.aspx

> If you're curious this is the ITK patch I'm working on:
> http://review.source.kitware.com/#/c/9308/


More information about the CMake mailing list