Makefile入门,超级详细,cmakelists.txt生成的makefile文件一行一行注释

以前自己都是写CMakeList.txt文件,没有关注过Makefile文件,但是有时候CmakeList.txt却存在一些问题,比如当装有两个版本的库的时候,指示制定库的版本或者设置链接库的路径,但是仍然存在库链接错误的问题。以前遇到问题都是根据报错去网上搜,但是很多时候都搜不到合适的答案,所以决定研究一下Makefile文件,这样遇到编译问题就可以自己追根溯源了。
以一个常见cmake生成的Makefile文件为例,逐行进行分析讲解,如有不对的地方,欢迎在评论区留言。

# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.16

# Default target executed when no arguments are given to make.
# .PHONY 是伪目标的意思,正常makefile代码格式是这样的:
# target : dependencies
#	command
#包含target,dependencies 和command三部分,target 和 dependencies通常都是实体文件,例如可执行文件或者库文件。
#当target不存在,或者dependencies比target新的时候就会执行command,生成target。
#但是有些target并不是实体文件,例如 clean:
#.PHONY:clean
#clean:
#	rm -rf ${obj}
#clean 并不是一个实体文件,它的dependencies是空的。所以target永远比dependencies新,
#如果存在 target 同名文件,就不会执行command
#加上一个.PHONY说明clean是一个伪目标,不是实体目标
#make clean就可以执行对应的command了
#类似的还有all, install, clean, distclean, TAGS, info, check
#make <phony_target> 就执行对应的command。


#Make 的默认行为是执行Makefile的第一个target,该目标一般会带起多个目标的执行。
#例如下面的 default_target:all, default_target是一个伪目标,make不会检查是否生成具体的default_target文件。
#但是会检查 default_target 的 dependencies all的生成或者更新情况,如果all没有生成或者更新,就会生成all。
#all是在后面定义的
default_target: all

.PHONY : default_target

# Allow only one "make -f Makefile2" at a time, but pass parallelism.
.NOTPARALLEL:


#=============================================================================
# Special targets provided by cmake.

# Disable implicit rules so canonical targets will work.
.SUFFIXES:


# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =

.SUFFIXES: .hpux_make_needs_suffix_list


# Suppress display of executed commands.
$(VERBOSE).SILENT:


# A target that is always out of date.
cmake_force:

.PHONY : cmake_force

#=============================================================================
#这些都是自定义的变量
# Set environment variables for the build.

# The shell in which to execute make rules.
SHELL = /bin/sh

# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake

# The command to remove a file.
RM = /usr/bin/cmake -E remove -f

# Escaping for special characters.
EQUALS = =

# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /home/lho/perception/yolov8_onnx

# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /home/lho/perception/yolov8_onnx/build

#=============================================================================
# Targets provided globally by CMake.

# Special rule for the target rebuild_cache
rebuild_cache:
	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
	/usr/bin/cmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache

# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache

.PHONY : rebuild_cache/fast

# Special rule for the target edit_cache
edit_cache:
	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..."
	/usr/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available.
.PHONY : edit_cache

# Special rule for the target edit_cache
edit_cache/fast: edit_cache

.PHONY : edit_cache/fast

#根据前面default_target的定义的all, make将执行下面命令
#首先检查all 的dependencies cmake_check_build_system
#cmake_check_build_system 是 CMake 自动生成的一个脚本文件,用于检查当前的构建系统是否可用。
#在 CMake 构建过程中,该脚本会被自动调用,并生成一个名为 CMakeFiles/CMakeError.log 的日志文件,
#用于记录构建系统检查过程中的错误信息和警告。
#具体来说,cmake_check_build_system 会进行以下几个步骤的检查:
#检查当前操作系统的类型和版本号;
#检查编译器是否可用,以及其版本号;
#检查系统库是否可用,并记录其路径和版本号;
#检查编译选项是否正确设置。
#如果某一项检查失败,该脚本将会生成错误信息,并停止构建过程。您可以通过查看 CMakeFiles/CMakeError.log 文件来了解详细的错误信息,
#并尝试修复问题。
#如果您遇到了cmake_check_build_system 相关的问题,建议您仔细查看 CMakeFiles/CMakeError.log 文件,
#找出具体的错误信息,并针对性地进行修复。通常情况下,检查编译器、系统库和编译选项等方面的设置,可以解决这类问题。
#当cmake_check_build_system检查完毕后将执行后面命令

# The main all target
all: cmake_check_build_system

#CMAKE_COMMAND = /usr/bin/cmake 是自定义的变量,-E: CMake命令行模式
#/usr/bin/cmake -E cmake_progress_start 应该是一个固定的命令,也没有搜到其定义,不影响整体理解,因此先跳过

	$(CMAKE_COMMAND) -E cmake_progress_start /home/lho/perception/yolov8_onnx/build/CMakeFiles /home/lho/perception/yolov8_onnx/build/CMakeFiles/progress.marks
	
#顶层Makefile使用make -f调用子目录中的文件(文件名可以随意,不一定用Makefile作为文件名)作为Makefile,
#顶层Makefile中的export的变量也可以传递变量到底层目录,另外在命令行中加入变量赋值选项,将覆盖顶层Makefile中export的变量;
#make -f CMakeFiles/Makefile2 all 就是make Makefile2 中的all目标

	$(MAKE) -f CMakeFiles/Makefile2 all
#这是一个 CMake 命令,它使用 $(CMAKE_COMMAND) 变量指定的 CMake 可执行文件来启动构建进度报告。
#-E cmake_progress_start 选项指定了要执行的命令(启动构建进度报告),/home/lho/vscode/C/build/CMakeFiles 是进度文件的目录,
#0 是初始进度值
	$(CMAKE_COMMAND) -E cmake_progress_start /home/lho/perception/yolov8_onnx/build/CMakeFiles 0
.PHONY : all

# The main clean target
clean:
	$(MAKE) -f CMakeFiles/Makefile2 clean
.PHONY : clean

# The main clean target
clean/fast: clean

.PHONY : clean/fast

# Prepare targets for installation.
preinstall: all
	$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall

# Prepare targets for installation.
preinstall/fast:
	$(MAKE) -f CMakeFiles/Makefile2 preinstall
.PHONY : preinstall/fast

# clear depends
depend:
	$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend

#=============================================================================
# Target rules for targets named yolov8_onnx

# 下面的target, 默认运行make是不会生成的,除非自己手动make 时添加
#例如 make yolov8_onnx 就会单独生成 target yolov8_onnx
# Build rule for target.
yolov8_onnx: cmake_check_build_system
	$(MAKE) -f CMakeFiles/Makefile2 yolov8_onnx
.PHONY : yolov8_onnx

# fast build rule for target.
yolov8_onnx/fast:
	$(MAKE) -f CMakeFiles/yolov8_onnx.dir/build.make CMakeFiles/yolov8_onnx.dir/build
.PHONY : yolov8_onnx/fast

#=============================================================================
# Target rules for targets named yolov5_seg_onnx

# Build rule for target.
yolov5_seg_onnx: cmake_check_build_system
	$(MAKE) -f CMakeFiles/Makefile2 yolov5_seg_onnx
.PHONY : yolov5_seg_onnx

# fast build rule for target.
yolov5_seg_onnx/fast:
	$(MAKE) -f CMakeFiles/yolov5_seg_onnx.dir/build.make CMakeFiles/yolov5_seg_onnx.dir/build
.PHONY : yolov5_seg_onnx/fast

#=============================================================================
# Target rules for targets named yolov5_seg_utils

# Build rule for target.
yolov5_seg_utils: cmake_check_build_system
	$(MAKE) -f CMakeFiles/Makefile2 yolov5_seg_utils
.PHONY : yolov5_seg_utils

# fast build rule for target.
yolov5_seg_utils/fast:
	$(MAKE) -f CMakeFiles/yolov5_seg_utils.dir/build.make CMakeFiles/yolov5_seg_utils.dir/build
.PHONY : yolov5_seg_utils/fast

# target to build an object file
include/yolov8_seg_onnx.o:
	$(MAKE) -f CMakeFiles/yolov5_seg_onnx.dir/build.make CMakeFiles/yolov5_seg_onnx.dir/include/yolov8_seg_onnx.o
.PHONY : include/yolov8_seg_onnx.o

# target to preprocess a source file
include/yolov8_seg_onnx.i:
	$(MAKE) -f CMakeFiles/yolov5_seg_onnx.dir/build.make CMakeFiles/yolov5_seg_onnx.dir/include/yolov8_seg_onnx.i
.PHONY : include/yolov8_seg_onnx.i

# target to generate assembly for a file
include/yolov8_seg_onnx.s:
	$(MAKE) -f CMakeFiles/yolov5_seg_onnx.dir/build.make CMakeFiles/yolov5_seg_onnx.dir/include/yolov8_seg_onnx.s
.PHONY : include/yolov8_seg_onnx.s

# target to build an object file
include/yolov8_seg_utils.o:
	$(MAKE) -f CMakeFiles/yolov5_seg_utils.dir/build.make CMakeFiles/yolov5_seg_utils.dir/include/yolov8_seg_utils.o
.PHONY : include/yolov8_seg_utils.o

# target to preprocess a source file
include/yolov8_seg_utils.i:
	$(MAKE) -f CMakeFiles/yolov5_seg_utils.dir/build.make CMakeFiles/yolov5_seg_utils.dir/include/yolov8_seg_utils.i
.PHONY : include/yolov8_seg_utils.i

# target to generate assembly for a file
include/yolov8_seg_utils.s:
	$(MAKE) -f CMakeFiles/yolov5_seg_utils.dir/build.make CMakeFiles/yolov5_seg_utils.dir/include/yolov8_seg_utils.s
.PHONY : include/yolov8_seg_utils.s

# target to build an object file
src/main.o:
	$(MAKE) -f CMakeFiles/yolov8_onnx.dir/build.make CMakeFiles/yolov8_onnx.dir/src/main.o
.PHONY : src/main.o

# target to preprocess a source file
src/main.i:
	$(MAKE) -f CMakeFiles/yolov8_onnx.dir/build.make CMakeFiles/yolov8_onnx.dir/src/main.i
.PHONY : src/main.i

# target to generate assembly for a file
src/main.s:
	$(MAKE) -f CMakeFiles/yolov8_onnx.dir/build.make CMakeFiles/yolov8_onnx.dir/src/main.s
.PHONY : src/main.s

# Help Target
help:
	@echo "The following are some of the valid targets for this Makefile:"
	@echo "... all (the default if no target is provided)"
	@echo "... clean"
	@echo "... depend"
	@echo "... rebuild_cache"
	@echo "... yolov8_onnx"
	@echo "... yolov5_seg_onnx"
	@echo "... edit_cache"
	@echo "... yolov5_seg_utils"
	@echo "... include/yolov8_seg_onnx.o"
	@echo "... include/yolov8_seg_onnx.i"
	@echo "... include/yolov8_seg_onnx.s"
	@echo "... include/yolov8_seg_utils.o"
	@echo "... include/yolov8_seg_utils.i"
	@echo "... include/yolov8_seg_utils.s"
	@echo "... src/main.o"
	@echo "... src/main.i"
	@echo "... src/main.s"
.PHONY : help



#=============================================================================
# Special targets to cleanup operation of make.

# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
#这是一个 CMake 命令,它使用 $(CMAKE_COMMAND) 变量指定的 CMake 可执行文件来检查构建系统。
#-S$(CMAKE_SOURCE_DIR) 和 -B$(CMAKE_BINARY_DIR) 选项分别指定了源目录和构建目录。
#--check-build-system CMakeFiles/Makefile.cmake 0 选项
#指定了要检查的构建系统文件(CMakeFiles/Makefile.cmake)和检查模式(0)。
cmake_check_build_system:
	$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system

																																																																																																																																																																																																																																																																																																																																																											

makefile2是子文件夹中的makefile文件,$(MAKE) -f CMakeFiles/Makefile2 all, -f 参数使得读取子目录的makefile文件名字不一定要是makefile。同时all参数,说明是执行makefile2中的target all

# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.16

# Default target executed when no arguments are given to make.
default_target: all

.PHONY : default_target

#=============================================================================
# Special targets provided by cmake.

# Disable implicit rules so canonical targets will work.
.SUFFIXES:


# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =

.SUFFIXES: .hpux_make_needs_suffix_list


# Suppress display of executed commands.
$(VERBOSE).SILENT:


# A target that is always out of date.
cmake_force:

.PHONY : cmake_force

#=============================================================================
# Set environment variables for the build.

# The shell in which to execute make rules.
SHELL = /bin/sh

# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake

# The command to remove a file.
RM = /usr/bin/cmake -E remove -f

# Escaping for special characters.
EQUALS = =

# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /home/lho/perception/yolov8_onnx

# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /home/lho/perception/yolov8_onnx/build

#=============================================================================
# Directory level rules for the build root directory

#生成下面的目标,all 是一个伪目标, CMakeFiles/yolov8_onnx.dir/all,CMakeFiles/yolov5_seg_onnx.dir/all
#CMakeFiles/yolov5_seg_utils.dir/all 是它的dependencies
# The main recursive "all" target.
all: CMakeFiles/yolov8_onnx.dir/all
all: CMakeFiles/yolov5_seg_onnx.dir/all
all: CMakeFiles/yolov5_seg_utils.dir/all

.PHONY : all

# The main recursive "preinstall" target.
preinstall:

.PHONY : preinstall

# The main recursive "clean" target.
clean: CMakeFiles/yolov8_onnx.dir/clean
clean: CMakeFiles/yolov5_seg_onnx.dir/clean
clean: CMakeFiles/yolov5_seg_utils.dir/clean

.PHONY : clean

#=============================================================================
# Target rules for target CMakeFiles/yolov8_onnx.dir

#CMakeFiles/yolov8_onnx.dir/all也是一个伪目标
#它的dependencies有CMakeFiles/yolov5_seg_onnx.dir/all,CMakeFiles/yolov5_seg_utils.dir/all
#当CMakeFiles/yolov5_seg_utils.dir/all存在时,就会执行后面的命令

# All Build rule for target.
CMakeFiles/yolov8_onnx.dir/all: CMakeFiles/yolov5_seg_onnx.dir/all
CMakeFiles/yolov8_onnx.dir/all: CMakeFiles/yolov5_seg_utils.dir/all

#$(MAKE) -f CMakeFiles/yolov8_onnx.dir/build.make CMakeFiles/yolov8_onnx.dir/depend
#$(MAKE) -f CMakeFiles/yolov8_onnx.dir/build.make CMakeFiles/yolov8_onnx.dir/build
#进入到下级目录中生成下级目录depend.make中的target CMakeFiles/yolov8_onnx.dir/depend和CMakeFiles/yolov8_onnx.dir/build

	$(MAKE) -f CMakeFiles/yolov8_onnx.dir/build.make CMakeFiles/yolov8_onnx.dir/depend
	$(MAKE) -f CMakeFiles/yolov8_onnx.dir/build.make CMakeFiles/yolov8_onnx.dir/build
	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --progress-dir=/home/lho/perception/yolov8_onnx/build/CMakeFiles --progress-num=5,6 "Built target yolov8_onnx"
.PHONY : CMakeFiles/yolov8_onnx.dir/all

# Build rule for subdir invocation for target.
CMakeFiles/yolov8_onnx.dir/rule: cmake_check_build_system
	$(CMAKE_COMMAND) -E cmake_progress_start /home/lho/perception/yolov8_onnx/build/CMakeFiles 6
	$(MAKE) -f CMakeFiles/Makefile2 CMakeFiles/yolov8_onnx.dir/all
	$(CMAKE_COMMAND) -E cmake_progress_start /home/lho/perception/yolov8_onnx/build/CMakeFiles 0
.PHONY : CMakeFiles/yolov8_onnx.dir/rule

# Convenience name for target.
yolov8_onnx: CMakeFiles/yolov8_onnx.dir/rule

.PHONY : yolov8_onnx

# clean rule for target.
CMakeFiles/yolov8_onnx.dir/clean:
	$(MAKE) -f CMakeFiles/yolov8_onnx.dir/build.make CMakeFiles/yolov8_onnx.dir/clean
.PHONY : CMakeFiles/yolov8_onnx.dir/clean

#=============================================================================
# Target rules for target CMakeFiles/yolov5_seg_onnx.dir

# All Build rule for target.
CMakeFiles/yolov5_seg_onnx.dir/all: CMakeFiles/yolov5_seg_utils.dir/all
	$(MAKE) -f CMakeFiles/yolov5_seg_onnx.dir/build.make CMakeFiles/yolov5_seg_onnx.dir/depend
	$(MAKE) -f CMakeFiles/yolov5_seg_onnx.dir/build.make CMakeFiles/yolov5_seg_onnx.dir/build
	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --progress-dir=/home/lho/perception/yolov8_onnx/build/CMakeFiles --progress-num=1,2 "Built target yolov5_seg_onnx"
.PHONY : CMakeFiles/yolov5_seg_onnx.dir/all

# Build rule for subdir invocation for target.
CMakeFiles/yolov5_seg_onnx.dir/rule: cmake_check_build_system
	$(CMAKE_COMMAND) -E cmake_progress_start /home/lho/perception/yolov8_onnx/build/CMakeFiles 4
	$(MAKE) -f CMakeFiles/Makefile2 CMakeFiles/yolov5_seg_onnx.dir/all
	$(CMAKE_COMMAND) -E cmake_progress_start /home/lho/perception/yolov8_onnx/build/CMakeFiles 0
.PHONY : CMakeFiles/yolov5_seg_onnx.dir/rule

# Convenience name for target.
yolov5_seg_onnx: CMakeFiles/yolov5_seg_onnx.dir/rule

.PHONY : yolov5_seg_onnx

# clean rule for target.
CMakeFiles/yolov5_seg_onnx.dir/clean:
	$(MAKE) -f CMakeFiles/yolov5_seg_onnx.dir/build.make CMakeFiles/yolov5_seg_onnx.dir/clean
.PHONY : CMakeFiles/yolov5_seg_onnx.dir/clean

#=============================================================================
# Target rules for target CMakeFiles/yolov5_seg_utils.dir

# All Build rule for target.
CMakeFiles/yolov5_seg_utils.dir/all:
	$(MAKE) -f CMakeFiles/yolov5_seg_utils.dir/build.make CMakeFiles/yolov5_seg_utils.dir/depend
	$(MAKE) -f CMakeFiles/yolov5_seg_utils.dir/build.make CMakeFiles/yolov5_seg_utils.dir/build
	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --progress-dir=/home/lho/perception/yolov8_onnx/build/CMakeFiles --progress-num=3,4 "Built target yolov5_seg_utils"
.PHONY : CMakeFiles/yolov5_seg_utils.dir/all

# Build rule for subdir invocation for target.
CMakeFiles/yolov5_seg_utils.dir/rule: cmake_check_build_system
	$(CMAKE_COMMAND) -E cmake_progress_start /home/lho/perception/yolov8_onnx/build/CMakeFiles 2
	$(MAKE) -f CMakeFiles/Makefile2 CMakeFiles/yolov5_seg_utils.dir/all
	$(CMAKE_COMMAND) -E cmake_progress_start /home/lho/perception/yolov8_onnx/build/CMakeFiles 0
.PHONY : CMakeFiles/yolov5_seg_utils.dir/rule

# Convenience name for target.
yolov5_seg_utils: CMakeFiles/yolov5_seg_utils.dir/rule

.PHONY : yolov5_seg_utils

# clean rule for target.
CMakeFiles/yolov5_seg_utils.dir/clean:
	$(MAKE) -f CMakeFiles/yolov5_seg_utils.dir/build.make CMakeFiles/yolov5_seg_utils.dir/clean
.PHONY : CMakeFiles/yolov5_seg_utils.dir/clean

#=============================================================================
# Special targets to cleanup operation of make.

# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
	$(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system

根据makefile2进入到下级目录中的build.make,
$(MAKE) -f CMakeFiles/yolov8_onnx.dir/build.make CMakeFiles/yolov8_onnx.dir/depend
$(MAKE) -f CMakeFiles/yolov8_onnx.dir/build.make CMakeFiles/yolov8_onnx.dir/build
然后找到其中target CMakeFiles/yolov8_onnx.dir/depend和CMakeFiles/yolov8_onnx.dir/build

# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.16

# Delete rule output on recipe failure.
.DELETE_ON_ERROR:


#=============================================================================
# Special targets provided by cmake.

# Disable implicit rules so canonical targets will work.
.SUFFIXES:
这是一个 CMake 命令,它使用 $(CMAKE_COMMAND) 变量指定的 CMake 可执行文件来检查构建系统。-S$(CMAKE_SOURCE_DIR) 和 -B$(CMAKE_BINARY_DIR) 选项分别指定了源目录和构建目录。--check-build-system CMakeFiles/Makefile.cmake 0 选项指定了要检查的构建系统文件(CMakeFiles/Makefile.cmake)和检查模式(0)。

# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =

.SUFFIXES: .hpux_make_needs_suffix_list


# Suppress display of executed commands.
$(VERBOSE).SILENT:


# A target that is always out of date.
cmake_force:

.PHONY : cmake_force

#=============================================================================
# Set environment variables for the build.

# The shell in which to execute make rules.
SHELL = /bin/sh

# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake

# The command to remove a file.
RM = /usr/bin/cmake -E remove -f

# Escaping for special characters.
EQUALS = =

# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /home/lho/perception/yolov8_onnx

# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /home/lho/perception/yolov8_onnx/build

# Include any dependencies generated for this target.
include CMakeFiles/yolov8_onnx.dir/depend.make

# Include the progress variables for this target.
include CMakeFiles/yolov8_onnx.dir/progress.make

# Include the compile flags for this target's objects.
include CMakeFiles/yolov8_onnx.dir/flags.make

CMakeFiles/yolov8_onnx.dir/src/main.o: CMakeFiles/yolov8_onnx.dir/flags.make
CMakeFiles/yolov8_onnx.dir/src/main.o: ../src/main.cpp
	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/home/lho/perception/yolov8_onnx/build/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Building CXX object CMakeFiles/yolov8_onnx.dir/src/main.o"
	/usr/bin/c++  $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -o CMakeFiles/yolov8_onnx.dir/src/main.o -c /home/lho/perception/yolov8_onnx/src/main.cpp

CMakeFiles/yolov8_onnx.dir/src/main.i: cmake_force
	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing CXX source to CMakeFiles/yolov8_onnx.dir/src/main.i"
	/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /home/lho/perception/yolov8_onnx/src/main.cpp > CMakeFiles/yolov8_onnx.dir/src/main.i

CMakeFiles/yolov8_onnx.dir/src/main.s: cmake_force
	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling CXX source to assembly CMakeFiles/yolov8_onnx.dir/src/main.s"
	/usr/bin/c++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /home/lho/perception/yolov8_onnx/src/main.cpp -o CMakeFiles/yolov8_onnx.dir/src/main.s

# Object files for target yolov8_onnx
yolov8_onnx_OBJECTS = \
"CMakeFiles/yolov8_onnx.dir/src/main.o"

# External object files for target yolov8_onnx
yolov8_onnx_EXTERNAL_OBJECTS =

#target yolov8_onnx 后面是它的dependencies
#当dependencies都存在时,就会执行下面两行command,
#	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --bold --progress-dir=/home/lho/perception/yolov8_onnx/build/CMakeFiles --progress-num=$(CMAKE_PROGRESS_2) "Linking CXX executable yolov8_onnx"
	#$(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/yolov8_onnx.dir/link.txt --verbose=$(VERBOSE)
#其中$(CMAKE_COMMAND) -E cmake_link_script 就是以命令行的方式执行 cmake_link_script,根据链接文件链接库

yolov8_onnx: CMakeFiles/yolov8_onnx.dir/src/main.o
yolov8_onnx: CMakeFiles/yolov8_onnx.dir/build.make
yolov8_onnx: /usr/local/opencv451/lib/libopencv_gapi.so.4.5.1
yolov8_onnx: /usr/local/opencv451/lib/libopencv_highgui.so.4.5.1
yolov8_onnx: /usr/local/opencv451/lib/libopencv_ml.so.4.5.1
yolov8_onnx: /usr/local/opencv451/lib/libopencv_objdetect.so.4.5.1
yolov8_onnx: /usr/local/opencv451/lib/libopencv_photo.so.4.5.1
yolov8_onnx: /usr/local/opencv451/lib/libopencv_stitching.so.4.5.1
yolov8_onnx: /usr/local/opencv451/lib/libopencv_video.so.4.5.1
yolov8_onnx: /usr/local/opencv451/lib/libopencv_videoio.so.4.5.1
yolov8_onnx: libyolov5_seg_onnx.so
yolov8_onnx: libyolov5_seg_utils.so
yolov8_onnx: /usr/local/opencv451/lib/libopencv_dnn.so.4.5.1
yolov8_onnx: /usr/local/opencv451/lib/libopencv_imgcodecs.so.4.5.1
yolov8_onnx: /usr/local/opencv451/lib/libopencv_calib3d.so.4.5.1
yolov8_onnx: /usr/local/opencv451/lib/libopencv_features2d.so.4.5.1
yolov8_onnx: /usr/local/opencv451/lib/libopencv_flann.so.4.5.1
yolov8_onnx: /usr/local/opencv451/lib/libopencv_imgproc.so.4.5.1
yolov8_onnx: /usr/local/opencv451/lib/libopencv_core.so.4.5.1
yolov8_onnx: CMakeFiles/yolov8_onnx.dir/link.txt
	@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --bold --progress-dir=/home/lho/perception/yolov8_onnx/build/CMakeFiles --progress-num=$(CMAKE_PROGRESS_2) "Linking CXX executable yolov8_onnx"
	$(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/yolov8_onnx.dir/link.txt --verbose=$(VERBOSE)

#target CMakeFiles/yolov8_onnx.dir/build  它的dependencies是 yolov8_onnx
# Rule to build all files generated by this target.
CMakeFiles/yolov8_onnx.dir/build: yolov8_onnx

.PHONY : CMakeFiles/yolov8_onnx.dir/build

CMakeFiles/yolov8_onnx.dir/clean:
	$(CMAKE_COMMAND) -P CMakeFiles/yolov8_onnx.dir/cmake_clean.cmake
.PHONY : CMakeFiles/yolov8_onnx.dir/clean

#target CMakeFiles/yolov8_onnx.dir/depend: 它没有dependencies
#这是一个 shell 命令,它首先更改当前目录到 /home/lho/vscode/C/build,
#然后使用 $(CMAKE_COMMAND) 变量指定的 CMake 可执行文件来计算依赖关系。
#-E cmake_depends 选项指定了要执行的命令(计算依赖关系),
#"Unix Makefiles" 指定了构建系统类型。
#接下来的四个参数分别指定了源目录、二进制目录、依赖信息文件和颜色选项。这个命令用于在构建过程中计算目标文件之间的依赖关系。
CMakeFiles/yolov8_onnx.dir/depend:
	cd /home/lho/perception/yolov8_onnx/build && $(CMAKE_COMMAND) 
	-E cmake_depends "Unix Makefiles" /home/lho/perception/yolov8_onnx /home/lho/perception/yolov8_onnx /home/lho/perception/yolov8_onnx/build 
	/home/lho/perception/yolov8_onnx/build 
	/home/lho/perception/yolov8_onnx/build/CMakeFiles/yolov8_onnx.dir/DependInfo.cmake --color=$(COLOR)
.PHONY : CMakeFiles/yolov8_onnx.dir/depend

link.txt文件如下,这是一个链接命令,它使用 /usr/bin/c++ 编译器将 CMakeFiles/yolov8_onnx.dir/src/main.o 文件链接到可执行文件 yolov8_onnx。该命令指定了多个库目录(-L 选项)和运行时库搜索路径(-Wl,-rpath 选项),并链接了多个库(以 .so 结尾的文件)。例如,它链接了 OpenCV 库(如 libopencv_gapi.so.4.5.1)和 onnxruntime 库(-lonnxruntime)。

/usr/bin/c++    -rdynamic CMakeFiles/yolov8_onnx.dir/src/main.o  -o yolov8_onnx   -L/usr/local/lib  -L/usr/local/opencv451/lib  -L/home/lho/perception/yolov8_onnx/build  -Wl,-rpath,/usr/local/lib:/usr/local/opencv451/lib:/home/lho/perception/yolov8_onnx/build /usr/local/opencv451/lib/libopencv_gapi.so.4.5.1 /usr/local/opencv451/lib/libopencv_highgui.so.4.5.1 /usr/local/opencv451/lib/libopencv_ml.so.4.5.1 /usr/local/opencv451/lib/libopencv_objdetect.so.4.5.1 /usr/local/opencv451/lib/libopencv_photo.so.4.5.1 /usr/local/opencv451/lib/libopencv_stitching.so.4.5.1 /usr/local/opencv451/lib/libopencv_video.so.4.5.1 /usr/local/opencv451/lib/libopencv_videoio.so.4.5.1 -lonnxruntime libyolov5_seg_onnx.so libyolov5_seg_utils.so /usr/local/opencv451/lib/libopencv_dnn.so.4.5.1 /usr/local/opencv451/lib/libopencv_imgcodecs.so.4.5.1 /usr/local/opencv451/lib/libopencv_calib3d.so.4.5.1 /usr/local/opencv451/lib/libopencv_features2d.so.4.5.1 /usr/local/opencv451/lib/libopencv_flann.so.4.5.1 /usr/local/opencv451/lib/libopencv_imgproc.so.4.5.1 /usr/local/opencv451/lib/libopencv_core.so.4.5.1 

所以读取makefile文件的流程就是,先找到最顶层的makefile文件。如果是默认make,就找它的第一个target, 然后根据第一个target 的dependencies依次递推。makefile文件也不一定名字都叫makefile,也有可能是 .cmake或者 .make文件。总之,如果要写大型工程,makefile文件不一定要会写,但是一定要看懂,这样第三库复杂且多时,才能追根溯源找到bug。

cmake_check_build_system

cmake基本用法

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值