projectIt can be used to specify the name of the project and the supported languages, all languages are supported by default. eg. project(HELLO),project(HELLO CXX)
setUsed to explicitly specify variables, eg.set(SRC_LIST main.cpp)
messageOutput user-defined information to the terminal, mainly including three kinds of information:
SEND_ERROR, an error occurred, the generation process was skipped
SATUS, output information prefixed with —
FATAL_ERROR, terminate all cmake processes immediately
eg. message(STATUS "This is SOURCE dir "${HELLO_SOURCE_DIR})
add_executableGenerate an executable file, eg. ADD_EXECUTABLE(hello ${SRC_LIST})The name of the generated executable file is hello, the source file reads the contents of the variable SRC_LIST, or directly writesADD_EXECUTABLE(hello main.cpp)
add_subdirectoryIt is used to add a subdirectory for storing source files to the current project, and can specify the storage location of intermediate binary and target binary. eg. ADD_SUBDIRECTORY(src bin)Add the src subdirectory to the project and specify the compilation output (including compilation intermediate results) path as the bin directory; if no bin directory is specified, then the compilation results (including intermediate results) will be stored in the build/src directory.
include_directoriesCan be used to add multiple specific header file search paths to the project, separated by spaces. e.g.INCLUDE_DIRECTORIES(/usr/include/hello)
The set command redefines the executable_output_path and library_output_path variables to specify the location of the final target binary.
target_link_libraries(可执行文件名 链接库路径)It needs to be placed add_executableafter it to specify what dynamic library the exe file should be linked with after it is generated. e.g.target_link_libraries(motionaveraging /home/dz/cnpy/build/libcnpy.so)
other
The variable is used to ${}get the value, but the variable name is directly used in the IF control statement
Instructions (parameter 1 parameter 2...) Parameters are enclosed in brackets and separated by spaces or semicolons
Instructions are case-insensitive, parameters and variables are case-insensitive
SET(SRC_LIST main.cpp)It can be written as SET(SRC_LIST “main.cpp”), if the source file name contains spaces, double quotes must be added
The suffix of ADD_EXECUTABLE(hello main) can be omitted, it will automatically find .c and .cpp, it is best not to write this way, there may be two files main.cpp and main
To create subdirectories, each directory needs to have a CMakeLists.txt description