在cmake中你如何做一个条件预处理器#ifdef #endif
。
例如,在soruce文件中有一个#ifdef #endif
,我想在赞美期间包含此文件?
你会怎么做?
#ifdef LWM2M_WITH_LOGS
#include <inttypes.h>
#define LOG(STR) lwm2m_printf("[%s:%d] " STR "\r\n", __func__ , __LINE__)
#endif
完整的源文件位于: Source file on github
CMakeLists.txt文件位于此处: CMakeLists.txt
答案 0 :(得分:1)
您可以在CMakeLists.txt
中添加选项:
option (WITH_LOGS "Use reach logging." OFF)
if (WITH_LOGS)
# Do some related work (if you need),
# ...
# and add definition for compiler
target_compile_definitions (lwm2mclient PRIVATE -DLWM2M_WITH_LOGS)
endif ()
配置您的项目:
cmake -DWITH_LOGS=ON {path-to-CMakeLists.txt}