0%

cmake 查看预处理文件

cmake 查看预处理文件

  1. 虽然clion自带的宏展开挺方便的, 但是偶尔需要整个文件预处理后的结果, 用于分析代码膨胀等问题
  2. cmake 直接生成了.o文件, 没法直接查看
  3. 去 cmake-build 文件夹下, 可以发现有个Makefile, 查看后其实就是项目的所有.o和输出目标
    1. 有多层cmake管理的有时候需要编译一下才会生成子目录的MakeFile, 需要进入对应的子目录的Makefile文件夹中才可以
  4. 直接make help 就可以看到有有输出.i .s .o的target
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
➜  thread_test_2 make help
The following are some of the valid targets for this Makefile:
... all (the default if no target is provided)
... clean
... depend
... edit_cache
... rebuild_cache
... stl_thread_test_2
... __/__/__/cpp_bootstrap/common/common_include/common_funcs.o
... __/__/__/cpp_bootstrap/common/common_include/common_funcs.i
... __/__/__/cpp_bootstrap/common/common_include/common_funcs.s
... __/__/__/cpp_bootstrap/common/common_include/common_includes.o
... __/__/__/cpp_bootstrap/common/common_include/common_includes.i
... __/__/__/cpp_bootstrap/common/common_include/common_includes.s
... __/__/__/cpp_bootstrap/common/common_include/log_init.o
... __/__/__/cpp_bootstrap/common/common_include/log_init.i
... __/__/__/cpp_bootstrap/common/common_include/log_init.s
... main.o
... main.i
... main.s
  1. 按需make需要的.i .s就行拉
1
2
3
4
5
6
7
8
➜  thread_test_2 make main.i                                     
Preprocessing CXX source to CMakeFiles/stl_thread_test_2.dir/main.cpp.i
➜ thread_test_2 ll
总用量 24K
drwxr-xr-x 3 root root 4.0K 4月 30 10:55 CMakeFiles
-rw-r--r-- 1 root root 1.2K 4月 30 10:44 cmake_install.cmake
-rw-r--r-- 1 root root 13K 4月 30 10:44 Makefile
➜ thread_test_2 cat CMakeFiles/stl_thread_test_2.dir/main.cpp.i