CMake详解

https://www.cnblogs.com/jsxyhelu/p/12804033.html
https://blog.csdn.net/liu798675179/article/details/51259505
https://blog.csdn.net/u011028345/article/details/74502317

CMake是用于管理源代码构建的工具。最初,CMake被设计为多种方言的生成器Makefile,如今,CMake可以生成现代的构建系统Ninja,以及用于IDE(例如Visual Studio和Xcode)的项目文件。
CMake被广泛用于C和C ++语言,但是它也可以用于构建其他语言的源代码。

命令行工具—— cmake

#生成项目构建系统
 cmake [<选项>] <源路径>
 cmake [<选项>] <现有构建路径>
 cmake [<选项>] -S <源路径> -B <构建路径>

#建立一个项目
 cmake --build <目录> [<选项>] [-<构建工具选项>]

#安装项目
 cmake --install <目录> [<选项>]

#打开一个项目
 cmake --open <目录>

#运行脚本
 cmake [{-D <var> = <>} ...] -P <cmake-script-file>

#运行命令行工具
 cmake -E <命令> [<选项>]

#运行查找包工具
 cmake --find-package [<选项>]

查看帮助 
 cmake --help [-<topic>]

生成项目构建系统

#cmake [<options>] <path-to-source> 
$ mkdir build ; cd build
$ cmake ../src

创建并进入构建树目录,指定源树绝对路径(相对路径)且源树目录必须包含一个CMakeLists.txt。不能包含一个CMakeCache.txt文件。

#cmake [<options>] <path-to-existing-build>
$ cd build
$ cmake .

< path-to-existing-build >为构建树目录,该命令从源代码树CMakeCache.txt文件(由上次Cmake运行产生)。< path-to-existing-build >为构建树目录可以是绝对路径或相对路径:

#cmake [<options>] -S <path-to-source> -B <path-to-build> 
$ cmake -S src -B build

指定源树路径和构建树路径,且源树路径必须包含CMakeLists.txt,如果构建树目录不存在将会自动创建。

在所有情况下,以下选项可能为零或多个。生成构建系统后,可以使用相应的本机构建工具来构建项目。 Unix Makefiles

$ make
$ make install

或者,可以使用cmake通过自动选择并调用适当的本机构建工具来构建项目。
选项

安装项目

CMake提供了一个命令行签名来安装已经生成的项目二进制树:cmake --install <dir> [<options>]
可以在构建项目以运行安装后使用它,而无需使用生成的构建系统或本机构建工具。选项包括:

--install <dir> # 要安装的项目二进制目录。这是必需的,必须首先。
--config <cfg> #对于多配置生成器,请选择configuration <cfg>。
--component <comp> #基于组件的安装。仅安装组件<comp>。
--prefix <prefix> #覆盖安装前缀, CMAKE_INSTALL_PREFIX。
--strip#在安装之前将其剥离。
-v, --verbose#启用详细输出。如果该选项可以省略 VERBOSE 环境变量已设置。

不带选项运行即可获得快速帮助。cmake --install

打开一个项目

cmake --open <dir>在关联的应用程序中打开生成的项目。仅某些生成器支持。

运行脚本

cmake [{-D <var>=<value>}...] -P <cmake-script-file>将给定的cmake文件作为以CMake语言编写的脚本进行处理。不执行配置或生成步骤,并且不修改缓存。如果使用定义了变量-D,则必须在-P参数之前完成。

运行命令行工具

CMake通过签名提供内置的命令行工具cmake -E <command> [<options>]运行或获取命令摘要。可用的命令有:cmake -Ecmake -E help

命令行工具—— ctest

ctest [<options>]
ctest --build-and-test <path-to-source> <path-to-build>
      --build-generator <generator> [<options>...]
      [--build-options <opts>...] [--test-command <command> [<args>...]]
ctest {-D <dashboard> | -M <model> -T <action> | -S <script> | -SP <script>}
      [-- <dashboard-options>...]

cmake命令

脚本命令

break() #从封闭的foreach()或while()循环中断。

cmake_host_system_information#查询运行cmake的主机系统的系统信息。
cmake_minimum_required #设置项目的cmake最低要求版本
cmake_parse_arguments #该命令用于宏或函数。处理该宏或函数的参数,并定义一组保存相应选项值的变量。
cmake_policy  #管理CMake策略设置。
configure_file #将文件复制到另一个位置并修改其内容。
continue #中止一个块中的其余块foreach() 要么 while() 循环
if
else
elseif

endforeach
endfunction #结束功能块中的命令列表。
endif
endmacro
endwhile
execute_process
file
find_file
find_library
find_package
find_path
find_program
foreach
function
get_cmake_property
get_directory_property
get_filename_component
get_property

include
include_guard
list
macro
mark_as_advanced
math
message
option
return
separate_arguments
set
set_directory_properties
set_property
site_name
string
unset
variable_watch
while

Project Commands
These commands are available only in CMake projects.

add_compile_definitions
add_compile_options
add_custom_command
add_custom_target
add_definitions
add_dependencies
add_executable
add_library
add_link_options
add_subdirectory
add_test
aux_source_directory
build_command
create_test_sourcelist
define_property
enable_language
enable_testing
export
fltk_wrap_ui
get_source_file_property
get_target_property
get_test_property
include_directories
include_external_msproject
include_regular_expression
install
link_directories
link_libraries
load_cache
project
remove_definitions
set_source_files_properties
set_target_properties
set_tests_properties
source_group
target_compile_definitions
target_compile_features
target_compile_options
target_include_directories
target_link_directories
target_link_libraries
target_link_options
target_precompile_headers
target_sources
try_compile
try_run
CTest Commands
These commands are available only in CTest scripts.

ctest_build
ctest_configure
ctest_coverage
ctest_empty_binary_directory
ctest_memcheck
ctest_read_custom_files
ctest_run_script
ctest_sleep
ctest_start
ctest_submit
ctest_test
ctest_update
ctest_upload

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值