forked from kevinkreiser/prime_server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
132 lines (104 loc) · 4.49 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
project(prime_server LANGUAGES CXX C)
INCLUDE(FindPkgConfig)
## Get version
file(STRINGS "${CMAKE_SOURCE_DIR}/prime_server/prime_server.hpp" version_lines REGEX "PRIME_SERVER_VERSION_(MAJOR|MINOR|PATCH)")
foreach(line ${version_lines})
if("${line}" MATCHES "(PRIME_SERVER_VERSION_(MAJOR|MINOR|PATCH))[\t ]+([0-9]+)")
set(${CMAKE_MATCH_1} ${CMAKE_MATCH_3})
endif()
endforeach()
if(DEFINED PRIME_SERVER_VERSION_MAJOR)
set(VERSION "${PRIME_SERVER_VERSION_MAJOR}")
if(DEFINED PRIME_SERVER_VERSION_MINOR)
set(VERSION "${VERSION}.${PRIME_SERVER_VERSION_MINOR}")
if(DEFINED PRIME_SERVER_VERSION_PATCH)
set(VERSION "${VERSION}.${PRIME_SERVER_VERSION_PATCH}")
endif()
endif()
else()
message(FATAL_ERROR "No prime_server major version")
endif()
# Use a C++11 enabled compiler
set(CMAKE_CXX_STANDARD 11)
# Handle the dependencies
pkg_check_modules(CURL REQUIRED libcurl>=7.22.0)
include_directories(${CURL_INCLUDE_DIR})
pkg_check_modules(ZMQ REQUIRED libzmq>=4.1.4)
include_directories(${ZMQ_INCLUDE_DIR})
pkg_check_modules(CZMQ REQUIRED libczmq>=3.0)
include_directories(${CZMQ_INCLUDE_DIR})
find_package (Threads REQUIRED)
# Include the hpp files
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/prime_server)
set(PRIME_LIBRARY_HEADERS
${CMAKE_SOURCE_DIR}/prime_server/prime_server.hpp
${CMAKE_SOURCE_DIR}/prime_server/http_util.hpp
${CMAKE_SOURCE_DIR}/prime_server/netstring_protocol.hpp
${CMAKE_SOURCE_DIR}/prime_server/logging.hpp
${CMAKE_SOURCE_DIR}/prime_server/zmq_helpers.hpp
${CMAKE_SOURCE_DIR}/prime_server/http_protocol.hpp)
set(PRIME_LIBRARY_SOURCES
${CMAKE_SOURCE_DIR}/src/http_protocol.cpp
${CMAKE_SOURCE_DIR}/src/http_util.cpp
${CMAKE_SOURCE_DIR}/src/netstring_protocol.cpp
${CMAKE_SOURCE_DIR}/src/prime_server.cpp
${CMAKE_SOURCE_DIR}/src/zmq_helpers.cpp)
# Build the library
add_library(prime_server SHARED ${PRIME_LIBRARY_SOURCES})
target_link_libraries(prime_server
${ZMQ_LIBRARIES}
${CZMQ_LIBRARIES}
${CURL_LIBRARIES})
# Build executables
add_executable(prime_echod ${CMAKE_SOURCE_DIR}/src/prime_echod.cpp)
target_link_libraries(prime_echod prime_server ${CMAKE_THREAD_LIBS_INIT})
add_executable(prime_filed ${CMAKE_SOURCE_DIR}/src/prime_filed.cpp)
target_link_libraries(prime_filed prime_server ${CMAKE_THREAD_LIBS_INIT})
add_executable(prime_httpd ${CMAKE_SOURCE_DIR}/src/prime_httpd.cpp)
target_link_libraries(prime_httpd prime_server ${CMAKE_THREAD_LIBS_INIT})
add_executable(prime_serverd ${CMAKE_SOURCE_DIR}/src/prime_serverd.cpp)
target_link_libraries(prime_serverd prime_server ${CMAKE_THREAD_LIBS_INIT})
add_executable(prime_proxyd ${CMAKE_SOURCE_DIR}/src/prime_proxyd.cpp)
target_link_libraries(prime_proxyd prime_server ${CMAKE_THREAD_LIBS_INIT})
add_executable(prime_workerd ${CMAKE_SOURCE_DIR}/src/prime_workerd.cpp)
target_link_libraries(prime_workerd prime_server ${CMAKE_THREAD_LIBS_INIT})
set_target_properties(prime_server PROPERTIES PUBLIC_HEADER "${PRIME_LIBRARY_HEADERS}")
# Install paths
set(prefix "${CMAKE_INSTALL_PREFIX}")
set(exec_prefix "${CMAKE_INSTALL_PREFIX}")
set(bindir "${CMAKE_INSTALL_PREFIX}/bin")
set(libdir "${CMAKE_INSTALL_PREFIX}/lib")
set(includedir "${CMAKE_INSTALL_PREFIX}/include/prime_server")
set(pkgconfigdir "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
install(TARGETS prime_server
LIBRARY DESTINATION ${libdir}
PUBLIC_HEADER DESTINATION ${includedir})
install(TARGETS prime_echod
prime_filed
prime_httpd
prime_serverd
prime_proxyd
prime_workerd DESTINATION ${bindir})
CONFIGURE_FILE(
"${CMAKE_CURRENT_SOURCE_DIR}/libprime_server.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/libprime_server.pc"
@ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libprime_server.pc" DESTINATION ${pkgconfigdir})
# Add tests - Requires CTest
enable_testing()
add_executable(http ${CMAKE_SOURCE_DIR}/test/http.cpp)
target_link_libraries(http prime_server ${CMAKE_THREAD_LIBS_INIT})
add_test(http http)
add_executable(interrupt ${CMAKE_SOURCE_DIR}/test/interrupt.cpp)
target_link_libraries(interrupt prime_server ${CMAKE_THREAD_LIBS_INIT})
add_test(interrupt interrupt)
add_executable(netstring ${CMAKE_SOURCE_DIR}/test/netstring.cpp)
target_link_libraries(netstring prime_server ${CMAKE_THREAD_LIBS_INIT})
add_test(netstring netstring)
add_executable(shaping ${CMAKE_SOURCE_DIR}/test/shaping.cpp)
target_link_libraries(shaping prime_server ${CMAKE_THREAD_LIBS_INIT})
add_test(shaping shaping)
add_executable(zmq ${CMAKE_SOURCE_DIR}/test/zmq.cpp)
target_link_libraries(zmq prime_server ${CMAKE_THREAD_LIBS_INIT})
add_test(zmq zmq)