cmake ed

Basics ed

base ed

project
project(<project>)
# or
project(<project> VERSION 1.0)
cmake_minimum_required(VERSION 3.10)
# c++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
Creates variables

executable
add_executable(<target> a.cpp b.cpp ...)

link
target_link_libraries(<target> <PRIVATE|PUBLIC|INTERFACE> <item>...)
item:options:

configure file
configure_file(config.h.in config.h)
Replaces @<project>_VERSION@ by 1.0

include
include(<file>)
# or
include(<module>)
  • stops and processes the sub CMakeLists.txt

subdirectory
add_subdirectory(<source-dir>)
# or
add_subdirectory(<source-dir> <binary-output-dir>)
  • stops and processes the sub CMakeLists.txt

find ed

file
find_file(<var> NAMES <file1> ... [PATHS <dir1> ...] [REQUIRED])
  • looks for a file with possible (base)names in some directories
  • sets variable to full path or <var>-NOTFOUND

library
find_library(<var> NAMES <file1> ... [PATHS <dir1>] ... [REQUIRED])
  • looks for a library file with possible (base)names in some directories
  • extension???
  • sets variable to full path or <var>-NOTFOUND

package
find_package(<package> [REQUIRED] [QUIET])
  • creates variable <package>_FOUND

other ed

#define
add_compile_definitions(HAS_LIB_GTK3=1 A=B C)

variables ed

set(VAR1 13)
set(SOURCE a.cpp b.cpp c.cpp)
func_using_variables(${SOURCE})

flow control ed

if
if(<condition>)
    bla...
elseif(<condition2>)
    bla bla
else()
    bla blup
endif()

while
while(<condition>)
    ...
endwhile()

for each ...nah
foreach(<var> IN LISTS <list>)
    ...
endforeach()

conditions
  • AND, OR, NOT
  • EXISTS file
  • IS_DIRECTORY file
  • LESS, GREATER, EQUAL, STR_EQUAL

Idea ed

todo
...

Categories: Programmieren