C++: 使用cmake构造项目

一. 项目结构

二. CMakeLists.txt文件说明

# CMake 最低版本号要求
cmake_minimum_required (VERSION 3.10)

# 项目信息
project (pro)

SET(CMAKE_BUILD_TYPE "Release")

# 使用c++11
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -w")

# 设置源文件
aux_source_directory(./common PROJECT_SRC)
aux_source_directory(./unit PROJECT_SRC)

# 添加头文件搜索目录
include_directories(
    PUBLIC ./
    PUBLIC ../share/include
)

# 添加链接库搜索目录
link_directories(
    ../share/lib
)

# 指定生成目标
add_executable(pro main.cpp ${PROJECT_SRC})

# 添加链接库
target_link_libraries(pro
    crypto
    dl
)
 
# 指定安装路径
install (TARGETS pro DESTINATION ${CMAKE_CURRENT_SOURCE_DIR}/../public/bin)

三. 编译以及安装

cd public/build
cmake ../../pro/.

Author: jhonse

Jhonse技术博客: http://blog.jhonse.com

Leave a Reply

Your email address will not be published. Required fields are marked *