首页 > 编程语言 >c++构建工具之cmake使用小结

c++构建工具之cmake使用小结

时间:2022-12-11 20:34:43浏览次数:44  
标签:cmake help -- c++ project exit 小结 Generates


0.前言

使用cmake的过程先是要编写一个cmakelists.txt的文本,然后使用cmake命令生成对应平台的工程。

在windows下命令行或者使用cmake gui工具,生成vs工程,然后使用vs编译。

在linux下则是根据cmakelists.txt生成makefile,然后使用make命令调用编译。


cmake命令编译指定目录下的cmakelists.txt,具体选项使用cmake -h查看如下:

Usage

cmake [options] <path-to-source>
cmake [options] <path-to-existing-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
-C <initial-cache> = Pre-load a script to populate the cache.
-D <var>[:<type>]=<value> = Create 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.
-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.
-E = CMake command mode.
-L[A][H] = List non-advanced cached variables.
--build <dir> = Build a CMake-generated project binary tree.
-N = View mode only.
-P <file> = Process script mode.
--find-package = Run in pkg-config like mode.
--graphviz=[file] = Generate graphviz of dependencies, see
CMakeGraphVizOptions.cmake for more.
--system-information [file] = Dump information about this system.
--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.
--trace = Put cmake in trace mode.
--trace-expand = Put cmake in trace mode with variable
expansion.
--warn-uninitialized = Warn about uninitialized values.
--warn-unused-vars = Warn about unused variables.
--no-warn-unused-cli = Don't warn about command line options.
--check-system-vars = Find problems with variable usage in system
files.
--help,-help,-usage,-h,-H,/? = Print usage information and exit.
--version,-version,/V [<f>] = Print version number and exit.
--help-full [<f>] = Print all help manuals and exit.
--help-manual <man> [<f>] = Print one help manual and exit.
--help-manual-list [<f>] = List help manuals available and exit.
--help-command <cmd> [<f>] = Print help for one command and exit.
--help-command-list [<f>] = List commands with help available and exit.
--help-commands [<f>] = Print cmake-commands manual and exit.
--help-module <mod> [<f>] = Print help for one module and exit.
--help-module-list [<f>] = List modules with help available and exit.
--help-modules [<f>] = Print cmake-modules manual and exit.
--help-policy <cmp> [<f>] = Print help for one policy and exit.
--help-policy-list [<f>] = List policies with help available and exit.
--help-policies [<f>] = Print cmake-policies manual and exit.
--help-property <prop> [<f>] = Print help for one property and exit.
--help-property-list [<f>] = List properties with help available and
exit.
--help-properties [<f>] = Print cmake-properties manual and exit.
--help-variable var [<f>] = Print help for one variable and exit.
--help-variable-list [<f>] = List variables with help available and exit.
--help-variables [<f>] = Print cmake-variables manual and exit.

Generators

The following generators are available on this platform:
Unix Makefiles = Generates standard UNIX makefiles.
Ninja = Generates build.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.
KDevelop3 = Generates KDevelop 3 project files.
KDevelop3 - Unix Makefiles = Generates KDevelop 3 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.



1.生成执行程序


project(HELLO)
set(SRC_LIST main.c hello.c)
add_executable(hello ${SRC_LIST})


2.生成动态库


project(HELLO)
set(LIB_SRC hello.c)
add_library(libhello STATIC ${LIB_SRC})


3.生成静态库


project(HELLO)
set(LIB_SRC hello.c)
add_library(libhello SHARED ${LIB_SRC})


标签:cmake,help,--,c++,project,exit,小结,Generates
From: https://blog.51cto.com/u_4296776/5928629

相关文章

  • C++:类的私有继承、公有继承、多重继承讨论
    背景第十四章课后练习第一题中,再次提及了私有继承、公有继承和多重继承。想了想好像这块儿的概念有点淡忘,感觉比较重要,特意写个小结。果然C++的越来越多的关键字很被人厌......
  • TNN推理测试demo--c++
    ////CreatedbyDangXSon2022/12/8.//#include<stdio.h>#include<stdlib.h>#include<string.h>#include<cfloat>#include<cstdlib>#include<fstream>......
  • C++ Employees With Three Different Positions Work At a Restaurant
    C++EmployeesWithThreeDifferentPositionsWorkAtaRestaurantObjectivesThisassignmentaimsatunderstandingclasshierarchies,multipleinheritanceand......
  • c++ weak_ptr
     weak_ptr(1)weak_ptr指向一个shared_ptr指向的对象,且不会改变对象的引用计数。(2)weak_ptr不控制所指对象的生命周期,不拥有所有权。(3)不能调用->和解引用*weak_ptr使用场......
  • C++:类模板知识回顾
    概述类的私有、公有、类继承有时并不能满足我们的开发需求,尤其是将类作为容器(泛型编程)使用时,因此类模板在C++随之衍生。相关概念也会在下文中一一阐述~模板类的定义与使......
  • python爬虫小结1
    python爬虫小结11正则匹配中注意的:importrea='<div>指数</div>'word=re.findall('<div>(.*?)</div>',a)print(word)其中(.*?)是能匹配基本所有的字符,但是对于跨行的......
  • C++学习---cstdio的源码学习分析04-创建临时文件函数tmpfile
    cstdio中的文件操作函数stdio.h中定义了文件删除函数remove,文件重命名函数rename,创建临时文件函数tmpfile,生成临时文件名函数tmpnam。接下来我们一起来分析一下tmpfile对应......
  • C++
    通讯录管理系统1、系统需求通讯录是一个可以记录亲人、好友信息的工具。本教程主要利用C++来实现一个通讯录管理系统系统中需要实现的功能如下:添加联系人:向通讯录中......
  • C/C++外卖点餐管理程序
    C/C++外卖点餐管理程序2、外卖点餐管理程序设计一个外卖点餐系统,要求餐厅管理员可以输入菜品信息(编号,菜名,价格,数量....),顾客可以根据菜品信息下单(订餐人,电话,菜品列表......
  • c++ l理解智能指针
     智能指针概述C++的指针包括原始指针和智能指针两种,智能指针是原始指针的封装,其优点是可以自动分配内存,无需担心内存的泄露。并不是所有的指针都可以封装为智能指针,很多......