개요 

Kitware 사에서 만든 build 를 하기위한 meta build system으로등 다양한 빌드 환경을 위한 빌드 파일을 생성하는 유틸리티로 QT 의 qmake 와 비슷한 역할 수행하며 https://github.com/Kitware/CMake 에 소스가 공개되어 있음

 

장점

  • autoconfig/automake 에 비해 사용이 편리
  • 다양한 빌드 환경 지원( Makefile, Visual Studio, Xcode )

단점

  • 문법이 맘에 안 듬(autoconf/automake 처럼 m4와 비슷한 문법)
  • 온라인 문서 품질이 낮음

 

간단 사용법

CMakeLists.txt  파일을 만들고 빌드 규칙을 기술한 후에 cmake 를 구동하면 타겟 빌드 스크립트가 생성됨.


CMakeLists.txt

## cmake 최소 필요 버전
cmake_minimum_required (VERSION 2.8)
 
## 프로젝트명
project (HELLO)

## 
set(CMAKE_BUILD_TYPE Release)
 
## -D 로 전달할 pre defined macro 가 있을 경우 사용
add_definitions(-D__MY_DEFINED__)
# Recurse into the "Hello" and "Demo" subdirectories. This does not actually cause another cmake executable to run. The same process will walk through the project's entire directory structure.
add_subdirectory (Hello)
add_subdirectory (Demo)
 
BASH


Find Package

컴파일에 필요한 라이브러리가 있는지 찾는 매크로


GNU MP

큰 수 연산을 처리하는 GMP library package. 아래 코드를 CMakeList.txt 에 넣거나 또는 CMake 의 Modules 폴더에 추가


##{ find GMP library
set(GMP_PREFIX "" CACHE PATH "The path to the prefix of a GMP installation")
find_path(GMP_INCLUDE_DIR gmp.h 
    PATHS ${GMP_PREFIX}/include /usr/include /usr/local/include)
find_library(GMP_LIBRARY NAMES gmp 
    PATHS ${GMP_PREFIX}/lib /usr/lib /usr/local/lib)
if(GMP_INCLUDE_DIR AND GMP_LIBRARY)
    get_filename_component(GMP_LIBRARY_DIR ${GMP_LIBRARY} PATH)
    set(GMP_FOUND TRUE)
endif()
if(GMP_FOUND)
   if(NOT GMP_FIND_QUIETLY)
      MESSAGE(STATUS "Found GMP: ${GMP_LIBRARY}")
   endif()
elseif(GMP_FOUND)
   if(GMP_FIND_REQUIRED)
      message(FATAL_ERROR "Could not find GMP")
   endif()
endif()
##} end
CODE

 

 

Ref