CMake Commands
CMake Commands
Starting from v3.0, CMake commands are all in lower case SET() --> set()
Common
message([<mode>] "message to display" ...)set(<variable> <value> [[CACHE <type> <docstring> [FORCE]] | PARENT_SCOPE])unset(<variable> [CACHE | PARENT_SCOPE])option(<option_variable> "help string describing option" [initial value])export(EXPORT <export-name> [NAMESPACE <namespace>] [FILE <filename>])install(TARGETS targets... [EXPORT <export-name>] [...])file(WRITE filename "message to write"... )also READ/APPEND/...list(APPEND <list> [<element> ...])also LENGTH/FIND/INSERT/REMOVE/SORT...string(REGEX REPLACE <regular_expression> <replace_expression> <output variable><input> [<input>...])also FIND/COMPARE/LENGTH/TOLOWER...
message("words to user")
message(STATUS ${PROJECT_SOURCE_DIR}) # may be ignored by catkin build
# mode: (none), STATUS, WARNING, AUTHOR_WARNING, SEND_ERROR, FATAL_ERROR, DEPRECATION
set(CMAKE_BUILD_TYPE Release) # Debug RelWithDebInfo MinSizeRel
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
unset(ENV{LD_LIBRARY_PATH}) # <variable> can be an environment variable
option(BUILD_DOC "Build documentation" ON)
# can be overwritten by "cmake -DBUILD_DOC=OFF .."
export(TARGETS ${TEASERPP_EXPORTED_TARGETS} FILE teaserpp-exports.cmake)
install(FILES cmake/teaserppConfig.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/teaserpp)
file(STRINGS myfile.txt myfile)
# stores a list in the variable “myfile”
# in which each item is a line from the input file.
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")Flow Control
if(),elseif(),else(),endif()while(),endwhile()foreach(),endforeach()macro(),endmacro()function(),endfunction()break(),return()enable_language(<lang> [OPTIONAL] )enable_testing()
Build Target
find_file (<VAR> name1 [path1 path2 ...])find_library (<VAR> name1 [path1 path2 ...])find_package(<package> [version] [EXACT] [QUIET] [MODULE] [REQUIRED] [[COMPONENTS][components...]] [OPTIONAL_COMPONENTS components...] [NO_POLICY_SCOPE])find_path (<VAR> name1 [path1 path2 ...])find_program (<VAR> name1 [path1 path2 ...])add_compile_options(<option> ...)add_definitions(-DFOO -DBAR ...): Adds -D define flags to the compilation of source files.add_dependencies(<target> [<target-dependency>]...)add_executable(<name> source1 [source2 ...])add_library(<name> [STATIC | SHARED | MODULE] source1 [source2 ...])add_subdirectory()add_test()include_directories()for all build targetstarget_include_directories()for a specific build targettarget_link_libraries()link to a specific targetHeader-only libraries (e.g., Eigen3) are not needed to be linked here.
target_link_directories()is not encouraged to use
Build Dependencies
configure_file(<input> <output> [...])Copy a file to another location and modify its contents.execute_process(COMMAND <cmd1> [args1...]] [WORKING_DIRECTORY <directory>] [...])include(<file|module>[...])Load and run CMake code from a file or module.
cmake_minimum_required(VERSION 3.10)
project(tinyply-download NONE)
include(ExternalProject)
ExternalProject_Add(pmc
GIT_REPOSITORY https://github.com/jingnanshi/tinyply.git
GIT_TAG 0b9fff8e8bd4d37256554fe40cf76b2f3134377b
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/tinyply-src"
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/tinyply-build"
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
TEST_COMMAND ""
)Last updated
Was this helpful?