cmake執行工程

sworsman31415926發表於2020-12-10

參考文獻:

c++構建工具之cmake使用小結_數學物理方法-CSDN部落格


使用cmake的過程先是要編寫一個cmakelists.txt的文字,然後使用cmake命令生成對應平臺的工程。

在windows下命令列或者使用cmake gui工具,生成vs工程,然後使用vs編譯。

在linux下則是根據cmakelists.txt生成makefile,然後使用make命令呼叫編譯。


1.cmake命令編譯指定目錄下的cmakelists.txt,具體選項使用cmake makelist.txt生成makefile,

2.然後執行make就可以進行程式碼編譯了。(非常好使)

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
  1. Usage

  2.  
  3. cmake [options] <path-to-source>

  4. cmake [options] <path-to-existing-build>

  5.  
  6. Specify a source directory to (re-)generate a build system for it in the

  7. current working directory. Specify an existing build directory to

  8. re-generate its build system.

  9.  
  10. Options

  11. -C <initial-cache> = Pre-load a script to populate the cache.

  12. -D <var>[:<type>]=<value> = Create a cmake cache entry.

  13. -U <globbing_expr> = Remove matching entries from CMake cache.

  14. -G <generator-name> = Specify a build system generator.

  15. -T <toolset-name> = Specify toolset name if supported by

  16. generator.

  17. -A <platform-name> = Specify platform name if supported by

  18. generator.

  19. -Wdev = Enable developer warnings.

  20. -Wno-dev = Suppress developer warnings.

  21. -Werror=dev = Make developer warnings errors.

  22. -Wno-error=dev = Make developer warnings not errors.

  23. -Wdeprecated = Enable deprecation warnings.

  24. -Wno-deprecated = Suppress deprecation warnings.

  25. -Werror=deprecated = Make deprecated macro and function warnings

  26. errors.

  27. -Wno-error=deprecated = Make deprecated macro and function warnings

  28. not errors.

  29. -E = CMake command mode.

  30. -L[A][H] = List non-advanced cached variables.

  31. --build <dir> = Build a CMake-generated project binary tree.

  32. -N = View mode only.

  33. -P <file> = Process script mode.

  34. --find-package = Run in pkg-config like mode.

  35. --graphviz=[file] = Generate graphviz of dependencies, see

  36. CMakeGraphVizOptions.cmake for more.

  37. --system-information [file] = Dump information about this system.

  38. --debug-trycompile = Do not delete the try_compile build tree.

  39. Only useful on one try_compile at a time.

  40. --debug-output = Put cmake in a debug mode.

  41. --trace = Put cmake in trace mode.

  42. --trace-expand = Put cmake in trace mode with variable

  43. expansion.

  44. --warn-uninitialized = Warn about uninitialized values.

  45. --warn-unused-vars = Warn about unused variables.

  46. --no-warn-unused-cli = Don't warn about command line options.

  47. --check-system-vars = Find problems with variable usage in system

  48. files.

  49. --help,-help,-usage,-h,-H,/? = Print usage information and exit.

  50. --version,-version,/V [<f>] = Print version number and exit.

  51. --help-full [<f>] = Print all help manuals and exit.

  52. --help-manual <man> [<f>] = Print one help manual and exit.

  53. --help-manual-list [<f>] = List help manuals available and exit.

  54. --help-command <cmd> [<f>] = Print help for one command and exit.

  55. --help-command-list [<f>] = List commands with help available and exit.

  56. --help-commands [<f>] = Print cmake-commands manual and exit.

  57. --help-module <mod> [<f>] = Print help for one module and exit.

  58. --help-module-list [<f>] = List modules with help available and exit.

  59. --help-modules [<f>] = Print cmake-modules manual and exit.

  60. --help-policy <cmp> [<f>] = Print help for one policy and exit.

  61. --help-policy-list [<f>] = List policies with help available and exit.

  62. --help-policies [<f>] = Print cmake-policies manual and exit.

  63. --help-property <prop> [<f>] = Print help for one property and exit.

  64. --help-property-list [<f>] = List properties with help available and

  65. exit.

  66. --help-properties [<f>] = Print cmake-properties manual and exit.

  67. --help-variable var [<f>] = Print help for one variable and exit.

  68. --help-variable-list [<f>] = List variables with help available and exit.

  69. --help-variables [<f>] = Print cmake-variables manual and exit.

  70.  
  71. Generators

  72.  
  73. The following generators are available on this platform:

  74. Unix Makefiles = Generates standard UNIX makefiles.

  75. Ninja = Generates build.ninja files.

  76. Watcom WMake = Generates Watcom WMake makefiles.

  77. CodeBlocks - Ninja = Generates CodeBlocks project files.

  78. CodeBlocks - Unix Makefiles = Generates CodeBlocks project files.

  79. CodeLite - Ninja = Generates CodeLite project files.

  80. CodeLite - Unix Makefiles = Generates CodeLite project files.

  81. Eclipse CDT4 - Ninja = Generates Eclipse CDT 4.0 project files.

  82. Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files.

  83. KDevelop3 = Generates KDevelop 3 project files.

  84. KDevelop3 - Unix Makefiles = Generates KDevelop 3 project files.

  85. Kate - Ninja = Generates Kate project files.

  86. Kate - Unix Makefiles = Generates Kate project files.

  87. Sublime Text 2 - Ninja = Generates Sublime Text 2 project files.

  88. Sublime Text 2 - Unix Makefiles

  89. = Generates Sublime Text 2 project files.



1.生成執行程式

 
  1. project(HELLO)

  2. set(SRC_LIST main.c hello.c)

  3. add_executable(hello ${SRC_LIST})


2.生成動態庫

 
  1. project(HELLO)

  2. set(LIB_SRC hello.c)

  3. add_library(libhello STATIC ${LIB_SRC})


3.生成靜態庫

 
  1. project(HELLO)

  2. set(LIB_SRC hello.c)

  3. add_library(libhello SHARED ${LIB_SRC})

相關文章