======Programming - Build Systems - cmake - Notes======
=====Using=====
If you see a CMakeLists.txt in the source tree, and there is no documentation on how to compile, the following ususally works relative to the directory with the CMakeLists.txt:
mkdir build
cd build
cmake ../
=====Adding include dirs when calling cmake=====
If cmake does not find certain include dirs on it's own, and you don't want to start editing cmake config files, you can expand the list of directories to search for include files when running cmake.
cmake -DCMAKE_CXX_FLAGS=-isystem\ /path/to/my/include
Source:[[https://stackoverflow.com/questions/25849571/adding-include-directories-to-cmake-when-calling-it-from-the-command-line|stack overflow - Adding include directories to CMake when calling it from the command line]]
=====Adding linker flags when calling cmake=====
cmake -DCMAKE_SHARED_LINKER_FLAGS="-fstack-protector" /path/to/source
Source: [[https://stackoverflow.com/questions/24532853/how-can-i-add-linker-flag-for-libraries-with-cmake|stack overlfow - How can I add linker flag for libraries with CMake?]]
=====Adding compiler flags when calling cmake=====
cmake -DCMAKE_C_FLAGS="-lm"
When compiling C++:
cmake -DCMAKE_CXX_FLAGS="-lm"
Source:[[https://stackoverflow.com/questions/11783932/how-do-i-add-a-linker-or-compile-flag-in-a-cmake-file|stack overflow - How do I add a linker or compile flag in a CMake file?]]