Recently, I encountered many predefined variables in writing CMakeLists, so I hereby record them for future reference.

The file structure is as follows:

  

Common path variables

PROJECT_NAME: The PROJECT name specified by PROJECT

    project(Demo)
Copy the code

PROJECT_SOURCE_DIR: The root directory of the project, the Demo directory in the figure above

PROJECT_BINARY_DIR: the directory where the cmake command is executed, usually in the build directory, where cmake..

CMAKE_CURRENT_SOURCE_DIR: directory where the current cmakelists. TXT file resides

CMAKE_CURRENT_BINARY_DIR: target Compile directory, which can be modified using ADD_SUBDIRECTORY

ADD_SUBDIRECTORY(example)Copy the code

EXECUTABLE_OUTPUT_PATH: Redefines the output location of the target link library file

Executables (EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)Copy the code

LIBRARY_OUTPUT_PATH: library file output location

    set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
Copy the code

Common system information variables

CMAKE_MAJOR_VERSION: cmake major version number 3 in Cmake Version 3.11.2

CMAKE_MINOR_VERSION: the second version of cmake, 11 in Cmake Version 3.11.2

CMAKE_PATCH_VERSION: the patch level of Cmake is 2 in Cmake Version 3.11.2

  

CMAKE_SYSTEM: system name with version number

CMAKE_SYSTEM_NAME: indicates the system name without the version number

CMAKE_SYSTEM_VERSION: indicates the system version

CMAKE_SYSTEM_PROCESSOR: processor name

Compilation options:

BUILD_SHARED_LIBS: specifies the type of the library to be compiled (shared or static) by default

CMAKE_C_FLAGS: Sets C compilation options

CMAKE_CXX_FLAGS: sets C++ compilation options

CMAKE_CXX_FLAGS_DEBUG: Sets compilation options when compilation type is Debug

CMAKE_CXX_FLAGS_RELEASE: Sets compilation options when compilation type is Release

CMAKE_CXX_COMPILER: sets the C++ compiler

Set the C++ compiler to g++set(CMAKE_CXX_COMPILER "g++") # set the library version to c++17And turn on the warningset(CMAKE_CXX_FLAGS "-std=c++17 -Wall"Set Debug mode, do not enable optimization, enable debugging, generate more detailed GDB debugging informationset(CMAKE_CXX_FLAGS_DEBUG "-O0 -g -ggdb") # Set Release mode to enable the highest level of optimizationset(CMAKE_CXX_FLAGS_RELEASE "-O3")
Copy the code

The introduction of predefined variables commonly used in CMakeLists is complete.