CMakeLists.txt 1.6 KB
Newer Older
羽飞's avatar
羽飞 已提交
1 2
ADD_EXECUTABLE(obclient)
MESSAGE("Begin to build " obclient)
羽飞's avatar
羽飞 已提交
3

羽飞's avatar
羽飞 已提交
4
INCLUDE(CheckCSourceCompiles)
羽飞's avatar
羽飞 已提交
5

羽飞's avatar
羽飞 已提交
6
MESSAGE(STATUS "source dir is " ${PROJECT_SOURCE_DIR})
羽飞's avatar
羽飞 已提交
7
#INCLUDE_DIRECTORIES([AFTER|BEFORE] [SYSTEM] dir1 dir2 ...)
羽飞's avatar
羽飞 已提交
8
TARGET_INCLUDE_DIRECTORIES(obclient PRIVATE . ${PROJECT_SOURCE_DIR}/../deps /usr/local/include /usr/include)
羽飞's avatar
羽飞 已提交
9 10 11
# 父cmake 设置的include_directories 和link_directories并不传导到子cmake里面
#INCLUDE_DIRECTORIES(BEFORE ${CMAKE_INSTALL_PREFIX}/include)

羽飞's avatar
羽飞 已提交
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
TARGET_LINK_DIRECTORIES(obclient PRIVATE /usr/local/lib ${PROJECT_BINARY_DIR}/../../lib)

CHECK_C_SOURCE_COMPILES("
    #include <stdio.h>
    #include <readline/readline.h>
    int main(int argc, char **argv)
    {
      return 0;
    }"
    HAVE_READLINE_HEADER)

FIND_LIBRARY(READLINE_LIBRARY readline)
IF (HAVE_READLINE_HEADER AND READLINE_LIBRARY)
    TARGET_LINK_LIBRARIES(obclient ${READLINE_LIBRARY})
    ADD_DEFINITIONS(-DUSE_READLINE)
ELSE ()
    MESSAGE ("readline is not found")
ENDIF()
羽飞's avatar
羽飞 已提交
30 31 32 33 34 35 36 37 38 39

FILE(GLOB_RECURSE ALL_SRC *.cpp)
FOREACH (F ${ALL_SRC})

    SET(PRJ_SRC ${PRJ_SRC} ${F})
    MESSAGE("Use " ${F})

ENDFOREACH (F)

# 指定目标文件位置
羽飞's avatar
羽飞 已提交
40
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../bin)
羽飞's avatar
羽飞 已提交
41
MESSAGE("Binary directory:" ${EXECUTABLE_OUTPUT_PATH})
羽飞's avatar
羽飞 已提交
42 43
TARGET_SOURCES(obclient PRIVATE ${PRJ_SRC})
TARGET_LINK_LIBRARIES(obclient common pthread dl)
羽飞's avatar
羽飞 已提交
44 45 46 47 48


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