CMake

Minimal example

cmake_minimum_required(<version>)
project( some_name )

add_executable(some_name src1.cxx src2.cxx)

Ako imamo neke include datoteke, kao i odvojenu bibl. da organizacija izgleda ovako:

|--CMakeLists.txt
|--include/
|   `- lib.h
|--lib/
|   `- lib.cpp
|--main.cpp
cmake_minimum_required(VERSION 3.26.3)
project(<name>)

include_directories(include/)

add_executable(<name> main.cpp lib/lib.cpp)

Ako imamo vise datoteka i svaku o njih hoćemo posebno da prevedemo. Npr. C i C++ datoteke. Dovoljno je samo da navedemo u add_executable. Primer:

# ..
project(<name> C CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -ggdb")

add_executable(<name1> name.cpp)
add_executable(<name2> name.c)
#..

Kako dodati spoljasnje biblioteke

Npr nas projekat zavisi od math, raylib, threads i drugih.

target_link_libraries(valley PRIVATE ${CMAKE_SOURCE_DIR}/lib/libimgui.a)
target_link_libraries(valley PRIVATE m) # math

Useful

set_source_files_properties - Very useful if you want to set a flag for a single file temporarily. I wouldn’t rely on it for much more than that; if you need extensive changes I would make that file it’s own target and handle it at the target level. link

https://iamsorush.com/posts/cpp-cmake-build/