12.在CMake中自定义宏

在进行程序测试的时候,我们可以在代码中添加一些宏定义,通过这些宏来控制这些代码是否生效
add_definitions(-D宏名称)

test.cpp:

include <stdio.h>

define NUMBER 3

int main()
{
int a = 10;

ifdef DEBUG

printf("我是一个程序猿,我不会爬树...\n");

endif

for(int i=0; i<NUMBER; ++i)
{
    printf("hello, GCC!!!\n");
}
return 0;

}

CMakeLists.txt:
cmake_minimum_required(VERSION 3.10.2)
project(test)
add_definitions(-DDEBUG)
add_executable(app test.cpp)

image

posted @ 2026-01-06 14:46  r5ett  阅读(1)  评论(0)    收藏  举报