CMakeLists.txt 2.1 KB
Newer Older
羽飞's avatar
羽飞 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

PROJECT(common)
MESSAGE("Begin to build " ${PROJECT_NAME})
MESSAGE(STATUS "This is PROJECT_BINARY_DIR dir " ${PROJECT_BINARY_DIR})
MESSAGE(STATUS "This is PROJECT_SOURCE_DIR dir " ${PROJECT_SOURCE_DIR})

INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/..)
#find_file() 只会找一个文件
#AUX_SOURCE_DIRECTORY(. SRC_LIST)
#FOREACH(F ${SRC_LIST})
#    MESSAGE(${F})
#ENDFOREACH(F)

FILE(GLOB_RECURSE ALL_SRC  *.cpp)
FOREACH(F ${ALL_SRC})
    SET(SRC_LIST ${SRC_LIST} ${F})
    MESSAGE("Use " ${F})
ENDFOREACH(F)


#SHARED,动态库
#STATIC,静态库
23
ADD_LIBRARY(common STATIC ${ALL_SRC} )
羽飞's avatar
羽飞 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

# 编译静态库时,自动会把同名的动态库给删除, 因此需要临时设置一下
SET_TARGET_PROPERTIES(common PROPERTIES CLEAN_DIRECT_OUTPUT 1)

# 设置版本号 VERSION指代动态库版本,SOVERSION指代API版本

SET(MAIJOR_VER 1)
SET(MINOR_VER  0)
SET(PATCH_VER  0)
SET(OTHER_VER  1)
ADD_DEFINITIONS(-DMAIJOR_VER=${MAIJOR_VER} -DMINOR_VER=${MINOR_VER} -DPATCH_VER=${PATCH_VER} -DOTHER_VER=${OTHER_VER})

SET_TARGET_PROPERTIES(common PROPERTIES VERSION ${MAIJOR_VER}.${MINOR_VER}.${PATCH_VER} SOVERSION ${MAIJOR_VER})

SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../../lib)
# Target 必须在定义 ADD_EXECUTABLE 之后, programs 不受这个限制
# TARGETS和PROGRAMS 的默认权限是OWNER_EXECUTE, GROUP_EXECUTE, 和WORLD_EXECUTE,即755权限, programs 都是处理脚步类
# 类型分为RUNTIME/LIBRARY/ARCHIVE, prog
42
INSTALL(TARGETS common
羽飞's avatar
羽飞 已提交
43 44 45 46 47 48 49 50 51 52 53 54
        LIBRARY DESTINATION lib
        ARCHIVE DESTINATION lib)

# 小心 安装的时候,不要变成include/func.h, 如果这样,第二次安装的时候会变成include/func.h/func.h
# INSTALL(FILES func.h DESTINATION include/)

FILE(GLOB_RECURSE ALL_HEADER  *.h)
FOREACH(F ${ALL_HEADER})
    file(RELATIVE_PATH RELAPATH_HEADER ${PROJECT_SOURCE_DIR} ${F}) # 获取相对路径
    get_filename_component(headDir ${RELAPATH_HEADER} DIRECTORY)
    MESSAGE("Install " ${RELAPATH_HEADER} " to " ${CMAKE_INSTALL_PREFIX} "/" ${PROJECT_NAME} "/include/" ${headDir})
    INSTALL(FILES ${RELAPATH_HEADER} DESTINATION include/${headDir})
55
ENDFOREACH(F)