【问题标题】:CMakeLists.txt how to include conditional preprocessor [duplicate]CMakeLists.txt 如何包含条件预处理器 [重复]
【发布时间】:2018-04-03 19:42:59
【问题描述】:

在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

【问题讨论】:

标签: c cmake preprocessor


【解决方案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}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-22
    • 1970-01-01
    • 1970-01-01
    • 2011-02-07
    • 1970-01-01
    • 1970-01-01
    • 2017-08-09
    • 1970-01-01
    相关资源
    最近更新 更多