【问题标题】:How to create your own compilation key in C++ [duplicate]如何在 C++ 中创建自己的编译密钥 [重复]
【发布时间】:2020-03-13 11:24:21
【问题描述】:

你有自己的 cmake c++ 项目,你需要创建一个编译密钥并在代码中获取有关它的信息。

我需要这样的东西。

在 CmakeLists.txt 中:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -myTest")

在 *.cpp 中

if(KEY == "myTest"){
    // testing code.
}

【问题讨论】:

  • “编译键”是指预处理器定义,如-DKEY=myTest
  • @jkb 我在哪里可以了解它?

标签: c++ cmake compilation


【解决方案1】:

在 CMakeLists.txt 中

add_compile_definitions(TESTING)
add_compile_options(-Wall)

在 *.cpp 中

#ifdef TESTING
    std::cout << "testing" << std::endl;
#else
#endif

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-08-09
  • 1970-01-01
  • 1970-01-01
  • 2021-10-31
  • 2011-04-09
  • 1970-01-01
  • 2018-05-08
相关资源
最近更新 更多