CMAKE 未定义 CYGWIN 变量

标签 cmake cygwin

我在 Windows 7 64 位下的 cygwin 控制台上使用 cmake。但是,cmake 变量 CYGWIN ( https://cmake.org/cmake/help/v3.3/variable/CYGWIN.html ) 未定义。我错过了什么吗?

例如,这是我的 CMakeLists.txt:

message("CYGWIN: ${CYGWIN}")
message("CMAKE SYSTEM: ${CMAKE_SYSTEM_NAME}")
project ( foo CXX)

我启动 cygwin 控制台并执行以下操作:

cmake path/to/my/CMakeLists.txt

选定的输出:

>    CYGWIN: 
>    CMAKE SYSTEM:
> -- The CXX compiler identification is GNU 4.9.2
> 
>    ( a warning about the WIN32 variable not being defined by cmake anymore)
> 
> -- Check for working CXX compiler: /usr/bin/x86_64-w64-mingw32-g++.exe
> -- Check for working CXX compiler: /usr/bin/x86_64-w64-mingw32-g++.exe -- works
> -- Detecting CXX compiler ABI info
> -- Detecting CXX compiler ABI info - done
> -- Detecting CXX compile features
> -- Detecting CXX compile features - done
> -- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc.exe
> -- Check for working C compiler: /usr/bin/x86_64-w64-mingw32-gcc.exe -- works
> -- Configuring done
> -- Generating done
> -- Build files have been written to: /foo/directory

配置:

  • 命名 CYGWIN_NT-6.1
  • cmake 版本 3.3.2(CMake 套件由 Kitware (kitware.com/cmake) 维护和支持。

最佳答案

CYGWIN cmake 变量由 project() 命令定义。将其移到 message 命令之前可以解决问题。

CMakeLists.txt:

project(foo CXX)
message("CYGWIN: ${CYGWIN}")
message("CMAKE SYSTEM: ${CMAKE_SYSTEM_NAME}")

相关输出:

> -- The CXX compiler identification is GNU 4.9.2
>    (a lot of talking)
>    CYGWIN: 1
>    CMAKE SYSTEM: CYGWIN

关于CMAKE 未定义 CYGWIN 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35728166/

相关文章:

bash - cd(1) 和带空格的变量 (cygwin)

node.js - 在 cygwin 中更新 nodejs

android - 从 Android Studio/CMake 中的子模块导入自己的本地共享库

git - 无法创建标签

c++ - 使用带有 cmake 的 OpenGL ES 2.0 生成 iOS 静态库

c++ - 依赖于另一个库的库上的 CMake 和 target_link_libraries

cygwin - 使用 Cygwin 获取 Mac 地址和主机名

c - 尝试运行 C 程序时没有任何效果?

c++ - Boost gil读取图像错误

c++ - 无法使用 Visual Studio 和 CMake 将 __cplusplus 设置为 C++17 标准