My cmake Notes
basic
cmake build projects in three steps:
- create dir
- cmake
- make
cmake -Bbuilds
cmake --build builds
mkdir _build
cmake ../
make
mkdir _n
cd _n
cmake -G "Ninja" ..
ninja
Commands
project: set the name of project.add_subdirectory: add a subdirectory to project.install: Specify rules to run at install time- copy file to /usr/lib/, /usr/bin
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
target_source: add_executable and target_source ?add_library: Add a library to the project using the specified source files.add_executable: Add an executable to the project using the specified source files.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
target_link_libraries: Specify libraries or flags to use when linking a given target and/or its dependents.- find_package
- https://stackoverflow.com/questions/20746936/what-use-is-find-package-if-you-need-to-specify-cmake-module-path-anyway
- add_definitions
- add_definitions(-DDEBUG)
Variables
- Locations : location constant variable
- CMAKE_SOURCE_DIR
- PROJECT_BINARY_DIR
- CMAKE_CURRENT_SOURCE_DIR
- CMAKE_MODULE_PATH
- Environment Variables
- CMAKE_INCLUDE_PATH
- CMAKE_LIBRARY_PATH
- System & Compiler Information
- CMAKE_MAJOR_VERSION
- Various Options
- Compilers and Tools
- CMAKE_C_COMPILER
Advance Topic
- Custom command : mimic Makefile style
reference
- https://github.com/ttroy50/cmake-examples :star: :star: :star:
- https://github.com/Akagi201/learning-cmake :star: provide examples, but some of them don’t work.
- https://github.com/onqtam/awesome-cmake
- https://github.com/wzpan/cmake-demo
- https://github.com/xiaoweiChen/CMake-Cookbook : 一本书的翻译,其实是讲解的很清晰的了
- https://github.com/forexample/package-example : cmake 模板 ?
- https://cgold.readthedocs.io/en/latest/
-
https://64.github.io/cmake-raytracer/ : 使用 cmake 来实现 raytracing
- https://cliutils.gitlab.io/modern-cmake/
- https://learnxinyminutes.com/docs/cmake/ : 好像还不错
本站所有文章转发 CSDN 将按侵权追究法律责任,其它情况随意。