如何在C++中创建自己的编译密钥

How to create your own compilation key in C++

本文关键字:自己的 编译 密钥 创建 C++      更新时间:2023-10-16

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

我需要这样的东西。

在CmakeLists.txt中:

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

在*.cpp 中

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

在CMakeLists.txt 中

add_compile_definitions(TESTING)
add_compile_options(-Wall)

在*.cpp 中

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