CMake常用命令

# CMake 最低版本號要求
cmake_minimum_required (VERSION 2.8)

# 項目信息
project (Demo1)

# 查找當前目錄下的所有源文件並將名稱保存到 DIR_SRCS 變量
aux_source_directory(. DIR_SRCS)

# 添加 math 子目錄
add_subdirectory(math)

# 指定生成目標
add_executable(Demo ${DIR_SRCS})

# 添加鏈接庫
target_link_libraries(Demo MathFunctions)

# 生成鏈接庫
add_library (MathFunctions ${DIR_LIB_SRCS})

# 加入一個配置頭文件,用於處理 CMake 對源碼的設置
configure_file (
  "${PROJECT_SOURCE_DIR}/config.h.in"
  "${PROJECT_BINARY_DIR}/config.h"
  )
  
# 是否使用自己的 MathFunctions 庫
option (USE_MYMATH
       "Use provided math implementation" ON)

# 是否加入 MathFunctions 庫
if (USE_MYMATH)
  include_directories ("${PROJECT_SOURCE_DIR}/math")
  add_subdirectory (math)  
  set (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions)
endif (USE_MYMATH)

# 檢查系統是否支持 pow 函數
include (${CMAKE_ROOT}/Modules/CheckFunctionExists.cmake)
check_function_exists (pow HAVE_POW)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章