CMake
Useful CMake commands
cmake -S . -B build : create build cache
cmake --build build : build the app
My CMake config
Tree
root
|-src
| |-CMakeLists.txt
| |-<source_files>
|-CMakeLists.txt
CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(<project_name>)
# Exports compile commands to use nvim autocompletion
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
# Add subdirectories for src and libs
add_subdirectory(src)
src/CMakeLists.txt
# src files
set(SRC "./main.c")
add_executable(${PROJECT_NAME} ${SRC})
# Link libraries
target_link_libraries(${PROJECT_NAME} PRIVATE <lib> ...)
add_compile_options(-Wall -Wextra)