c++构建工具之cmake使用小结
生活随笔
收集整理的這篇文章主要介紹了
c++构建工具之cmake使用小结
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
0.前言
使用cmake的過程先是要編寫一個cmakelists.txt的文本,然后使用cmake命令生成對應(yīng)平臺的工程。
在windows下命令行或者使用cmake gui工具,生成vs工程,然后使用vs編譯。
在linux下則是根據(jù)cmakelists.txt生成makefile,然后使用make命令調(diào)用編譯。
cmake命令編譯指定目錄下的cmakelists.txt,具體選項使用cmake -h查看如下:
Usagecmake [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 bygenerator.-A <platform-name> = Specify platform name if supported bygenerator.-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 warningserrors.-Wno-error=deprecated = Make deprecated macro and function warningsnot 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, seeCMakeGraphVizOptions.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 variableexpansion.--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 systemfiles.--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 andexit.--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.GeneratorsThe 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.生成執(zhí)行程序
project(HELLO) set(SRC_LIST main.c hello.c) add_executable(hello ${SRC_LIST})
2.生成動態(tài)庫
project(HELLO) set(LIB_SRC hello.c) add_library(libhello STATIC ${LIB_SRC})
3.生成靜態(tài)庫
project(HELLO) set(LIB_SRC hello.c) add_library(libhello SHARED ${LIB_SRC})
4.參考資料
http://blog.csdn.net/dbzhang800/article/details/6314073
http://blog.csdn.net/dbzhang800/article/details/6329068
https://cmake.org/cmake/help/v3.3/index.html
http://blog.csdn.net/sjt19910311/article/details/51660209
http://blog.csdn.net/wzzfeitian/article/details/40963457
使用cmake的過程先是要編寫一個cmakelists.txt的文本,然后使用cmake命令生成對應(yīng)平臺的工程。
在windows下命令行或者使用cmake gui工具,生成vs工程,然后使用vs編譯。
在linux下則是根據(jù)cmakelists.txt生成makefile,然后使用make命令調(diào)用編譯。
cmake命令編譯指定目錄下的cmakelists.txt,具體選項使用cmake -h查看如下:
Usagecmake [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 bygenerator.-A <platform-name> = Specify platform name if supported bygenerator.-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 warningserrors.-Wno-error=deprecated = Make deprecated macro and function warningsnot 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, seeCMakeGraphVizOptions.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 variableexpansion.--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 systemfiles.--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 andexit.--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.GeneratorsThe 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.生成執(zhí)行程序
project(HELLO) set(SRC_LIST main.c hello.c) add_executable(hello ${SRC_LIST})
2.生成動態(tài)庫
project(HELLO) set(LIB_SRC hello.c) add_library(libhello STATIC ${LIB_SRC})
3.生成靜態(tài)庫
project(HELLO) set(LIB_SRC hello.c) add_library(libhello SHARED ${LIB_SRC})
4.參考資料
http://blog.csdn.net/dbzhang800/article/details/6314073
http://blog.csdn.net/dbzhang800/article/details/6329068
https://cmake.org/cmake/help/v3.3/index.html
http://blog.csdn.net/sjt19910311/article/details/51660209
http://blog.csdn.net/wzzfeitian/article/details/40963457
總結(jié)
以上是生活随笔為你收集整理的c++构建工具之cmake使用小结的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c++构建工具之make使用小结
- 下一篇: linux命令之创建符号连接-ln