
上QQ阅读APP看书,第一时间看更新
How it works
CMake correctly defines CMAKE_SYSTEM_NAME for the target OS and therefore there is typically no need to use custom commands, tools, or scripts to query this information. The value of this variable can then be used to implement OS-specific conditionals and workarounds. On systems that have the uname command, this variable is set to the output of uname -s. The variable is set to "Darwin" on macOS. On Linux and Windows, it evaluates to "Linux" and "Windows", respectively. We now know how to execute a specific CMake code on a certain OS if we need to. Of course, we should try to minimize such customization in order to simplify migration to new platforms.
To minimize trouble when moving from one platform to another, you should avoid using Shell commands directly and also avoid explicit path delimiters (forward slashes on Linux and macOS and backward slashes on Windows). Only use forward slashes in CMake code as path delimiters and CMake will automatically translate them for the OS environment in question.