我目前正在努力删除 CMake 作为库的依赖项,因为它似乎可以将大部分生成的代码设为静态。执行一些环境检查以查看我们使用的是哪种操作系统和编译器。 CMake 中的其中一项检查如下所示:
if (MSVC)
set (HAVE_SYS_TYPES_H 1)
set (HAVE_STDINT_H 1)
set (HAVE_STDDEF_H 1)
# snip more things
else ()
# snip more things
endif ()
可以用下面的 C 代码代替吗?
#ifdef _MSC_VER
#define HAVE_SYS_TYPES_H
#define HAVE_STDINT_H
#define HAVE_STDDEF_H
// snip more things
#else
// snip more things
#endif
我最担心的是情况是否相同。我认为它们是,但我无法找到任何可以证实这一点的东西,而且我目前无法访问工作的 Windows 开发环境来构建它并找出答案。
感谢您提供的任何可能的帮助!
最佳答案
CMake 3.4 MSVC Documentation :
True
when using Microsoft Visual C++.Set to
true
when the compiler is some version of Microsoft Visual C++.
MSDN Predefined Macros Documentation :
Lists the predefined ANSI/ISO C99 and Microsoft C++ implementation preprocessor macros.
...
Microsoft-Specific Predefined Macros
_MSC_VER Evaluates to an integer literal that encodes the major and minor number components of the compiler's version number. ...
由于 CMake MSVC
在使用 Microsoft Visual C++ 时为真,而 _MSC_VER
是 Microsoft 特定的 C++ 宏,因此在确定编译是否使用 Microsoft编译器。
但是,我不确定 #define
语句。 CMake set
命令只是设置 CMake 变量了解如何在 CMake 脚本中使用这些变量会很有用。
您拥有的可能就足够了,或者可能:
#define HAVE_SYS_TYPES_H 1
#define HAVE_STDINT_H 1
#define HAVE_STDDEF_H 1
CMake add_definitions
命令是添加预处理器定义的一种方法。
关于c++ - 来自 CMake 的 MSVC 是否与 _MSC_VER 相同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33001659/