[CMake] file(TO_NATIVE_PATH ... ) and cross-compiling

Stephen McDowell sjm324 at cornell.edu
Wed Mar 21 16:29:23 EDT 2018


Disclaimer: I cannot speak to intent, and have never used these before.

So since you’re cross compiling, when looking at the docs ( https://cmake.org/cmake/help/v3.0/command/file.html <https://cmake.org/cmake/help/v3.0/command/file.html> ), I think you can get away with using TO_CMAKE_PATH.  I do not know how you actually determine this, but the idea would be

if (CMAKE_CROSSCOMPILING)
  if (… host is windows …)
      if (… target is unix …)
        … use TO_CMAKE_PATH …
      else()
        … use TO_NATIVE_PATH …
      endif()
  else() # … host is unix …
    if (… target is unix …)
      … use TO_CMAKE_PATH or TO_NATIVE_PATH …
    else() # … target is windows
      … PROBLEM …
    endif()
endif()

That is, I think if you are compiling on Windows for Unix, you can cheat and use TO_CMAKE_PATH to get unix style paths.  But if you are compiling on unix for Windows, I don’t know how you get it to be Windows paths.

But if this does solve Windows -> Unix, you could maybe just message(FATAL_ERROR …) saying that cross compiling for Windows from Unix is not supported.  You could also take a look at the implementation of TO_NATIVE_PATH and just snag the Windows code and make your own function that converts it, maybe calling it to_windows_path() or something?

I hope that is helpful, but I really don’t know if anything in the above is possible :/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180321/684a321c/attachment.html>


More information about the CMake mailing list