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

羽飞's avatar
羽飞 已提交
3 4
INCLUDE_DIRECTORIES(. ${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/deps /usr/local/include)
LINK_DIRECTORIES(/usr/local/lib)
羽飞's avatar
羽飞 已提交
5 6

FILE(GLOB_RECURSE ALL_SRC *.cpp *.c)
羽飞's avatar
羽飞 已提交
7
SET(MAIN_SRC main.cpp)
羽飞's avatar
羽飞 已提交
8 9 10 11 12 13 14 15 16 17 18
MESSAGE("MAIN SRC: " ${MAIN_SRC})
FOREACH (F ${ALL_SRC})

    IF (NOT ${F} STREQUAL ${MAIN_SRC})
        SET(LIB_SRC ${LIB_SRC} ${F})
    ENDIF()

    MESSAGE("Use " ${F})

ENDFOREACH (F)

羽飞's avatar
羽飞 已提交
19 20 21 22 23 24
SET(LIBEVENT_STATIC_LINK TRUE)
FIND_PACKAGE(Libevent CONFIG REQUIRED)

# JsonCpp cannot work correctly with FIND_PACKAGE

SET(LIBRARIES common pthread dl libevent::core libevent::pthreads libjsoncpp.a)
羽飞's avatar
羽飞 已提交
25 26

# 指定目标文件位置
羽飞's avatar
羽飞 已提交
27
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
羽飞's avatar
羽飞 已提交
28
MESSAGE("Binary directory:" ${EXECUTABLE_OUTPUT_PATH})
羽飞's avatar
羽飞 已提交
29
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
羽飞's avatar
羽飞 已提交
30
MESSAGE("Archive directory:" ${LIBRARY_OUTPUT_PATH})
羽飞's avatar
羽飞 已提交
31 32 33 34 35 36 37

ADD_EXECUTABLE(observer ${MAIN_SRC})
TARGET_LINK_LIBRARIES(observer observer_static)

ADD_LIBRARY(observer_static STATIC ${LIB_SRC})
SET_TARGET_PROPERTIES(observer_static PROPERTIES OUTPUT_NAME observer)
TARGET_LINK_LIBRARIES(observer_static ${LIBRARIES})
羽飞's avatar
羽飞 已提交
38 39 40 41

# Target 必须在定义 ADD_EXECUTABLE 之后, programs 不受这个限制
# TARGETS和PROGRAMS 的默认权限是OWNER_EXECUTE, GROUP_EXECUTE, 和WORLD_EXECUTE,即755权限, programs 都是处理脚本类
# 类型分为RUNTIME/LIBRARY/ARCHIVE, prog
羽飞's avatar
羽飞 已提交
42
INSTALL(TARGETS observer observer_static 
羽飞's avatar
羽飞 已提交
43 44
    RUNTIME DESTINATION bin
    ARCHIVE DESTINATION lib)