Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

中文注解 #88

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
aa094ee
Update README.adoc
jianage Sep 14, 2022
b4cdf7a
Update README.adoc
jianage Sep 14, 2022
92a0ec6
Update README.adoc
jianage Sep 14, 2022
61dd034
Update README.adoc
jianage Sep 14, 2022
97f7b67
Update README.adoc
jianage Sep 15, 2022
b90ebb9
Update README.adoc
jianage Sep 15, 2022
30fb78a
Update README.adoc
jianage Sep 15, 2022
70102ea
Update README.adoc
jianage Sep 15, 2022
402bdd8
Update README.adoc
jianage Sep 15, 2022
219001e
Update README.adoc
jianage Sep 15, 2022
13e2285
Update README.adoc
jianage Sep 15, 2022
2e46dd6
Update README.adoc
jianage Sep 16, 2022
fe65e58
Update README.adoc
jianage Sep 16, 2022
25caa32
Update README.adoc
jianage Sep 16, 2022
d36b1b1
Update README.adoc
jianage Sep 16, 2022
61b9618
Update README.adoc
jianage Sep 16, 2022
31e3a67
Update README.adoc
jianage Sep 16, 2022
5d58948
Update README.adoc
jianage Sep 16, 2022
a24b7d9
Update README.adoc
jianage Sep 16, 2022
5e153d5
Update README.adoc
jianage Sep 16, 2022
9ea4d0b
Update README.adoc
jianage Sep 16, 2022
fd9ebf9
Update README.adoc
jianage Sep 16, 2022
d0628ba
Update README.adoc
jianage Sep 17, 2022
40dfcb4
Update README.adoc
jianage Sep 17, 2022
2efb732
Update README.adoc
jianage Sep 17, 2022
aee8897
Update README.adoc
jianage Sep 17, 2022
2990bff
Update README.adoc
jianage Sep 17, 2022
9abf067
Update README.adoc
jianage Sep 17, 2022
e404d37
Update README.adoc
jianage Sep 17, 2022
003c193
Update README.adoc
jianage Sep 17, 2022
a140fb1
Update README.adoc
jianage Sep 17, 2022
f517f0d
Merge pull request #1 from jianage/my_note
jianage Sep 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion 01-basic/A-hello-cmake/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ cmake_minimum_required(VERSION 3.5)

A CMake build can include a project name to make referencing certain
variables easier when using multiple projects.
(**CMake构建可以包含一个项目名称,以确保使用多个项目时,引用变量更容易**)

[source,cmake]
----
Expand All @@ -56,6 +57,7 @@ The +add_executable()+ command specifies that an executable should be
build from the specified source files, in this example main.cpp. The
first argument to the +add_executable()+ function is the name of the
executable to be built, and the second argument is the list of source files to compile.
(**这将创建一个可执行程序,但不一定需要与项目同名**)

[source,cmake]
----
Expand Down Expand Up @@ -88,6 +90,8 @@ The root or top level folder that you run the cmake command from is known as you
CMAKE_BINARY_DIR and is the root folder for all your binary files.
CMake supports building and generating your binary files both in-place and also
out-of-source.
(**CMAKE_BINARY_DIR,为运行cmake命令的工作目录,是二进制目标文件的根文件目录,即二进制中间目标文件存放位置的顶级目录**)
(**cmake支持在本地或源文件之外,构建您的二进制文件**)


#### In-Place Build
Expand Down Expand Up @@ -153,7 +157,7 @@ A-hello-cmake$ tree
----


#### Out-of-Source Build
#### Out-of-Source Build(**推荐**)

Out-of-source builds allow you to create a single build folder that can be anywhere on
your file system. All temporary build and object files are located in this directory keeping
Expand Down
16 changes: 9 additions & 7 deletions 01-basic/B-hello-headers/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ Some of these include:
[cols=",",options="header",]
|=======================================================================
|Variable |Info
|CMAKE_SOURCE_DIR |The root source directory
|CMAKE_SOURCE_DIR |The root source directory(最外层CMakeLists.txt所在目录)

|CMAKE_CURRENT_SOURCE_DIR |The current source directory if using
sub-projects and directories.
sub-projects and directories.(当前处理的CMakeLists.txt所在的目录)

|PROJECT_SOURCE_DIR |The source directory of the current cmake project.
|PROJECT_SOURCE_DIR |The source directory of the current cmake project.(包含PROJECT()命令的最近一个CMakeLists.txt所在文件夹路径)

|CMAKE_BINARY_DIR |The root binary / build directory. This is the
directory where you ran the cmake command.
directory where you ran the cmake command.(二进制文件所在的根目录)

|CMAKE_CURRENT_BINARY_DIR |The build directory you are currently in.
|CMAKE_CURRENT_BINARY_DIR |The build directory you are currently in.(当前正在处理的二进制目录路径)

|PROJECT_BINARY_DIR |The build directory for the current project.
|PROJECT_BINARY_DIR |The build directory for the current project.(当前工程所创建的build目录)
|=======================================================================

## Source Files Variable
## Source Files Variable(给需要多个一起编译的源文件设置一个统一变量名)

Creating a variable which includes the source files allows you to be
clearer about these files and easily add them to multiple commands, for example,
Expand Down Expand Up @@ -98,6 +98,8 @@ correct results if you add a new source file.
When you have different include folders, you can make your compiler aware of them using the
+target_include_directories()+ link:https://cmake.org/cmake/help/v3.0/command/target_include_directories.html[function]. When compiling this target this will add these directories to the compiler with the -I flag e.g. `-I/directory/path`

(*编译此目标时,将把该目录添加到编译器中,故这里的target应该指的是可执行程序,而目录指的是头文件所在目录*)

[source,cmake]
----
target_include_directories(target
Expand Down
22 changes: 18 additions & 4 deletions 01-basic/C-static-library/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ $ tree

# Concepts

## Adding a Static Library
## Adding a Static Library(创建一个静态库)

The +add_library()+ function is used to create a library from some source files.
This is called as follows:

(*使用关键字STATIC-静态,这里的target为hello_library,不必与工程同名,只是声明一个静态库target名,这将创建一个名为libhello_library.a的静态库(在二进制文件目录下)*)

(*使用的源文件目录,默认以CMakeLists.txt所在目录为起点*)

[source,cmake]
----
add_library(hello_library STATIC
Expand All @@ -57,6 +61,12 @@ As mentioned in the previous example, we pass the source files directly to the

In this example, we include directories in the library using the +target_include_directories()+ function with the scope set to +PUBLIC+.

(*这里的target目标,为hello_library,其实是库target名*)

(*为target包含的目录为~/include,所以库的源文件只需#include "static/Hello.h"(这就是target's include directory),而不需使用绝对路径*)

(*这里的范围属性scope,设置成PUBIC,表示当编译这个target或连接link了这个target的其他target时,将该目录添加到target或连接了该target的其他target的包含目录中,所以这也是为什么连接了库的源文件只需#include "static/Hello.h"*)

[source,cmake]
----
target_include_directories(hello_library
Expand All @@ -72,9 +82,9 @@ This will cause the included directory used in the following places:

The meaning of scopes are:

* +PRIVATE+ - the directory is added to this target's include directories
* +INTERFACE+ - the directory is added to the include directories for any targets that link this library.
* +PUBLIC+ - As above, it is included in this library and also any targets that link this library.
* +PRIVATE+ - the directory is added to this target's include directories(将目录添加到该target的包含目录中)
* +INTERFACE+ - the directory is added to the include directories for any targets that link this library.(该目录将添加到连接此target的任何其他target的包含目录中,不包括本target)
* +PUBLIC+ - As above, it is included in this library and also any targets that link this library.(如上所述,它包括在此target中,也包括连接此target的任何其他target)


[TIP]
Expand All @@ -100,6 +110,10 @@ you use multiple libraries in your project.
When creating an executable that will use your library you must tell the compiler
about the library. This can be done using the +target_link_libraries()+ function.

(*创建可执行文件,之传递了一个main.cpp,我们还需建可执行文件与库连接起来,我们使用target_link_libraries函数来告诉编译器*)

(*这里只需将范围属性设置成PRIVATE*)

[source,cmake]
----
add_executable(hello_binary
Expand Down
10 changes: 9 additions & 1 deletion 01-basic/D-shared-library/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ $ tree

# Concepts

## Adding a Shared Library
## Adding a Shared Library(创建一个动态库)

As with the previous example on static libraries, the +add_library()+ function
is also used to create a shared library from some source files.
This is called as follows:

(*使用关键自SHARED-动态,这将创建一个名为libhello_library.so的动态库文件*)

[source,cmake]
----
add_library(hello_library SHARED
Expand All @@ -59,6 +61,12 @@ add_library(hello::library ALIAS hello_library)

As shown below, this allows you to reference the target using the alias name when linking it against other targets.

## 添加包含目录

----
target_include_directories(hello_library PUBLIC {PROJECT_SOURCE_DIR}/include)
----

## Linking a Shared Library

Linking a shared library is the same as linking a static library. When creating your
Expand Down
17 changes: 15 additions & 2 deletions 01-basic/F-build-type/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,25 @@ CMake has a number of built in build configurations which can be used to compile
your project. These specify the optimization levels and if debug information is
to be included in the binary.

(*CMake中有许多内置的构建配置,用来编译你的工程project。它们指定了优化级别以及是否将调试信息包含在二进制文件中*)

The levels provided are:

* Release - Adds the `-O3 -DNDEBUG` flags to the compiler

(*发行版,顾名思义,程序完成开发后的发布版本,对代码做了优化,速度快,但无法跟踪代码,不能打断点调试*)

* Debug - Adds the `-g` flag

(*调试版,即对代码不做任何优化,但可以调试项目中的任意文件。速度相对较慢、体积也更大*)

* MinSizeRel - Adds `-Os -DNDEBUG`

(*Release的近似版,代码也同样记过优化,但同时也支持添加断点进行调试*)

* RelWithDebInfo - Adds `-O2 -g -DNDEBUG` flags

(最小体积版本,与Release版近似,但更偏重于优化文件大小,而非运行速度)

The files in this tutorial are below:

Expand All @@ -31,11 +44,11 @@ $ tree

# Concepts

## Set Build Type
## Set Build Type (构建类型)

The build type can be set using the following methods.

- Using a gui tool such as ccmake / cmake-gui
- Using a gui tool such as ccmake / cmake-gui (CMake图形界面)

image::cmake-gui-build-type.png[cmake-gui build type]

Expand Down
2 changes: 2 additions & 0 deletions 01-basic/G-compile-flags/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ toc::[]

# Introduction

(*compile flags——编译标志。可执行文件的生成离不开编译,那么如何编译,如使用C++或C的那个版本?这就要用到编译标志了*)

CMake supports setting compile flags in a number of different ways:

* using +target_compile_definitions()+ function
Expand Down
37 changes: 32 additions & 5 deletions 01-basic/H-third-party-library/README.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
= Including Third Party Library
= Including Third Party Library(包含第三方库)
:toc:
:toc-placement!:

Expand All @@ -13,6 +13,14 @@ the `find_package()` function. This will search for CMake modules in the format
default search path will include `/usr/share/cmake/Modules`. On my system this
includes support for approximately 142 common third party libraries.

(*几乎所有非平凡的项目都要求包含第三方库、头文件或程序。CMake支持使用find_package()函数(间接)查找这些工具的路径*)

(*这将从CMAKE_MODULE_PATH中的文件夹列表搜索格式为FindXXX.cmake的CMake模块,如果没找到将会查找XXXConfig.cmake或XXX-config.cmake,在这些格式的文件里定义了许多变量,用于指定要包含的库和头文件的路径*)

(*CMAKE_MODULE_PATH指定的默认路径为/usr/share/cmake-<version>/Modules;在我的系统中,包含对大约142个通用第三方库的支持*)

(*find_package()支持两种模式,一是Module模式,二是Config模式;如果Module模式搜索失败,则会转入Config模式,搜索路径是/usr/local/lib/cmake/<libraryname>(find_package的搜索路径是一系列的集合)*)


The files in this tutorial are below:

Expand Down Expand Up @@ -40,6 +48,8 @@ As mentioned above the `find_package()` function will search for CMake modules i
format of the arguments to `find_package` will depend on the module you are looking
for. This is typically documented at the top of the `FindXXX.cmake` file.

(*find_package()参数的确切格式取决于要查找的模块,这通常记录在FindXXX.cmake文件的顶部*)

A basic example of finding boost is below:

[source,cmake]
Expand All @@ -49,10 +59,21 @@ find_package(Boost 1.46.1 REQUIRED COMPONENTS filesystem system)

The arguments are:

* Boost - Name of the library. This is part of used to find the module file FindBoost.cmake
* Boost - Name of the library. This is part of used to find the module file FindBoost.cmake(是用于查找模块文件FindBoost.cmake的一部分)

*Boost库是为C++语言标准库提供扩展的一些程序库的总称,由Boost社区组织开发、维护。Boost库可以与C++标准库完美共同工作,并为其提供扩展功能*

* 1.46.1 - The minimum version of boost to find

*需要的boost库的最低版本*

* REQUIRED - Tells the module that this is required and to fail if it cannot be found

*告诉模块这是必须的,如果找不到会报错*

* COMPONENTS - The list of components to find in the library.

*在Boost中要找的部分*

Boost includes can take more arguments and also make use of other variables.
More complex setups are provided in later examples.
Expand All @@ -63,6 +84,8 @@ More complex setups are provided in later examples.
Most included packages will set a variable `XXX_FOUND`, which can be used to check
if the package is available on the system.

(*大多数被包含(被找到)的包将设置变量XXX_FOUND,用于检查软件包在系统上是否可用*)

In this example the variable is `Boost_FOUND`:

[source,cmake]
Expand All @@ -75,25 +98,29 @@ else()
endif()
----

## Exported Variables
## Exported Variables(导出变量)

After a package is found it will often export variables which can inform the user
where to find the library, header, or executable files. Similar to the `XXX_FOUND`
variable, these are package specific and are typically documented at the top of the
`FindXXX.cmake` file.

(*找到包后,将自动导出变量,这些变量通常记录在FindXXX.cmake文件的顶部。这些变量可以通知用户在哪里可以找到库、头文件或可执行文件*)

The variables exported in this example include:

* `Boost_INCLUDE_DIRS` - The path to the boost header files.

In some cases you can also check these variables by examining the cache using
ccmake or cmake-gui.

## Alias / Imported targets
## Alias / Imported targets(别名/导入目标)

Most modern CMake libraries link:https://cmake.org/cmake/help/v3.6/prop_tgt/IMPORTED.html#prop_tgt:IMPORTED[export] +ALIAS+ targets in their module files.
The benefit of imported targets are that they can also populate include directories and linked libraries.

(*大多数现代CMake库在其模块文件(FindXXX.cmake)导出别名目标。导入目标的好处是它们也可以填充包含目录和链接的库。*)

For example, starting from v3.5+ of CMake, the
Boost module supports this. Similar to using your own ALIAS target for libraires, an +ALIAS+ in a module can make referencing found targets easier.

Expand All @@ -104,7 +131,7 @@ of the subsystem. For example you can use:
* `Boost::system` for the boost system library.
* `Boost::filesystem` for filesystem library.

As with your own targets, these targets include their dependencies, so linking against
As with your own targets, these targets include their dependencies(依赖关系), so linking against
`Boost::filesystem` will automatically add `Boost::boost` and `Boost::system` dependencies.

To link against an imported target you can use the following:
Expand Down
2 changes: 2 additions & 0 deletions 01-basic/I-compiling-with-clang/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ When building with CMake it is possible to set the C and C++ compiler. This exam
is the same as the link:../A-hello-cmake[hello-cmake] example except that it shows the most basic
method of changing the compiler from the default gcc to http://clang.llvm.org/[clang].

(*以下介绍了将编译器从默认的gcc更改为clang的最基本的方式*)

The files in this tutorial are below:

```
Expand Down
12 changes: 11 additions & 1 deletion 01-basic/J-building-with-ninja/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ $ tree

# Concepts

### Generators
### Generators(生成器)

CMake https://cmake.org/cmake/help/v3.0/manual/cmake-generators.7.html[generators] are
responsible for writing the input files (e.g. Makefiles) for the underlying build system. Running `cmake --help`
will show the generators available. For cmake v2.8.12.2 the generators supported
on my system include:

(*CMake生成器就是通过CMakelists.txt文件生成适用于不同项目类型的makefile文件,然后makefile文件被不同的编译器使用进行编译*)

(*当然C/C++有许多开发环境,故也有多种生成器*)

[source,bash]
----
Generators
Expand All @@ -57,6 +61,8 @@ CMake includes different types of generators such as Command-Line, IDE, and Extr

These generators are for command-line build tools, like Make and Ninja. The chosen tool chain must be configured prior to generating the build system with CMake.

(*这些生成器用于命令行构建工具。在使用CMake生成构建系统之前,须配置所选的工具链*)

The supported generators include:

* Borland Makefiles
Expand All @@ -72,6 +78,8 @@ The supported generators include:

These generators are for Integrated Development Environments that include their own compiler. Examples are Visual Studio and Xcode which include a compiler natively.

(*这些生成器用于含有自己的编译器的IDE(集成开发环境),不需自己配置工具链*)

The supported generators include:

* Visual Studio 6
Expand All @@ -88,6 +96,8 @@ The supported generators include:

These are generators create a configuration to work with an alternative IDE tool and must be included with either an IDE or Command-Line generator.

(*这些生成器创建一个配置来使用一个可选的IDE工具,并且必须包含在IDE或命令行生成器中。 *)

The supported generators include:

* CodeBlocks
Expand Down