[英]Cross-platform paths in CMake
I have a project I can build on both Linux and Windows using CMake. 我有一个项目,我可以使用CMake在Linux和Windows上构建。 The only issue is that Unix-style paths, in CMakeLists.txt, can't work on Windows (which uses backslashes instead of slashes, also requiring the drive letter).
唯一的问题是CMakeLists.txt中的Unix风格路径无法在Windows上运行(它使用反斜杠而不是斜杠,也需要驱动器号)。
Is there any way I can write a cross-platform CMakeLists.txt? 有什么方法可以编写跨平台的CMakeLists.txt吗?
You question affects different details: 您的问题影响不同的细节:
GET_FILENAME_COMPONENT(X "${CMAKE_CURRENT_SOURCE_DIR}" REALPATH)
can solve the whole path without writing any absolute paths. GET_FILENAME_COMPONENT(X "${CMAKE_CURRENT_SOURCE_DIR}" REALPATH)
可以在不写绝对路径的情况下解决整个路径。 PATH
environment variable. PATH
环境变量中。 So you do not need to search them by yourself (with absolute paths) or FIND_PROGRAM()
to get the tools absolute path without guessing around. FIND_PROGRAM()
来获取工具绝对路径而不需要猜测。 You could add hints in which registry entries and paths cmake will search for the tool or IF(WIN32)
or IF(UNIX)
. IF(WIN32)
或IF(UNIX)
检测平台。 Hope, this helps... 希望这可以帮助...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.