Cmake

From Andreida
Revision as of 10:10, 11 January 2026 by Andreas (talk | contribs) (Created page with "So, what is cmake? CMake allows you to tell what should happen and cmake creates a whole lot of logic around that and makes it happen. If you want to learn how to do it: https://cmake.org/getting-started/ While creating your CMakeLists.txt you will have a lot of tries and errors normally. Ease your pain by putting a Makefile in the same folder and using this to organize the use of CMake. <pre> LIB_DIR=lib EXE_DIR=bin DIR_BUILD=build .PHONY: all all: cmake -B $(DI...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

So, what is cmake? CMake allows you to tell what should happen and cmake creates a whole lot of logic around that and makes it happen.

If you want to learn how to do it: https://cmake.org/getting-started/

While creating your CMakeLists.txt you will have a lot of tries and errors normally. Ease your pain by putting a Makefile in the same folder and using this to organize the use of CMake.

LIB_DIR=lib
EXE_DIR=bin
DIR_BUILD=build

.PHONY: all
all:
     cmake -B $(DIR_BUILD)
     cmake --build $(DIR_BUILD)

.PHONY: clean
clean:
     rm -rf $(LIB_DIR) $(EXE_DIR) $(DIR_BUILD)

 # clang-format
 .PHONY: cf
 cf:
 #   @clang-format -style=file -i include/*.h
 #   @clang-format -style=file -i *.h
 #   @clang-format -style=file -i *.cpp
     @clang-format -style=file -i *.cxx

.PHONY: list
list:
     @$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# F    inished Make data base/ {if ($$1 !~ "^[#.]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e     '^$@$$'

This will give you the options to

  • build
  • clean
  • format the code with clang-format, but perhaps you'd prefer this to be done via CMake
  • list all the options for the Makefile

Start with

make list