Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
Clone or download
CMakeLists.txt 2.78 KB
Copy Edit Web IDE Raw Blame History
夏楚 authored 2017-07-27 17:02 . 使能GOP缓存
project(ZLToolKit)
cmake_minimum_required(VERSION 2.8)
#加载自定义模块
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake")
#设置库文件路径
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
#设置可执行程序路径
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
#设置子目录
set(SUB_DIR_LIST "Network" "Poller" "Thread" "Util")
#使能GOP缓存
add_definitions(-DENABLE_RING_USEBUF)
foreach(SUB_DIR ${SUB_DIR_LIST})
#遍历源文件
aux_source_directory(src/${SUB_DIR} SRC_LIST)
#创建头文件安装文件夹
execute_process(COMMAND mkdir -p ${PROJECT_BINARY_DIR}/include/${CMAKE_PROJECT_NAME}/${SUB_DIR}/ )
#遍历头文件
file(GLOB_RECURSE HEADER_FILES "${PROJECT_SOURCE_DIR}/src/${SUB_DIR}/*.h")
#拷贝头文件至安装文件夹
execute_process(COMMAND cp ${HEADER_FILES} ${PROJECT_BINARY_DIR}/include/${CMAKE_PROJECT_NAME}/${SUB_DIR}/ )
endforeach(SUB_DIR ${SUB_DIR_LIST})
#非苹果平台移除.mm类型的文件
if(NOT APPLE)
list(REMOVE_ITEM SRC_LIST "src/Network/Socket_ios.mm")
endif(NOT APPLE)
set(LINK_LIB_LIST)
#查找openssl是否安装
find_package(OpenSSL QUIET)
if(OPENSSL_FOUND)
message(STATUS "找到openssl库:\"${OPENSSL_INCLUDE_DIR}\",ENABLE_OPENSSL宏已打开")
include_directories(${OPENSSL_INCLUDE_DIR})
add_definitions(-DENABLE_OPENSSL)
list(APPEND LINK_LIB_LIST ${OPENSSL_LIBRARIES})
endif(OPENSSL_FOUND)
#查找mysql是否安装
find_package(MYSQL QUIET)
if(MYSQL_FOUND)
message(STATUS "找到mysqlclient库:\"${MYSQL_INCLUDE_DIR}\",ENABLE_MYSQL宏已打开")
include_directories(${MYSQL_INCLUDE_DIR})
add_definitions(-DENABLE_MYSQL)
list(APPEND LINK_LIB_LIST ${MYSQL_LIBRARIES})
endif(MYSQL_FOUND)
#打印库文件
message(STATUS "将链接依赖库:${LINK_LIB_LIST}")
#引用头文件路径
include_directories(${PROJECT_SOURCE_DIR}/src)
#使能c++11
add_compile_options(-std=c++11)
add_compile_options(-Wno-deprecated-declarations)
add_compile_options(-Wno-predefined-identifier-outside-function)
#编译动态库
if(NOT IOS AND NOT ANDROID)
add_library(${CMAKE_PROJECT_NAME}_shared SHARED ${SRC_LIST})
target_link_libraries(${CMAKE_PROJECT_NAME}_shared ${LINK_LIB_LIST})
set_target_properties(${CMAKE_PROJECT_NAME}_shared PROPERTIES OUTPUT_NAME "${CMAKE_PROJECT_NAME}")
install(TARGETS ${CMAKE_PROJECT_NAME}_shared LIBRARY DESTINATION lib)
endif()
#编译静态库
add_library(${CMAKE_PROJECT_NAME}_static STATIC ${SRC_LIST})
set_target_properties(${CMAKE_PROJECT_NAME}_static PROPERTIES OUTPUT_NAME "${CMAKE_PROJECT_NAME}")
install(TARGETS ${CMAKE_PROJECT_NAME}_static ARCHIVE DESTINATION lib)
#安装头文件至系统目录
install(DIRECTORY ${PROJECT_BINARY_DIR}/include/${CMAKE_PROJECT_NAME} DESTINATION include)
#测试程序
if(NOT IOS)
add_subdirectory(tests)
endif(NOT IOS)

Comment ( 0 )

Sign in for post a comment