Ninja & Make

Administrator
发布于 2023-12-15 / 21 阅读
0
1

Ninja & Make

Ninja & Make

ninja调试

ninja -v 打印执行的命令

一个小例子

test.c

	#include <stdio.h>
	int main()
	{
	    printf("%s", "Hello GCC\n");
	    return 0;
	}

CMakeLists.txt

	cmake_minimum_required(VERSION 3.1...3.21)
	project(test)
	add_executable(test test.c)

ninja编译,通过ninja -v 我们就可以看到执行的具体命令了

	mkdir build
	cd build
	
	cmake3 -GNinja ..
	-- The C compiler identification is GNU 7.3.1
	-- The CXX compiler identification is GNU 7.3.1
	-- Check for working C compiler: /opt/rh/devtoolset-7/root/usr/bin/cc
	-- Check for working C compiler: /opt/rh/devtoolset-7/root/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: /opt/rh/devtoolset-7/root/usr/bin/c++
	-- Check for working CXX compiler: /opt/rh/devtoolset-7/root/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/yuanwenxing/postgresql/testninja/build
	
	ninja -v
	[1/2] /opt/rh/devtoolset-7/root/usr/bin/cc    -MD -MT CMakeFiles/test.dir/test.c.o -MF CMakeFiles/test.dir/test.c.o.d -o CMakeFiles/test.dir/test.c.o   -c ../test.c
	[2/2] : && /opt/rh/devtoolset-7/root/usr/bin/cc    CMakeFiles/test.dir/test.c.o  -o test   && :

make 编译,make -n (通用方法,只打印命令,不执行)或者 make VERBOSE=1(部分适用)

-n, --just-print, --dry-run, --recon

	cmake3  ..
	-- The C compiler identification is GNU 7.3.1
	-- The CXX compiler identification is GNU 7.3.1
	-- Check for working C compiler: /opt/rh/devtoolset-7/root/usr/bin/cc
	-- Check for working C compiler: /opt/rh/devtoolset-7/root/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: /opt/rh/devtoolset-7/root/usr/bin/c++
	-- Check for working CXX compiler: /opt/rh/devtoolset-7/root/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/yuanwenxing/postgresql/testninja/build
	
	make -n
	/usr/bin/cmake3 -S/home/yuanwenxing/postgresql/testninja -B/home/yuanwenxing/postgresql/testninja/build --check-build-system CMakeFiles/Makefile.cmake 0
	/usr/bin/cmake3 -E cmake_progress_start /home/yuanwenxing/postgresql/testninja/build/CMakeFiles /home/yuanwenxing/postgresql/testninja/build/CMakeFiles/progress.marks
	make -s -f CMakeFiles/Makefile2 all
	make -s -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/depend
	cd /home/yuanwenxing/postgresql/testninja/build && /usr/bin/cmake3 -E cmake_depends "Unix Makefiles" /home/yuanwenxing/postgresql/testninja /home/yuanwenxing/postgresql/testninja /home/yuanwenxing/postgresql/testninja/build /home/yuanwenxing/postgresql/testninja/build /home/yuanwenxing/postgresql/testninja/build/CMakeFiles/test.dir/DependInfo.cmake --color=
	make -s -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/build
	/usr/bin/cmake3 -E cmake_echo_color --switch= --green --progress-dir=/home/yuanwenxing/postgresql/testninja/build/CMakeFiles --progress-num=1 "Building C object CMakeFiles/test.dir/test.c.o"
	/opt/rh/devtoolset-7/root/usr/bin/cc    -o CMakeFiles/test.dir/test.c.o   -c /home/yuanwenxing/postgresql/testninja/test.c
	/usr/bin/cmake3 -E cmake_echo_color --switch= --green --bold --progress-dir=/home/yuanwenxing/postgresql/testninja/build/CMakeFiles --progress-num=2 "Linking C executable test"
	/usr/bin/cmake3 -E cmake_link_script CMakeFiles/test.dir/link.txt --verbose=
	/usr/bin/cmake3 -E cmake_echo_color --switch= --progress-dir=/home/yuanwenxing/postgresql/testninja/build/CMakeFiles --progress-num=1,2 "Built target test"
	/usr/bin/cmake3 -E cmake_progress_start /home/yuanwenxing/postgresql/testninja/build/CMakeFiles 0
	
	make VERBOSE=1
	/usr/bin/cmake3 -S/home/yuanwenxing/postgresql/testninja -B/home/yuanwenxing/postgresql/testninja/build --check-build-system CMakeFiles/Makefile.cmake 0
	/usr/bin/cmake3 -E cmake_progress_start /home/yuanwenxing/postgresql/testninja/build/CMakeFiles /home/yuanwenxing/postgresql/testninja/build/CMakeFiles/progress.marks
	make  -f CMakeFiles/Makefile2 all
	make[1]: Entering directory `/home/yuanwenxing/postgresql/testninja/build'
	make  -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/depend
	make[2]: Entering directory `/home/yuanwenxing/postgresql/testninja/build'
	cd /home/yuanwenxing/postgresql/testninja/build && /usr/bin/cmake3 -E cmake_depends "Unix Makefiles" /home/yuanwenxing/postgresql/testninja /home/yuanwenxing/postgresql/testninja /home/yuanwenxing/postgresql/testninja/build /home/yuanwenxing/postgresql/testninja/build /home/yuanwenxing/postgresql/testninja/build/CMakeFiles/test.dir/DependInfo.cmake --color=
	make[2]: Leaving directory `/home/yuanwenxing/postgresql/testninja/build'
	make  -f CMakeFiles/test.dir/build.make CMakeFiles/test.dir/build
	make[2]: Entering directory `/home/yuanwenxing/postgresql/testninja/build'
	[ 50%] Building C object CMakeFiles/test.dir/test.c.o
	/opt/rh/devtoolset-7/root/usr/bin/cc    -o CMakeFiles/test.dir/test.c.o   -c /home/yuanwenxing/postgresql/testninja/test.c
	[100%] Linking C executable test
	/usr/bin/cmake3 -E cmake_link_script CMakeFiles/test.dir/link.txt --verbose=1
	/opt/rh/devtoolset-7/root/usr/bin/cc    CMakeFiles/test.dir/test.c.o  -o test 
	make[2]: Leaving directory `/home/yuanwenxing/postgresql/testninja/build'
	[100%] Built target test
	make[1]: Leaving directory `/home/yuanwenxing/postgresql/testninja/build'
	/usr/bin/cmake3 -E cmake_progress_start /home/yuanwenxing/postgresql/testninja/build/CMakeFiles 0


评论