CMake convert unix to Windows path

I am trying to convert a unix-style MSYS path, such as /c/my/path/to/a/folder to a Windows path or something that CMake would understand, for example C:/my/path/to/a/folder. I would like him to work on the right path already.

Is there any correct way to do this?

Note. Please do not specify cygwin cygwin.

Edit: file(TO_CMAKE_PATH mypath result)not working

+4
source share
2 answers

There are no built-in CMake functions for this, but you can write a function / macro for this:

macro(msys_to_cmake_path MsysPath ResultingPath)
  string(REGEX REPLACE "^/([a-zA-Z])/" "\\1:/" ${ResultingPath} "${MsysPath}")
endmacro()

set(mypath "/c/my/path/to/a/folder")
msys_to_cmake_path(${mypath} result)

message("Converted \"${mypath}\" to \"${result}\".")

Having said that, I agree with Antonio's comment that it seems unusual in the first place.

+3
source

, MSYS MSYS ; , MSYS:

cmd //c echo /c/my/path/to/a/folder

c:/my/path/to/a/folder. , , , :

cmd //c echo /home/my/path/to/a/folder

C:/MinGW/msys/1.0/home/my/path/to/a/folder ( , MSYS , C:/MinGW/msys/1.0).

, MSYS- , msys.bat, ( 64- Windows), , (, CMake), :

C:/MinGW/msys/1.0/bin/sh -c 'cmd //c echo /home/my/path/to/a/folder'

, , MSYS, , , ; , MSYS cmd.exe Windows ( ).

, ( ), :

cmd //c echo "/home/my/path with spaces"

, cmd. , ; .

+2
source

All Articles