parse / and \ on cmake

if I let DJPEG_INCLUDE_DIRS=…\ …\libjpeg-turbo\include
the error will say can’t parse “\l” until I change \ to /
But other parameter DCMAKE_INSTALL_PREFIX or DOPENCV_EXTRA_MODULES_PATH can use the \
Why? How to know when using the / or \

cmake -G "Visual Studio 16 2019" ^
		-S . ^
		-DCMAKE_INSTALL_PREFIX=..\release ^
DOPENCV_EXTRA_MODULES_PATH=..\opencv_contrib\modules ^
		-DJPEG_INCLUDE_DIRS=../../libjpeg-turbo/include 

If \ works in some situations, it is by pure chance. CMake paths use always ‘/’.

Which is the correct ( " " or not " " )?
DJPEG_INCLUDE_DIRS=…/…/libjpeg-turbo/include
DJPEG_INCLUDE_DIRS="…/…/libjpeg-turbo/include"

cmake always use “/”, you mean windows and linux?
But windows path is D:\test
linux is /home/test

Yes. CMake is a multi-platform tool, so it uses its own format for paths.

CMake takes care to convert to native format when it interacts with the system…

Can I make sure that both of them are correct?

DJPEG_INCLUDE_DIRS=…/…/libjpeg-turbo/include
DJPEG_INCLUDE_DIRS="…/…/libjpeg-turbo/include"

The second is wrong. When you specify arguments on the command line, you have to quote, if needed, the whole expression:

.cmake .. "-DDJPEG_INCLUDE_DIRS=…/…/libjpeg-turbo/include"

See the Quoting Simple Command Arguments section of my blog post for a more detailed discussion of the quoting behavior you’re asking about.

“-DJPEG_INCLUDE_DIRS:PATH=…\libjpeg-turbo\include” would probably do what you want. CMake should convert relative path to an absolute path with proper slashes on a windows command line. Those other variables also get set to PATH type from what I remember.

See CMake(1) documentation on -D.

cmake always use “/”
I meet the problem.

SET PREFIX=../release
cmake --install build --config release --prefix %PREFIX%
xcopy build\xxx.lib %PREFIX%\lib

the xcopy dest will be the ../release\lib

xcopy build\xxx.lib %PREFIX:/=\%\lib

But that’s knowledge about how to use your shell and unrelated to cmake.

Also, instead of xcopy, properly use install() commands to the wanted result?

cmake always use “/”
xcpoy use " \ "

I try to use the “” on --prefix, it work

cmake --install build --config release --prefix ..\release