#ifdef与CMake的调试与平台无关 [英] #ifdef DEBUG with CMake independent from platform
问题描述
我正在使用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时才记录日志。)
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与CMake的调试与平台无关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!