在cmake中如何做条件预处理器#ifdef #endif
。
例如有一个 #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
最佳答案
您可以在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}
关于CMakeLists.txt 如何包含条件预处理器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46886308/