CMake + MSVC 构建工具 2015 - 调用 cmake 后做什么?
CMake + MSVC build tools 2015 - what to do after invoking cmake?
我以前从未在 Windows 或 MSVC 上使用过 CMake;所以这是一个新手问题。
我已经在 Windows 10 机器上安装了 CMake 和一些可自由下载的最小 "Microsoft Visual C++ build tools 2015"(来自 here)。我已经检查了基于 CMake 的项目(在 Linux 上构建良好),我准备好了。
因此,在 shell window 中,我会:
PS C:\Users\joeuser\the_project> mkdir build
... etc. etc. ...
PS C:\Users\joeuser\the_project> cd build
PS C:\Users\joeuser\the_project\build> cmake ../
-- Building for: Visual Studio 14 2015
-- Selecting Windows SDK version to target Windows 10.0.15063.
-- lots of checks here
-- etc. etc.
这就完成了。到目前为止,一切都很好。但是——现在怎么办?在 Unix'ish 系统上,我会执行 make
,也许 make install
;也许 make clean
以后。我的问题是:
- 我使用的 MSVC 工具是否具有
make
的等效项?我已经开始研究 nmake 和 msys,但我不确定它们是否与此相关。
- 我现在要做什么才能构建、安装或清理构建目录?
- 在我的场景中使用不同的 CMake 生成器是better/easier/more常见的做法吗?
将我之前的评论作为答案:
然后您可以直接通过 CMake 调用底层构建工具:
cmake --build . --target ALL_BUILD --config Debug -- /nologo /verbosity:minimal
这为您提供了一个几乎安静的构建过程,就像您从 make
习惯的那样。
Why the hell do I have to provide so much arguments to CMake?
因为 CMake 是构建系统生成器并将这些参数定向到底层构建工具(make
、MSBuild
、nmake
、...)。底层构建工具可能对目标等有不同的命名约定,例如让用户几乎总是提供目标 all
、clean
和 install
。但是CMake生成的Visual Studio方案默认使用ALL_BUILD
、INSTALL
、RUN_TESTS
。没有 CLEAN
目标。使用 MSBuild,
- 安装你的解决方案你会select
--target INSTALL
.
- 对于 运行 测试,你会 select
--target RUN_TESTS
.
- 对于清理,您必须使用
--target ALL_BUILD --config Debug -- /nologo /verbosity:minimal /t:Clean
,因为Visual Studio解决方案不包含清理目标,但 MSBuild 提供了一个。
MSBuild 的其他重要参数是:
/maxcpucount:<numberOfCpus>
(限制构建过程使用的 CPU 数量)和
"/l:FileLogger,Microsoft.Build.Engine;logfile=<YOUR_LOGFILE_NAME>"
将 MSBuild 输出保存到文件。
我以前从未在 Windows 或 MSVC 上使用过 CMake;所以这是一个新手问题。
我已经在 Windows 10 机器上安装了 CMake 和一些可自由下载的最小 "Microsoft Visual C++ build tools 2015"(来自 here)。我已经检查了基于 CMake 的项目(在 Linux 上构建良好),我准备好了。
因此,在 shell window 中,我会:
PS C:\Users\joeuser\the_project> mkdir build
... etc. etc. ...
PS C:\Users\joeuser\the_project> cd build
PS C:\Users\joeuser\the_project\build> cmake ../
-- Building for: Visual Studio 14 2015
-- Selecting Windows SDK version to target Windows 10.0.15063.
-- lots of checks here
-- etc. etc.
这就完成了。到目前为止,一切都很好。但是——现在怎么办?在 Unix'ish 系统上,我会执行 make
,也许 make install
;也许 make clean
以后。我的问题是:
- 我使用的 MSVC 工具是否具有
make
的等效项?我已经开始研究 nmake 和 msys,但我不确定它们是否与此相关。 - 我现在要做什么才能构建、安装或清理构建目录?
- 在我的场景中使用不同的 CMake 生成器是better/easier/more常见的做法吗?
将我之前的评论作为答案:
然后您可以直接通过 CMake 调用底层构建工具:
cmake --build . --target ALL_BUILD --config Debug -- /nologo /verbosity:minimal
这为您提供了一个几乎安静的构建过程,就像您从 make
习惯的那样。
Why the hell do I have to provide so much arguments to CMake?
因为 CMake 是构建系统生成器并将这些参数定向到底层构建工具(make
、MSBuild
、nmake
、...)。底层构建工具可能对目标等有不同的命名约定,例如让用户几乎总是提供目标 all
、clean
和 install
。但是CMake生成的Visual Studio方案默认使用ALL_BUILD
、INSTALL
、RUN_TESTS
。没有 CLEAN
目标。使用 MSBuild,
- 安装你的解决方案你会select
--target INSTALL
. - 对于 运行 测试,你会 select
--target RUN_TESTS
. - 对于清理,您必须使用
--target ALL_BUILD --config Debug -- /nologo /verbosity:minimal /t:Clean
,因为Visual Studio解决方案不包含清理目标,但 MSBuild 提供了一个。
MSBuild 的其他重要参数是:
/maxcpucount:<numberOfCpus>
(限制构建过程使用的 CPU 数量)和"/l:FileLogger,Microsoft.Build.Engine;logfile=<YOUR_LOGFILE_NAME>"
将 MSBuild 输出保存到文件。