1.添加路径
add_subdirectory("replay")
2.添加执行程序
add_executable(replay "replay.cc")
3.设置项目文件路径
set_target_properties(replay PROPERTIES FOLDER replay)
4.设置依赖库
target_link_litraries(replay sc2api)
5.编译库
file(GLOB sources_replay "replay/*.cpp" "replay/.cc" "replay/*.h")
add_library(replay sources_replay)
5.添加依赖库头文件路径
link_directories(${BOOST_ROOT}/include)
6.查找依赖库
SET(BOOST_COMPONENTS)
LIST(APPEND BOOST_COMPONENTS thread
date_time
system
filesystem
program_options
signals
serialization
chrono
unit_test_framework
context
locale
coroutine)
FIND_PACKAGE(Boost 1.60 REQUIRED COMPONENTS ${BOOST_COMPONENTS})
7.设置编译版本
add_compile_options(-std=c++11)
8.设置库文件编译属性
set_target_properties(${target} PROPERTIES LINKER_LANGUAGE CXX)
9.cmake 输出错误信息,
message(FATAL_ERROR " please set MYSQLCPP_ROOT_DIR")
10.find_library
find_library(mysql_libs mysqlcppconn ${MYSQLCPP_ROOT_DIR})
11.设置编译语言
SET_TARGET_PROPERTIES(libbbbb PROPERTIES LINKER_LANGUAGE C)
12.引入*.cmake
SET(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
include(xxxxxx)
14.添加宏参数
add_definitions(-DBITPRIM_CURRENCY_BCH)
15.自定义宏
macro(add_design_path path)
file(GLOB souce_file "mode/${path}/*.hpp" "mode/${path}/*.cpp")
add_executable("${path}" ${souce_file})
target_include_directories(${path} PUBLIC "mode/${path}")
endmacro()
16.foreach
set(design_path
factory)
foreach(path ${design_path})
add_design_path(${path})
endforeach()
17.获取执行命令
execute_process(
COMMAND git log -1 --format=%H
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE GIT_VERSION
)
string (REGEX REPLACE "[\n\t\r]" "" GIT_VERSION ${GIT_VERSION})