CMake:Variables
CMake에서 사용되는 변수 목록을 나열한다.
Category
- CMake
- CMakeLists.txt
- CMake:Modules
- CMake:Test (CTest)
- CMake:Pack (CPack)
- CMake:Policies
- CMake:Example
- CMake:Troubleshooting
변수가 할당되지 않아있을 경우
CMAKE_STATIC_LIBRARY_PREFIX
와 같은 변수 값이 할당되어 있지 않다면 project()
명령을 호출한 후 사용하면 된다.
List of variables
- CMAKE_<LANG>_COMPILER_ID
- Stackoverflow: In cmake, how can I test if the compiler is Clang?
- CMake » 3.0.2 Documentation » cmake-variables(7) » CMAKE_<LANG>_COMPILER_ID
- 컴파일러 ID(문자열)을 획득할 수 있다. <span style="text-color:red;">(
enable_language()
를 통하여 컴파일러 검색이 완료되어야 한다.)
- CXX_STANDARD
- Stackoverflow: How to activate C++ 11 in CMake?
- CMake » 3.1.3 Documentation » cmake-properties(7) » CXX_STANDARD
- CMake » 3.1.3 Documentation » cmake-commands(7) » target_compile_features
- CMAKE_PROGRAM_PATH
-
LIST(APPEND CMAKE_PROGRAM_PATH "c:/MyProject/Tools/mingw/bin/" ...)
와 같이 추가할 수 있다. - CMake에서 사용하는, 실행파일을 검색할 PATH목록.
- CMAKE_LIBRARY_PATH
- CMake에서 사용하는, 링커에 적용할 LIBRARY_PATH목록.
- CMAKE_COMMAND
- 전체 경로를 포함한 cmake 명령.
- CMAKE_EXECUTABLE_SUFFIX
- 실행파일 확장자. (Win32는
.exe
에 해당한다)
- CMAKE_STATIC_LIBRARY_PREFIX
- 정적 라이브러리 Prefix. (Unix는
lib
)
- CMAKE_STATIC_LIBRARY_SUFFIX
- 정적 라이브러리 Suffix. (Unix는
.a
)
- BUILD_SHARED_LIBS
- ON일 경우 공유 라이브러리로 빌드하고, OFF일 경우 정적 라이브러리로 빌드한다.
- CMAKE_VERBOSE_MAKEFILE
- ON일 경우 상세 빌드 메시지를 출력한다. (
make VERBOSE=1
)
- CMAKE_BUILD_TYPE
- 빌드 타입 (Debug, Release, RelWithDebInfo, MinSizeRel)
- CMAKE_INSTALL_PREFIX
- make install 명령으로 설치할 경로를 설정한다.
- CMAKE_INCLUDE_PATH
- This is used when searching for include files. (e.g. using the
FIND_PATH()
command)
- CMAKE_LIBRARY_PATH
- This is used when searching for libraries. (e.g. using the
FIND_LIBRARY()
command)
- CMAKE_PREFIX_PATH
- (since CMake 2.6.0) This is used when searching for include files, binaries, or libraries using either the
FIND_PACKAGE()
,FIND_PATH()
,FIND_PROGRAM()
, orFIND_LIBRARY()
commands.
- CMAKE_PREFIX_PATH
- ???
- CMAKE_C_FLAGS
CMAKE_CXX_FLAGS - Stackoverflow: cmake CFLAGS CXXFLAGS modification
- CC & C++ 명령어 플래그
- CMAKE_CXX_COMPILER
- CXX compiler.
- PROJECT_SOURCE_DIR
- CMakeLists.txt가 존재하는 디렉토리.
- PROJECT_BINARY_DIR
- 실제 빌드 작업이 진행되는 디렉토리.
- CMAKE_MACOSX_RPATH
- CMake » 3.0.2 Documentation » cmake-properties(7) » MACOSX_RPATH
- Whether to use rpaths on Mac OS X.
- This variable is used to initialize the MACOSX_RPATH1 property on all targets.
- CMAKE_INSTALL_NAME_DIR
- Mac OS X directory name for installed targets.
- CMAKE_INSTALL_NAME_DIR is used to initialize the INSTALL_NAME_DIR property on all targets. See that target property for more information.
- CMAKE_CXX_EXTENSIONS
- Compile Feature Requirements
- Default value for CXX_EXTENSIONS property of targets.
- CMAKE_CXX_STANDARD
- Default value for CXX_STANDARD property of targets. Supported values are 98, 11 and 14.
- CMAKE_CXX_STANDARD_REQUIRED
- Boolean describing whether the value of CXX_STANDARD is a requirement.
- CMAKE_POSITION_INDEPENDENT_CODE
- ON일 경우
-fPIC
를 정용한다.
- CMAKE_CURRENT_LIST_FILE
- this is the full path to the listfile currently being processed.
- CMAKE_CURRENT_LIST_DIR
- (since 2.8.3) this is the directory of the listfile currently being processed.
- CMAKE_CURRENT_LIST_LINE
- this is linenumber where the variable is used.
- CMAKE_CURRENT_SOURCE_DIR
- this is the directory where the currently processed CMakeLists.txt is located in
- CMAKE_CL_64
- Set to true when using the 64 bit cl compiler from Microsoft.
- CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS
- Windows에서 전체 심볼을 Export할 것인지 여부를 적용한다.
CMake Directory Variables
SOURCE_DIR Variables
These variables contain the paths to various source code directories. Note how every one of them refers to a directory that contains a CMakeLists.txt file.
- CMAKE_SOURCE_DIR
- The path to the top level of the source tree. This is the directory that contains the top-level CMakeLists.txt file. That is, this is the source directory you specify to the cmake command.
- CMAKE_CURRENT_SOURCE_DIR
- The path to the directory containing the CMakeLists.txt file that is currently being processed.
- PROJECT_SOURCE_DIR
- Top level source directory for the current project. Not every CMakeLists.txt file defines a project–this is the directory that contains the most recent CMakeLists.txt file that defined a project.
- projectName_SOURCE_DIR
- Source directory for the named project. This is the directory that contains the CMakeLists.txt file that contains the project(projectName) definition. Every CMakeLists.txt file need not define a project, but one reason to define a project is to create this variable so you can refer to its source files later, in other CMakeLists.txt files.
BINARY_DIR Variables
The build tree will contain a directory hierarchy corresponding to the hierarchy of directories in the source tree containing CMakeLists.txt files. Each of the following variables refers to a directory in the build tree corresponding to a source tree directory that contains a CMakeLists.txt file.
- CMAKE_BINARY_DIR
- The path to the top level of the build tree. This is the directory in which you ran the cmake command.
- CMAKE_CURRENT_BINARY_DIR
- The path to the binary directory currently being processed. When an add_subdirectory command is encountered in a CMakeLists.txt file, a corresponding directory is created in the build directory. This variable contains that subdirectory.
- PROJECT_BINARY_DIR
- Top level binary directory for the current project. Not every CMakeLists.txt file defines a project–this is the directory in the build tree that corresponds to the most recent CMakeLists.txt file that defined a project.
- projectName_BINARY_DIR
- Binary directory for the named project. This is the directory in the build tree that corresponds to the CMakeLists.txt file that contains a project(projectName) definition. Every CMakeLists.txt file need not define a project, but one reason to define a project is to create this variable so you can refer to its binary files later, in other CMakeLists.txt files.
Environment Variables
환경변수 설정은 아래와 같이 적용할 수 있다.
Runtime output directories
As in Oleg's answer, I believe the correct variable to set is CMAKE_RUNTIME_OUTPUT_DIRECTORY. we use the following in our root CMakeLists.txt:
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
You can also specify the output directories on a per target basis:
set_target_properties( targets...
PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
)
In both cases you can append _[CONFIG] to the variable/property name to make the output directory apply to a specific configuration (the standard values for config are DEBUG, RELEASE, MINSIZEREL and RELWITHDEBINFO).
Read cmake variable in bash script
Bash 스크립트에서 cmake 변수를 읽는 방법은 아래와 같다.
Favorite site
References
-
When this property is set to true, the directory portion of the “install_name” field of shared libraries will be @rpath unless overridden by INSTALL_NAME_DIR. Runtime paths will also be embedded in binaries using this target and can be controlled by the INSTALL_RPATH target property. ↩