Skip to the content.

My cmake Notes

basic

cmake build projects in three steps:

  1. create dir
  2. cmake
  3. make
cmake -Bbuilds
cmake --build builds

mkdir _build
cmake ../
make

mkdir _n
cd _n
cmake -G "Ninja" ..
ninja

Commands

  1. project : set the name of project.
  2. add_subdirectory : add a subdirectory to project.
  3. install : Specify rules to run at install time
    • copy file to /usr/lib/, /usr/bin
  4. set : Set a normal, cache, or environment variable to a given value.
    • Multi-item variable : https://stackoverflow.com/questions/31037882/whats-the-cmake-syntax-to-set-and-use-variables
  5. target_source : add_executable and target_source ?
  6. add_library : Add a library to the project using the specified source files.
  7. add_executable : Add an executable to the project using the specified source files.
  8. include_directories : Add include directories to the build.
    • CMAKE_INCLUDE_CURRENT_DIR : automatically add the current source and build directories to the include path.
    • target_include_directories : https://stackoverflow.com/questions/31969547/what-is-the-difference-between-include-directories-and-target-include-directorie
  9. target_link_libraries : Specify libraries or flags to use when linking a given target and/or its dependents.
  10. find_package
  1. add_definitions
    • add_definitions(-DDEBUG)

Variables

  1. Locations : location constant variable
    • CMAKE_SOURCE_DIR
    • PROJECT_BINARY_DIR
    • CMAKE_CURRENT_SOURCE_DIR
    • CMAKE_MODULE_PATH
  2. Environment Variables
    • CMAKE_INCLUDE_PATH
    • CMAKE_LIBRARY_PATH
  3. System & Compiler Information
    • CMAKE_MAJOR_VERSION
  4. Various Options
  5. Compilers and Tools
    • CMAKE_C_COMPILER

Advance Topic

  1. Custom command : mimic Makefile style

reference

本站所有文章转发 CSDN 将按侵权追究法律责任,其它情况随意。