cmake 编写步骤

# 最低cmake版本
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

# 工程名
PROJECT(websocket)

# 添加头文件目录
INCLUDE_DIRECTORIES(include)

# 源文件目录
AUX_SOURCE_DIRECTORY(src DIR_SRCS)

# 头文件目录
set(INCLUDE_DIR ./include)

# 设置头文件
set(INCLUDE_FILES
    ${INCLUDE_DIR}/websocketapi.h
    ${INCLUDE_DIR}/message_queue.hpp
)

# 设置库输出目录
set(LIBRARY_OUTPUT_PATH ../lib/win32)

# 引用库包含文件目录
# INCLUDE_DIRECTORIES(${CURL_DIR}/include)


if( ANDROID )
    # 链接库文件路径
    # LINK_DIRECTORIES(${CURL_DIR}/lib/armeabi)
    # LINK_DIRECTORIES(C:/workspace/opensource/libs/boost/lib/armeabi)
    # LINK_DIRECTORIES(C:\workspace\opensource\libs\jsoncpp\lib\armeabi)
    # 链接库文件
    # link_libraries(${CURL_DIR}/lib/armeabi/libcurl.so)
    # link_libraries(C:\workspace\opensource\libs\jsoncpp\lib\armeabi\libjson.so)
elseif( WIN32 )
    # 链接库文件路径
    # LINK_DIRECTORIES(${CURL_DIR}/lib/win32)
    # LINK_DIRECTORIES(C:/workspace/opensource/libs/boost/lib/win32)
    # LINK_DIRECTORIES(C:\workspace\opensource\libs\jsoncpp\lib\win32)
    # 链接库文件
    # link_libraries(${CURL_DIR}/lib/win32/libcurl_imp.lib)
    # link_libraries(C:\workspace\opensource\libs\jsoncpp\lib\win32\libjson.dll.a)
endif()

# 添加新库
add_library(websock SHARED ${INCLUDE_FILES} ${DIR_SRCS})
add_library(websock_static STATIC ${INCLUDE_FILES} ${DIR_SRCS})

# 库文件安装目录
if( WIN32 )
     INSTALL(TARGETS websock websock_static DESTINATION ${LIBRARY_OUTPUT_PATH})
endif

 

你可能感兴趣的:(c/c++)