CMakeLists.txt 1.5 KB
Newer Older
羽飞's avatar
羽飞 已提交
1 2 3
MESSAGE(STATUS "This is PROJECT_BINARY_DIR dir " ${PROJECT_BINARY_DIR})
MESSAGE(STATUS "This is PROJECT_SOURCE_DIR dir " ${PROJECT_SOURCE_DIR})

羽飞's avatar
羽飞 已提交
4
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/deps)
羽飞's avatar
羽飞 已提交
5 6 7 8 9 10 11 12 13

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

#SHARED,动态库
#STATIC,静态库
14
ADD_LIBRARY(common STATIC ${ALL_SRC} )
羽飞's avatar
羽飞 已提交
15 16 17 18

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

羽飞's avatar
羽飞 已提交
19
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
羽飞's avatar
羽飞 已提交
20 21 22
# Target 必须在定义 ADD_EXECUTABLE 之后, programs 不受这个限制
# TARGETS和PROGRAMS 的默认权限是OWNER_EXECUTE, GROUP_EXECUTE, 和WORLD_EXECUTE,即755权限, programs 都是处理脚步类
# 类型分为RUNTIME/LIBRARY/ARCHIVE, prog
23
INSTALL(TARGETS common
羽飞's avatar
羽飞 已提交
24 25 26 27 28 29 30 31 32 33
        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)
羽飞's avatar
羽飞 已提交
34
    MESSAGE("Install " ${RELAPATH_HEADER} " to " ${CMAKE_INSTALL_PREFIX} "/" common "/include/" ${headDir})
羽飞's avatar
羽飞 已提交
35
    INSTALL(FILES ${RELAPATH_HEADER} DESTINATION include/${headDir})
36
ENDFOREACH(F)