Running CMake {运行 CMake}
- 1. CLion - Create a new CMake project
- 2. Running CMake (运行 CMake)
- 2.1. Building a project (构建项目)
- 2.2. Picking a compiler (指定编译器)
- 2.3. Verbose and partial builds (详细和部分的构建)
- 2.4. Options (选项)
- 2.4.1. Standard options (标准选项)
- 2.5. Debugging your CMake files (调试你的 CMake 文件)
- 2.6. Setting options (设置选项)
- 2.7. Picking a generator (指定生成器)
- References
1. CLion - Create a new CMake project
- Welcome to CLion
- New Project
/home/yongqiang/CLionProjects/yongqiang/
- Open Project Wizard
- Theme: Intellij Light
File -> Settings -> Appearance & Behavior -> Appearance
Classic UI
- main.cpp
/home/yongqiang/CLionProjects/yongqiang/main.cpp
#include <iostream>
int main() {
std::cout << "Hello, World!" << std::endl;
return 0;
}
- CMakeLists.txt
/home/yongqiang/CLionProjects/yongqiang/CMakeLists.txt
cmake_minimum_required(VERSION 3.22)
project(yongqiang)
set(CMAKE_CXX_STANDARD 14)
add_executable(yongqiang main.cpp)
- Build
- Run
2. Running CMake (运行 CMake)
https://cliutils.gitlab.io/modern-cmake/chapters/intro/running.html
https://modern-cmake-cn.github.io/Modern-CMake-zh_CN/chapters/intro/running.html
2.1. Building a project (构建项目)
Unless otherwise noted, you should always make a build directory and build from there.
除非另行说明,你始终应该建立一个专用于构建的目录并在那里构建项目。
You can technically do an in-source build, but you’ll have to be careful not to overwrite files or add them to git, so just don’t.
从技术上来讲,你可以在源代码目录下执行 CMake 构建命令,但是必须注意不要覆盖文件或者把它们添加到 git,所以别这么做就好。
Here’s the Classic CMake Build Procedure (经典的 CMake 构建流程):
~/package $ mkdir build
~/package $ cd build
~/package/build $ cmake ..
~/package/build $ make
(base) yongqiang@yongqiang:~$ cd CLionProjects/
(base) yongqiang@yongqiang:~/CLionProjects$ ls
yongqiang
(base) yongqiang@yongqiang:~/CLionProjects$ cd yongqiang/
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ ls
CMakeLists.txt cmake-build-debug main.cpp
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ mkdir build
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ cd build
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$ cmake ..
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (7.3s)
-- Generating done (0.0s)
-- Build files have been written to: /home/yongqiang/CLionProjects/yongqiang/build
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$ make
[ 50%] Building CXX object CMakeFiles/yongqiang.dir/main.cpp.o
[100%] Linking CXX executable yongqiang
[100%] Built target yongqiang
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$ ls
CMakeCache.txt CMakeFiles Makefile cmake_install.cmake yongqiang
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$ ./yongqiang
Hello, World!
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$
You can replace the make line with cmake --build .
if you’d like, and it will call make
or whatever build tool you are using.
你可以用 cmake --build .
替换 make
这一行。它会调用 make
或者任何你正在使用的构建工具。
~/package $ mkdir build
~/package $ cd build
~/package/build $ cmake ..
~/package/build $ cmake --build .
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ ls
CMakeLists.txt cmake-build-debug main.cpp
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ mkdir build
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ cd build
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$ cmake ..
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (4.9s)
-- Generating done (0.0s)
-- Build files have been written to: /home/yongqiang/CLionProjects/yongqiang/build
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$ cmake --build .
[ 50%] Building CXX object CMakeFiles/yongqiang.dir/main.cpp.o
[100%] Linking CXX executable yongqiang
[100%] Built target yongqiang
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$ ./yongqiang
Hello, World!
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$
If you are using a newer version of CMake (which you usually should be, except for checking compatibility with older CMake), you can instead do this.
如果你正在使用版本比较新的 CMake (除非你正在检查对于老版本 CMake 的兼容性,否则应该使用较新的版本),你也可以这样做。
~/package $ cmake -S . -B build
~/package $ cmake --build build
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ ls
CMakeLists.txt cmake-build-debug main.cpp
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ cmake -S . -B build
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (1.3s)
-- Generating done (0.0s)
-- Build files have been written to: /home/yongqiang/CLionProjects/yongqiang/build
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ ls
CMakeLists.txt build cmake-build-debug main.cpp
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ cmake --build build
[ 50%] Building CXX object CMakeFiles/yongqiang.dir/main.cpp.o
[100%] Linking CXX executable yongqiang
[100%] Built target yongqiang
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ ls
CMakeLists.txt build cmake-build-debug main.cpp
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ cd build/
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$ ls
CMakeCache.txt CMakeFiles Makefile cmake_install.cmake yongqiang
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$ ./yongqiang
Hello, World!
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$
以下任何一条命令都能够执行安装:
# From the build directory (pick one)
~/package/build $ make install
~/package/build $ cmake --build . --target install
~/package/build $ cmake --install . # CMake 3.15+ only
# From the source directory (pick one)
~/package $ make -C build install
~/package $ cmake --build build --target install
~/package $ cmake --install build # CMake 3.15+ only
As long as you do not forget to type the build directory as the argument, staying out of the build directory is shorter, and making source changes is easier from the source directory. You should try to get used to using --build
, as that will free you from using only make
to build.
只要你别忘记输入构建目录作为参数,在构建目录之外的时间较短,并且从源代码目录更改源代码比较方便就行。你应该试着习惯使用 --build
,因为它能让你免于只用 make
来构建。
Note that working from the build directory is historically much more common, and some tools and commands (including CTest < 3.20) still require running from the build directory.
需要注意的是,在构建目录下进行工作一直都非常普遍,并且一些工具和命令 (including CTest < 3.20) 仍然需要在 build
目录中才能工作。
You can point CMake at either the source directory from the build directory, or at an existing build directory from anywhere.
你可以指定 CMake 工作在来自构建目录的源代码目录,也可以工作在任何现有的构建目录。
If you use cmake --build
instead of directly calling the underlying build system, you can use -v
for verbose builds (CMake 3.14+), -j N
for parallel builds on N cores (CMake 3.12+), and --target
(any version of CMake) or -t
(CMake 3.15+) to pick a target.
如果你使用 cmake --build
而不是直接调用更底层的构建系统 (make
),你可以用 -v
参数在构建时获得详细的输出 (CMake 3.14+),用 -j N
指定用 N 个 CPU 核心并行构建项目 (CMake 3.12+),以及用 --target
(any version of CMake) or -t
(CMake 3.15+) 来选择一个目标进行部分地构建。
Otherwise, these commands vary between build systems, such as VERBOSE=1 make
and ninja -v
. You can instead use the environment variables for these, as well, such as CMAKE_BUILD_PARALLEL_LEVEL
(CMake 3.12+) and VERBOSE
(CMake 3.14+).
这些命令因不同的构建系统而异,例如 VERBOSE=1 make
and ninja -v
。你也可以使用环境变量替代它们,例如 CMAKE_BUILD_PARALLEL_LEVEL
(CMake 3.12+) and VERBOSE
(CMake 3.14+)。
2.2. Picking a compiler (指定编译器)
Selecting a compiler must be done on the first run in an empty directory. It’s not CMake syntax per se, but you might not be familiar with it.
指定编译器必须在第一次运行时在空目录中进行。这种命令并不属于 CMake 语法。
To pick Clang:
~/package/build $ CC=clang CXX=clang++ cmake ..
That sets the environment variables in bash for CC
and CXX
, and CMake will respect those variables. This sets it just for that one line, but that’s the only time you’ll need those; afterwards CMake continues to use the paths it deduces from those values.
这条命令设置了 bash 里的环境变量 CC
和 CXX
,并且 CMake 会使用这些参数。这一行命令就够了,你也只需要调用一次;之后 CMake 会继续使用从这些变量里推导出来的路径。
2.3. Verbose and partial builds (详细和部分的构建)
Although not all build tools support it, you can get verbose builds (pick one):
~/package $ cmake --build build --verbose # CMake 3.14+ only
~/package/build $ VERBOSE=1 make
You can actually write make VERBOSE=1
, and make
will also do the right thing, though that’s a feature of make
and not the command line in general.
实际上你写成 make VERBOSE=1
,make
也能正确工作,但这是 make
的一个特性而不是命令行的惯用写法。
You can also build just a part of a build by specifying a target, such as the name of a library or executable you’ve defined in CMake, and make will just build that target.
你也可以通过指定一个目标来仅构建一部分,例如指定你已经在 CMake 中定义的库或可执行文件的名称,然后 make
将会只构建这一个目标。
~/package $ mkdir build
~/package $ cd build
~/package/build $ cmake ..
~/package/build $ VERBOSE=1 make
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ ls
CMakeLists.txt cmake-build-debug main.cpp
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ mkdir build
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang$ cd build
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$ cmake ..
-- The C compiler identification is GNU 9.4.0
-- The CXX compiler identification is GNU 9.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done (4.2s)
-- Generating done (0.0s)
-- Build files have been written to: /home/yongqiang/CLionProjects/yongqiang/build
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$ VERBOSE=1 make
/home/yongqiang/miniconda3/bin/cmake -S/home/yongqiang/CLionProjects/yongqiang -B/home/yongqiang/CLionProjects/yongqiang/build --check-build-system CMakeFiles/Makefile.cmake 0
/home/yongqiang/miniconda3/bin/cmake -E cmake_progress_start /home/yongqiang/CLionProjects/yongqiang/build/CMakeFiles /home/yongqiang/CLionProjects/yongqiang/build//CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/yongqiang/CLionProjects/yongqiang/build'
make -f CMakeFiles/yongqiang.dir/build.make CMakeFiles/yongqiang.dir/depend
make[2]: Entering directory '/home/yongqiang/CLionProjects/yongqiang/build'
cd /home/yongqiang/CLionProjects/yongqiang/build && /home/yongqiang/miniconda3/bin/cmake -E cmake_depends "Unix Makefiles" /home/yongqiang/CLionProjects/yongqiang /home/yongqiang/CLionProjects/yongqiang /home/yongqiang/CLionProjects/yongqiang/build /home/yongqiang/CLionProjects/yongqiang/build /home/yongqiang/CLionProjects/yongqiang/build/CMakeFiles/yongqiang.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/yongqiang/CLionProjects/yongqiang/build'
make -f CMakeFiles/yongqiang.dir/build.make CMakeFiles/yongqiang.dir/build
make[2]: Entering directory '/home/yongqiang/CLionProjects/yongqiang/build'
[ 50%] Building CXX object CMakeFiles/yongqiang.dir/main.cpp.o
/usr/bin/c++ -MD -MT CMakeFiles/yongqiang.dir/main.cpp.o -MF CMakeFiles/yongqiang.dir/main.cpp.o.d -o CMakeFiles/yongqiang.dir/main.cpp.o -c /home/yongqiang/CLionProjects/yongqiang/main.cpp
[100%] Linking CXX executable yongqiang
/home/yongqiang/miniconda3/bin/cmake -E cmake_link_script CMakeFiles/yongqiang.dir/link.txt --verbose=1
/usr/bin/c++ CMakeFiles/yongqiang.dir/main.cpp.o -o yongqiang
make[2]: Leaving directory '/home/yongqiang/CLionProjects/yongqiang/build'
[100%] Built target yongqiang
make[1]: Leaving directory '/home/yongqiang/CLionProjects/yongqiang/build'
/home/yongqiang/miniconda3/bin/cmake -E cmake_progress_start /home/yongqiang/CLionProjects/yongqiang/build/CMakeFiles 0
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$
2.4. Options (选项)
CMake has support for cached options. A Variable in CMake can be marked as “cached”, which means it will be written to the cache (a file called CMakeCache.txt
in the build directory) when it is encountered. You can preset (or change) the value of a cached option on the command line with -D
. When CMake looks for a cached variable, it will use the existing value and will not overwrite it.
CMake 支持缓存选项。CMake 中的变量可以被标记为 “cached”,这意味着它会被写入缓存(构建目录中名为 CMakeCache.txt 的文件)。你可以在命令行中用 -D
预先设定或更改缓存选项的值。CMake 查找一个缓存的变量时,它就会使用已有的值并且不会覆盖这个值。
2.4.1. Standard options (标准选项)
These are common CMake options to most packages:
-DCMAKE_BUILD_TYPE=
Pick fromRelease
,RelWithDebInfo
,Debug
, or sometimes more.
从Release
,RelWithDebInfo
,Debug
或者可能存在的更多参数中选择。-DCMAKE_INSTALL_PREFIX=
The location to install to. System install on UNIX would often be/usr/local
(the default), user directories are often~/.local
, or you can pick a folder.
这是安装位置。UNIX 系统默认的位置是/usr/local
,用户目录是~/.local
,也可以是你自己指定的文件夹。-DBUILD_SHARED_LIBS=
You can set thisON
orOFF
to control the default for shared libraries (the author can pick one vs. the other explicitly instead of using the default, though)
你可以把这里设置为 ON 或 OFF 来控制共享库的默认值 (不过,你也可以明确选择其他值而不是默认值)-DBUILD_TESTING=
This is a common name for enabling tests, not all packages use it, though, sometimes with good reason.
这是启用测试的通用名称,当然不会所有软件包都会使用它,有时这样做确实不错。
2.5. Debugging your CMake files (调试你的 CMake 文件)
We’ve already mentioned verbose output for the build, but you can also see verbose CMake configure output too. The --trace
option will print every line of CMake that is run. Since this is very verbose, CMake 3.7 added --trace-source="filename"
, which will print out every executed line of just the file you are interested in when it runs. If you select the name of the file you are interested in debugging (usually by selecting the parent directory when debugging a CMakeLists.txt, since all of those have the same name), you can just see the lines that run in that file.
我们已经提到了在构建时可以有详细输出,但你也可以看到详细的 CMake 配置输出。--trace
选项能够打印出运行的 CMake 的每一行。由于它过于冗长,CMake 3.7 添加了 --trace-source="filename"
选项,这让你可以打印出你想看的特定文件运行时执行的每一行。如果你选择了要调试的文件的名称 (在调试 CMakeLists.txt 时通常选择父目录,因为它的名字在任何项目中都一样),你就会只看到这个文件里运行的那些行。
2.6. Setting options (设置选项)
You set options in CMake with -D
. You can see a list of options with -L
, or a list with human-readable help with -LH
. If you don’t list the source/build directory, the listing will not rerun CMake (cmake -L
instead of cmake -L .
).
在 CMake 中,你可以使用 -D
设置选项。你能使用 -L
列出所有选项,或者用 -LH
列出人类更易读的选项列表。如果你没有列出源代码目录或构建目录,这条命令将不会重新运行 CMake (使用 cmake -L
而不是 cmake -L .
)。
2.7. Picking a generator (指定生成器)
You can build with a variety of tools; make
is usually the default.
你可以选择的构建工具有很多,通常默认的是 make
。要显示在你的系统上 CMake 可以调用的所有构建工具,运行
~/package/build $ cmake --help
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$ cmake --help
Usage
cmake [options] <path-to-source>
cmake [options] <path-to-existing-build>
cmake [options] -S <path-to-source> -B <path-to-build>
Specify a source directory to (re-)generate a build system for it in the
current working directory. Specify an existing build directory to
re-generate its build system.
Options
-S <path-to-source> = Explicitly specify a source directory.
-B <path-to-build> = Explicitly specify a build directory.
-C <initial-cache> = Pre-load a script to populate the cache.
-D <var>[:<type>]=<value> = Create or update a cmake cache entry.
-U <globbing_expr> = Remove matching entries from CMake cache.
-G <generator-name> = Specify a build system generator.
-T <toolset-name> = Specify toolset name if supported by
generator.
-A <platform-name> = Specify platform name if supported by
generator.
--toolchain <file> = Specify toolchain file
[CMAKE_TOOLCHAIN_FILE].
--install-prefix <directory> = Specify install directory
[CMAKE_INSTALL_PREFIX].
-Wdev = Enable developer warnings.
-Wno-dev = Suppress developer warnings.
-Werror=dev = Make developer warnings errors.
-Wno-error=dev = Make developer warnings not errors.
-Wdeprecated = Enable deprecation warnings.
-Wno-deprecated = Suppress deprecation warnings.
-Werror=deprecated = Make deprecated macro and function warnings
errors.
-Wno-error=deprecated = Make deprecated macro and function warnings
not errors.
--preset <preset>,--preset=<preset>
= Specify a configure preset.
--list-presets[=<type>] = List available presets.
-E = CMake command mode.
-L[A][H] = List non-advanced cached variables.
--fresh = Configure a fresh build tree, removing any
existing cache file.
--build <dir> = Build a CMake-generated project binary tree.
--install <dir> = Install a CMake-generated project binary
tree.
--open <dir> = Open generated project in the associated
application.
-N = View mode only.
-P <file> = Process script mode.
--find-package = Legacy pkg-config like mode. Do not use.
--graphviz=<file> = Generate graphviz of dependencies, see
CMakeGraphVizOptions.cmake for more.
--system-information [file] = Dump information about this system.
--log-level=<ERROR|WARNING|NOTICE|STATUS|VERBOSE|DEBUG|TRACE>
= Set the verbosity of messages from CMake
files. --loglevel is also accepted for
backward compatibility reasons.
--log-context = Prepend log messages with context, if given
--debug-trycompile = Do not delete the try_compile build tree.
Only useful on one try_compile at a time.
--debug-output = Put cmake in a debug mode.
--debug-find = Put cmake find in a debug mode.
--debug-find-pkg=<pkg-name>[,...]
= Limit cmake debug-find to the
comma-separated list of packages
--debug-find-var=<var-name>[,...]
= Limit cmake debug-find to the
comma-separated list of result variables
--trace = Put cmake in trace mode.
--trace-expand = Put cmake in trace mode with variable
expansion.
--trace-format=<human|json-v1>
= Set the output format of the trace.
--trace-source=<file> = Trace only this CMake file/module. Multiple
options allowed.
--trace-redirect=<file> = Redirect trace output to a file instead of
stderr.
--warn-uninitialized = Warn about uninitialized values.
--no-warn-unused-cli = Don't warn about command line options.
--check-system-vars = Find problems with variable usage in system
files.
--compile-no-warning-as-error= Ignore COMPILE_WARNING_AS_ERROR property and
CMAKE_COMPILE_WARNING_AS_ERROR variable.
--profiling-format=<fmt> = Output data for profiling CMake scripts.
Supported formats: google-trace
--profiling-output=<file> = Select an output path for the profiling data
enabled through --profiling-format.
-h,-H,--help,-help,-usage,/? = Print usage information and exit.
--version,-version,/V [<file>]
= Print version number and exit.
--help-full [<file>] = Print all help manuals and exit.
--help-manual <man> [<file>] = Print one help manual and exit.
--help-manual-list [<file>] = List help manuals available and exit.
--help-command <cmd> [<file>]= Print help for one command and exit.
--help-command-list [<file>] = List commands with help available and exit.
--help-commands [<file>] = Print cmake-commands manual and exit.
--help-module <mod> [<file>] = Print help for one module and exit.
--help-module-list [<file>] = List modules with help available and exit.
--help-modules [<file>] = Print cmake-modules manual and exit.
--help-policy <cmp> [<file>] = Print help for one policy and exit.
--help-policy-list [<file>] = List policies with help available and exit.
--help-policies [<file>] = Print cmake-policies manual and exit.
--help-property <prop> [<file>]
= Print help for one property and exit.
--help-property-list [<file>]= List properties with help available and
exit.
--help-properties [<file>] = Print cmake-properties manual and exit.
--help-variable var [<file>] = Print help for one variable and exit.
--help-variable-list [<file>]= List variables with help available and exit.
--help-variables [<file>] = Print cmake-variables manual and exit.
Generators
The following generators are available on this platform (* marks default):
Green Hills MULTI = Generates Green Hills MULTI files
(experimental, work-in-progress).
* Unix Makefiles = Generates standard UNIX makefiles.
Ninja = Generates build.ninja files.
Ninja Multi-Config = Generates build-<Config>.ninja files.
Watcom WMake = Generates Watcom WMake makefiles.
CodeBlocks - Ninja = Generates CodeBlocks project files.
CodeBlocks - Unix Makefiles = Generates CodeBlocks project files.
CodeLite - Ninja = Generates CodeLite project files.
CodeLite - Unix Makefiles = Generates CodeLite project files.
Eclipse CDT4 - Ninja = Generates Eclipse CDT 4.0 project files.
Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.
Kate - Ninja = Generates Kate project files.
Kate - Unix Makefiles = Generates Kate project files.
Sublime Text 2 - Ninja = Generates Sublime Text 2 project files.
Sublime Text 2 - Unix Makefiles
= Generates Sublime Text 2 project files.
(base) yongqiang@yongqiang:~/CLionProjects/yongqiang/build$
And you can pick a tool with -G"My Tool"
(quotes only needed if spaces are in the tool name). You should pick a tool on your first CMake call in a directory, just like the compiler. Feel free to have several build directories, like build/
and buildXcode
.
你也可以用 -G"My Tool"
(仅当构建工具的名字中包含空格时才需要引号) 来指定构建工具。像指定编译器一样,你应该在一个目录中第一次调用 CMake 时就指定构建工具。如果有好几个构建目录也没关系,比如 build/
and buildXcode
。
You can set the environment variable CMAKE_GENERATOR
to control the default generator (CMake 3.15+).
你可以用环境变量 CMAKE_GENERATOR
来指定默认的生成器 (CMake 3.15+)。
Note that makefiles will only run in parallel if you explicitly pass a number of threads, such as make -j2
, while Ninja will automatically run in parallel. You can directly pass a parallelization option such as -j2
to the cmake --build .
command in recent versions of CMake.
makefiles 只会在你明确地指出线程数目之时才会并行运行,比如 make -j2
,而 Ninja 却会自动地并行运行。在较新版本的 CMake 中,你能直接传递并行选项,比如 -j2
,到命令 cmake --build .
。
References
[1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/
[2] Quick start guide, https://www.jetbrains.com/help/clion/clion-quick-start-guide.html
[3] 轻松上手, https://www.jetbrains.com/zh-cn/clion/features/start-your-project.html