欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

自用CMakeLists.txt

程序员文章站 2024-02-19 19:06:58
...

更新:

2019-6-26 最近在新学cmake,分享一个自己能理解的模板。

# cmake verison
CMAKE_MINIMUM_REQUIRED(VERSION 3.5)

# projcet name
PROJECT(demo)

# 添加预定义宏
#ADD_DEFINITIONS(-std=c++11)
ADD_DEFINITIONS(-g)

# head file path
INCLUDE_DIRECTORIES(./include ./src)

# add the source in project root directory
AUX_SOURCE_DIRECTORY(./src DIR_SRCS)

# set environment variable
SET(RUNTIME_LIB "-lpthread -lm -lz -ldl -lsqlite3")

# add executable file (编译为可执行文件)
#ADD_EXECUTABLE(${PROJECT_NAME} ${DIR_SRCS})

# add library file (编译为链接库)
ADD_LIBRARY(${PROJECT_NAME} SHARED ${DIR_SRCS})
ADD_LIBRARY(${PROJECT_NAME}_static STATIC ${DIR_SRCS})
# 将_static后缀的静态库重命名改回同名的链接库名称, CMAKE不允许出现同名的Target
SET_TARGET_PROPERTIES(${PROJECT_NAME}_static PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
# 使动态库携带版本号
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION 0.1 SOVERSION 0)

# 设置动态库输出位置
SET(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)

# add link library
TARGET_LINK_LIBRARIES(${PROJECT_NAME}
    ${RUNTIME_LIB}
    )

 

相关标签: cmake