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

3
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
羽飞's avatar
羽飞 已提交
4 5

FILE(GLOB_RECURSE ALL_SRC *.cpp *.c)
羽飞's avatar
羽飞 已提交
6
SET(MAIN_SRC main.cpp)
羽飞's avatar
羽飞 已提交
7 8 9 10 11 12 13 14 15 16 17
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
羽飞 已提交
18 19 20 21 22 23
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
羽飞 已提交
24 25

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

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

ADD_LIBRARY(observer_static STATIC ${LIB_SRC})
35 36 37 38 39 40 41 42 43 44 45
INCLUDE (readline)
MINIOB_FIND_READLINE()
IF (HAVE_READLINE)
    TARGET_LINK_LIBRARIES(observer_static ${READLINE_LIBRARY})
    TARGET_INCLUDE_DIRECTORIES(observer_static PRIVATE ${READLINE_INCLUDE_DIR})
    ADD_DEFINITIONS(-DUSE_READLINE)
    MESSAGE ("observer_static use readline")
ELSE ()
    MESSAGE ("readline is not found")
ENDIF()

羽飞's avatar
羽飞 已提交
46 47
SET_TARGET_PROPERTIES(observer_static PROPERTIES OUTPUT_NAME observer)
TARGET_LINK_LIBRARIES(observer_static ${LIBRARIES})
羽飞's avatar
羽飞 已提交
48 49 50 51

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