在CMake中自定义宏 add_definitions(-DDEBUG)

heheda@linux:~/Linux/loveDBTeacher-v6$ tree
.
├── CMakeLists.txt
└── test.c

0 directories, 2 files
heheda@linux:~/Linux/loveDBTeacher-v6$
  • test.c
#include 
#define NUMBER 3

int main() {
    int a = 10;
#ifdef DEBUG
    printf("我是一个程序猿,我不会爬树...\n");
#endif
    for(int i=0;i
  • CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(MyProject)
add_definitions(-DDEBUG)
add_executable(app test.c)
执行命令:
1.mkdir build
2.cd build
3.cmake ..
4.make
5./app

执行结果:
heheda@linux:~/Linux/loveDBTeacher-v6$ mkdir build
heheda@linux:~/Linux/loveDBTeacher-v6$ cd build
heheda@linux:~/Linux/loveDBTeacher-v6/build$ cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/heheda/Linux/loveDBTeacher-v6/build
heheda@linux:~/Linux/loveDBTeacher-v6/build$ make
Scanning dependencies of target app
[ 50%] Building C object CMakeFiles/app.dir/test.c.o
[100%] Linking C executable app
[100%] Built target app
heheda@linux:~/Linux/loveDBTeacher-v6/build$ ./app
我是一个程序猿,我不会爬树...
Hello,I am Heheda
Hello,I am Heheda
Hello,I am Heheda
heheda@linux:~/Linux/loveDBTeacher-v6/build$

在CMake中自定义宏 add_definitions(-DDEBUG)_第1张图片

你可能感兴趣的:(CMake,笔记,linux,CMake)