CMakeCheatsheet.txt
A small guide to creating your own library using CMake. Please note that this post is prepared for myself to remind me how to use it after a long time of forgetfulness.
project()
andcmake_minimum_required()
is mandatory.${PROJECT_NAME}
is a variable holds our project name which is decleared inproject()
command.- If you have your library files in directories, it means that you have multi-level structure. To achieve an accurate Makefile, you need to specify these directories with using
add_subdirectory()
. It should not be forgetten that each directory needs their own CMakeLists.txt files that containsadd_library()
. target_include_directory()
: It lets you to include libraries without its full path if they are marked withadd_library()
. Consider this conversion:"Adder/adder.h"
to<adder.h>
.target_link_directory()
: It creates a library inside the build folder, and a library file to use.