@nrailgun
2015-11-19T19:08:34.000000Z
字数 588
阅读 1985
强力软件
编译一个项目时候恰好需要使用 CMake,决定看一下。
项目信息:
cmake_minimum_required(VERSION 2.6)
project(Tutorial)
set(Tutorial_VERSION_MAJOR 3)
set(Tutorial_VERSION_MINOR 14)
选项:
option(USE_MYMATH "use my sqrt" OFF)
if (USE_MYMATH)
# Whatever
endif(USE_MYMATH)
配置文件:
configure_file(
"${PROJECT_SOURCE_DIR}/TutorialConfig.h.in"
"${PROJECT_BINARY_DIR}/TutorialConfig.h"
)
包括子文件夹:
include_directories("${PROJECT_BINARY_DIR}")
添加子文件夹:
add_subdirectory(MathFunctions)
设定变量:
set(EXTRA_LIBS ${EXTRA_LIBS} MathFunctions)
建立库:
add_library(MathFunctions MathFunctions.cxx)
编译链接:
add_executable(a.out main.cpp)
target_link_libraries(a.out ${EXTRA_LIBS})