Documente Academic
Documente Profesional
Documente Cultură
Basics
Init/Config
cmake_minimum_version (VERSION 2.8)
project (project_name)
#if test build required
enable_testing()
#version number
set (project_name_VERSION_MAJOR 1)
set (project_name_VERSION_MINOR 0)
configure_file (
${PROJECT_SOURCE_DIR}/ProjectNameConfig.h.in"
${PROJECT_BINARY_DIR}/ProjectNameConfig.h"
)
include_directories ("${PROJECT_BINARY_DIR}")
include_directories ("${PROJECT_SOURCE_DIR}")
${EXTRA_BINCFLAGS})
#making binary
add_executable (BinaryName ${binary_name_SRCS})
target_link_libraries (BinaryName "..libs.." ${LIBS})
#installation
install (TARGETS BinaryName DESTINATION
${CMAKE_INSTALL_PREFIX})
#error while loading shared libraries: cannot open
#shared object file: No such file or directory
set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) #do this
#tests (optional)
add_test (BinaryNameTest BinaryName input_args)
#message
message ("Please do this...${var_name}")
#error message
message (FATAL_ERROR "An error occured!")
#conditional statement
if (condition)
do sth
else (condition) #condition must match
do sth else
endif (condition)
Executable(s)
#logical operators
if (A AND/OR B)
if (NOT A)
#creating an alias for a lib
add_library(<name> ALIAS <target>)
#Add a dependency between top-level targets.
add_dependencies (<target> [<target-dependency>]...)
#accessing properties e.g.
get_property(inc_dirs DIRECTORY PROPERTY
INCLUDE_DIRECTORIES)
message ("inc_dirs = ${inc_dirs}")
Details
Non standard find modules