我正在使用 CMake 在 Windows (Visual Studio) 以及 Linux 机器 (gcc) 上构建我的项目.我想将一些代码标记为仅调试",例如
I am using CMake for building my projects on Windows (Visual Studio) as well as on Linux machines(gcc). I'd like to mark some code as "debugging only", like with
#ifdef DEBUG
//some logging here
#endif
问题是:CMake调试"构建类型的所有平台上都有哪些编译器定义?DEBUG 好像不存在.(我只想在构建类型为 Debug 时进行日志记录或其他任何操作.)
The question is: what compiler definition is available on all platforms in the CMake "Debug" build type? DEBUG seems not to exist. (I want to have the logging or whatever only when the build type is Debug.)
CMake 默认将 -DNDEBUG
添加到 CMAKE_C_FLAGS_{RELEASE, MINSIZEREL} 中.因此,您可以使用 #ifndef NDEBUG
.
CMake adds -DNDEBUG
to the CMAKE_C_FLAGS_{RELEASE, MINSIZEREL} by default. So, you can use #ifndef NDEBUG
.
这篇关于#ifdef DEBUG 与 CMake 独立于平台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!