forked from yedf2/handy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Minor CMake Cleanups * cmake_minimum_required(VERSION 3.2) CMake 3.9 isn't available on Ubuntu 16.04 - an LTS version that we still use * Fix building shared libraries * Add install targets to CMakeLists * Update README-en.md
- Loading branch information
1 parent
a45daa8
commit fc3aea3
Showing
2 changed files
with
141 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,110 @@ | ||
cmake_minimum_required(VERSION 3.9) | ||
add_definitions(-DOS_MACOSX) | ||
project(echo) | ||
cmake_minimum_required(VERSION 3.2) | ||
project(handy) | ||
|
||
include_directories("${PROJECT_SOURCE_DIR}") | ||
set(CMAKE_CXX_STANDARD 11) | ||
|
||
aux_source_directory(handy HANDY_SRCS) | ||
add_library(handy | ||
${HANDY_SRCS}) | ||
|
||
add_executable(codec-cli | ||
examples/codec-cli.cc) | ||
target_link_libraries(codec-cli handy) | ||
|
||
add_executable(codec-svr | ||
examples/codec-svr.cc) | ||
target_link_libraries(codec-svr handy) | ||
|
||
add_executable(daemon | ||
examples/daemon.cc) | ||
target_link_libraries(daemon handy) | ||
|
||
add_executable(echo | ||
examples/echo.cc) | ||
target_link_libraries(echo handy) | ||
|
||
add_executable(hsha | ||
examples/hsha.cc) | ||
target_link_libraries(hsha handy) | ||
|
||
add_executable(http-hello | ||
examples/http-hello.cc) | ||
target_link_libraries(http-hello handy) | ||
|
||
add_executable(idle-close | ||
examples/idle-close.cc) | ||
target_link_libraries(idle-close handy) | ||
|
||
add_executable(reconnect | ||
examples/reconnect.cc) | ||
target_link_libraries(reconnect handy) | ||
|
||
add_executable(safe-close | ||
examples/safe-close.cc) | ||
target_link_libraries(safe-close handy) | ||
|
||
add_executable(stat | ||
examples/stat.cc) | ||
target_link_libraries(stat handy) | ||
|
||
add_executable(timer | ||
examples/timer.cc) | ||
target_link_libraries(timer handy) | ||
|
||
add_executable(udp-cli | ||
examples/udp-cli.cc) | ||
target_link_libraries(udp-cli handy) | ||
|
||
add_executable(udp-hsha | ||
examples/udp-hsha.cc) | ||
target_link_libraries(udp-hsha handy) | ||
|
||
add_executable(udp-svr | ||
examples/udp-svr.cc) | ||
target_link_libraries(udp-svr handy) | ||
|
||
add_executable(write-on-empty | ||
examples/write-on-empty.cc) | ||
target_link_libraries(write-on-empty handy) | ||
|
||
add_executable(10m-cli | ||
10m/10m-cli.cc) | ||
target_link_libraries(10m-cli handy) | ||
|
||
add_executable(10m-svr | ||
10m/10m-svr.cc) | ||
target_link_libraries(10m-svr handy) | ||
|
||
add_executable(kqueue | ||
raw-examples/kqueue.cc) | ||
target_link_libraries(kqueue handy) | ||
|
||
include(GNUInstallDirs) | ||
|
||
find_package(Threads REQUIRED) | ||
|
||
list(APPEND HANDY_SRCS | ||
${PROJECT_SOURCE_DIR}/handy/daemon.cc | ||
${PROJECT_SOURCE_DIR}/handy/net.cc | ||
${PROJECT_SOURCE_DIR}/handy/codec.cc | ||
${PROJECT_SOURCE_DIR}/handy/http.cc | ||
${PROJECT_SOURCE_DIR}/handy/conn.cc | ||
${PROJECT_SOURCE_DIR}/handy/poller.cc | ||
${PROJECT_SOURCE_DIR}/handy/udp.cc | ||
${PROJECT_SOURCE_DIR}/handy/threads.cc | ||
${PROJECT_SOURCE_DIR}/handy/file.cc | ||
${PROJECT_SOURCE_DIR}/handy/util.cc | ||
${PROJECT_SOURCE_DIR}/handy/conf.cc | ||
${PROJECT_SOURCE_DIR}/handy/stat-svr.cc | ||
${PROJECT_SOURCE_DIR}/handy/port_posix.cc | ||
${PROJECT_SOURCE_DIR}/handy/event_base.cc | ||
${PROJECT_SOURCE_DIR}/handy/logging.cc) | ||
|
||
if(CMAKE_HOST_APPLE) | ||
add_definitions(-DOS_MACOSX) | ||
elseif(CMAKE_HOST_UNIX) | ||
add_definitions(-DOS_LINUX) | ||
else(CMAKE_HOST_APPLE) | ||
message(FATAL_ERROR "Platform not supported") | ||
endif(CMAKE_HOST_APPLE) | ||
|
||
option(BUILD_HANDY_SHARED_LIBRARY "Build Handy Shared Library" OFF) | ||
option(BUILD_HANDY_STATIC_LIBRARY "Build Handy Shared Library" ON) | ||
option(BUILD_HANDY_EXAMPLES "Build Handy Examples" OFF) | ||
|
||
##Handy Shared Library | ||
if(BUILD_HANDY_SHARED_LIBRARY) | ||
add_library(handy SHARED ${HANDY_SRCS}) | ||
target_include_directories(handy PUBLIC ${PROJECT_SOURCE_DIR}/handy) | ||
target_link_libraries(handy Threads::Threads) | ||
install(TARGETS handy DESTINATION ${CMAKE_INSTALL_LIBDIR}) | ||
endif(BUILD_HANDY_SHARED_LIBRARY) | ||
|
||
#Handy Static library | ||
if(BUILD_HANDY_STATIC_LIBRARY) | ||
add_library(handy_s STATIC ${HANDY_SRCS}) | ||
target_include_directories(handy_s PUBLIC ${PROJECT_SOURCE_DIR}/handy/) | ||
target_link_libraries(handy_s Threads::Threads) | ||
install(TARGETS handy_s DESTINATION ${CMAKE_INSTALL_LIBDIR}) | ||
endif(BUILD_HANDY_STATIC_LIBRARY) | ||
|
||
if(BUILD_HANDY_SHARED_LIBRARY OR BUILD_HANDY_STATIC_LIBRARY) | ||
install(FILES | ||
${PROJECT_SOURCE_DIR}/handy/codec.h | ||
${PROJECT_SOURCE_DIR}/handy/conf.h | ||
${PROJECT_SOURCE_DIR}/handy/conn.h | ||
${PROJECT_SOURCE_DIR}/handy/daemon.h | ||
${PROJECT_SOURCE_DIR}/handy/event_base.h | ||
${PROJECT_SOURCE_DIR}/handy/file.h | ||
${PROJECT_SOURCE_DIR}/handy/handy.h | ||
${PROJECT_SOURCE_DIR}/handy/handy-imp.h | ||
${PROJECT_SOURCE_DIR}/handy/http.h | ||
${PROJECT_SOURCE_DIR}/handy/logging.h | ||
${PROJECT_SOURCE_DIR}/handy/net.h | ||
${PROJECT_SOURCE_DIR}/handy/poller.h | ||
${PROJECT_SOURCE_DIR}/handy/port_posix.h | ||
${PROJECT_SOURCE_DIR}/handy/slice.h | ||
${PROJECT_SOURCE_DIR}/handy/stat-svr.h | ||
${PROJECT_SOURCE_DIR}/handy/status.h | ||
${PROJECT_SOURCE_DIR}/handy/threads.h | ||
${PROJECT_SOURCE_DIR}/handy/udp.h | ||
${PROJECT_SOURCE_DIR}/handy/util.h | ||
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/handy) | ||
endif(BUILD_HANDY_SHARED_LIBRARY OR BUILD_HANDY_STATIC_LIBRARY) | ||
|
||
|
||
function(add_handy_executable EXECUTABLE_NAME EXECUTABLE_SOURCES) | ||
add_executable(${EXECUTABLE_NAME} ${EXECUTABLE_SOURCES}) | ||
target_link_libraries(${EXECUTABLE_NAME} handy_s) | ||
target_include_directories(${EXECUTABLE_NAME} PUBLIC ${PROJECT_SOURCE_DIR}) | ||
install(TARGETS ${EXECUTABLE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR}) | ||
endfunction(add_handy_executable) | ||
|
||
|
||
if(BUILD_HANDY_EXAMPLES) | ||
add_handy_executable(codec-cli examples/codec-cli.cc) | ||
add_handy_executable(codec-svr examples/codec-svr.cc) | ||
add_handy_executable(daemon examples/daemon.cc) | ||
add_handy_executable(echo examples/echo.cc) | ||
add_handy_executable(hsha examples/hsha.cc) | ||
add_handy_executable(http-hello examples/http-hello.cc) | ||
add_handy_executable(idle-close examples/idle-close.cc) | ||
add_handy_executable(reconnect examples/reconnect.cc) | ||
add_handy_executable(safe-close examples/safe-close.cc) | ||
add_handy_executable(stat examples/stat.cc) | ||
add_handy_executable(timer examples/timer.cc) | ||
add_handy_executable(udp-cli examples/udp-cli.cc) | ||
add_handy_executable(udp-hsha examples/udp-hsha.cc) | ||
add_handy_executable(udp-svr examples/udp-svr.cc) | ||
add_handy_executable(write-on-empty examples/write-on-empty.cc) | ||
add_handy_executable(10m-cli 10m/10m-cli.cc) | ||
add_handy_executable(10m-svr 10m/10m-svr.cc) | ||
|
||
if(CMAKE_HOST_APPLE) | ||
add_handy_executable(kqueue raw-examples/kqueue.cc) | ||
endif(CMAKE_HOST_APPLE) | ||
endif(BUILD_HANDY_EXAMPLES) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters