Child pages
  • CMake 사용 예제

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagebash
titleCMakeLists.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)
 


Find Package

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


GNU MP

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


Code Block
##{ 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

...