1
- CMAKE_MINIMUM_REQUIRED (VERSION 3.2 )
2
- PROJECT (trantor )
1
+ cmake_minimum_required (VERSION 3.2 )
2
+ project (Trantor )
3
+
4
+ set (TRANTOR_MAJOR_VERSION 1 )
5
+ set (TRANTOR_MINOR_VERSION 0 )
6
+ set (TRANTOR_PATCH_VERSION 0 )
7
+ set (TRANTOR_VERSION
8
+ ${TRANTOR_MAJOR_VERSION} .${TRANTOR_MINOR_VERSION}.${TRANTOR_PATCH_VERSION} )
9
+
10
+ # Offer the user the choice of overriding the installation directories
11
+ set (INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries" )
12
+ set (INSTALL_INCLUDE_DIR include CACHE PATH
13
+ "Installation directory for header files" )
14
+ if (WIN32 AND NOT CYGWIN )
15
+ set (DEF_INSTALL_TRANTOR_CMAKE_DIR cmake )
16
+ else ()
17
+ set (DEF_INSTALL_TRANTOR_CMAKE_DIR lib/cmake/Trantor )
18
+ endif ()
19
+ set (INSTALL_TRANTOR_CMAKE_DIR ${DEF_INSTALL_TRANTOR_CMAKE_DIR} CACHE PATH
20
+ "Installation directory for cmake files" )
21
+
22
+ # Make relative paths absolute (needed later on)
23
+ foreach (p LIB INCLUDE TRANTOR_CMAKE )
24
+ set (var INSTALL_${p}_DIR )
25
+ if (NOT IS_ABSOLUTE "${${var} }" )
26
+ set (${var} "${CMAKE_INSTALL_PREFIX} /${${var} }" )
27
+ endif ()
28
+ endforeach ()
3
29
4
30
# include directories
5
- INCLUDE_DIRECTORIES (
31
+ include_directories (
6
32
${PROJECT_SOURCE_DIR}
7
33
${PROJECT_SOURCE_DIR} /trantor/utils
8
34
${PROJECT_SOURCE_DIR} /trantor/net
9
35
${PROJECT_SOURCE_DIR} /trantor/net/inner
10
- /usr/local/include
11
- /usr/include
12
36
)
13
37
14
38
# lib directories
15
- LINK_DIRECTORIES (
16
- ${PROJECT_BINARY_DIR} /
17
- /usr/local/lib
18
- /usr/lib
19
- )
20
-
21
- SET (public_net_headers
22
- trantor/net/EventLoop.h
23
- trantor/net/EventLoopThread.h
24
- trantor/net/EventLoopThreadPool.h
25
- trantor/net/InetAddress.h
26
- trantor/net/TcpClient.h
27
- trantor/net/TcpConnection.h
28
- trantor/net/TcpServer.h
29
- trantor/net/callbacks.h )
30
-
31
- SET (public_utils_headers
32
- trantor/utils/AsyncFileLogger.h
33
- trantor/utils/ConcurrentTaskQueue.h
34
- trantor/utils/Date.h
35
- trantor/utils/Funcs.h
36
- trantor/utils/LockFreeQueue.h
37
- trantor/utils/LogStream.h
38
- trantor/utils/Logger.h
39
- trantor/utils/MsgBuffer.h
40
- trantor/utils/NonCopyable.h
41
- trantor/utils/ObjectPool.h
42
- trantor/utils/SerialTaskQueue.h
43
- trantor/utils/TaskQueue.h
44
- trantor/utils/TimingWheel.h )
39
+ # LINK_DIRECTORIES(
40
+ # ${PROJECT_BINARY_DIR}
41
+ # )
45
42
46
- SOURCE_GROUP ( "Public API" FILES ${public_net_headers} ${public_utils_headers} )
47
-
48
- SET (trantor_sources
43
+ set (trantor_sources
49
44
trantor/utils/AsyncFileLogger.cc
50
45
trantor/utils/ConcurrentTaskQueue.cc
51
46
trantor/utils/Date.cc
@@ -71,25 +66,90 @@ SET(trantor_sources
71
66
trantor/net/inner/poller/EpollPoller.cc
72
67
trantor/net/inner/poller/KQueue.cc )
73
68
74
- FIND_PACKAGE (OpenSSL )
75
- IF (OpenSSL_FOUND )
69
+ find_package (OpenSSL )
70
+ if (OpenSSL_FOUND )
76
71
include_directories (${OPENSSL_INCLUDE_DIR} )
77
- LINK_LIBRARIES (${OPENSSL_LIBRARIES} )
78
- SET (trantor_sources ${trantor_sources} trantor/net/ssl/SSLConnection.cc )
79
- ELSE ()
80
- SET (trantor_sources ${trantor_sources} trantor/net/ssl/SSLConnectionSkipped.cc )
81
- ENDIF ()
72
+ link_libraries (${OPENSSL_LIBRARIES} )
73
+ set (trantor_sources ${trantor_sources} trantor/net/ssl/SSLConnection.cc )
74
+ else ()
75
+ set (trantor_sources ${trantor_sources} trantor/net/ssl/SSLConnectionSkipped.cc )
76
+ endif ()
77
+
78
+ add_library (trantor ${trantor_sources} )
79
+ set_property (TARGET trantor PROPERTY CXX_STANDARD 14 )
80
+ set_property (TARGET trantor PROPERTY CXX_STANDARD_REQUIRED ON )
81
+ set_property (TARGET trantor PROPERTY CXX_EXTENSIONS OFF )
82
+
83
+ if (MAKETEST STREQUAL YES )
84
+ add_subdirectory (trantor/tests )
85
+ endif ()
86
+
87
+ set (public_net_headers
88
+ trantor/net/EventLoop.h
89
+ trantor/net/EventLoopThread.h
90
+ trantor/net/EventLoopThreadPool.h
91
+ trantor/net/InetAddress.h
92
+ trantor/net/TcpClient.h
93
+ trantor/net/TcpConnection.h
94
+ trantor/net/TcpServer.h
95
+ trantor/net/callbacks.h )
96
+
97
+ set (public_utils_headers
98
+ trantor/utils/AsyncFileLogger.h
99
+ trantor/utils/ConcurrentTaskQueue.h
100
+ trantor/utils/Date.h
101
+ trantor/utils/Funcs.h
102
+ trantor/utils/LockFreeQueue.h
103
+ trantor/utils/LogStream.h
104
+ trantor/utils/Logger.h
105
+ trantor/utils/MsgBuffer.h
106
+ trantor/utils/NonCopyable.h
107
+ trantor/utils/ObjectPool.h
108
+ trantor/utils/SerialTaskQueue.h
109
+ trantor/utils/TaskQueue.h
110
+ trantor/utils/TimingWheel.h )
111
+
112
+ source_group ( "Public API" FILES ${public_net_headers} ${public_utils_headers} )
113
+
114
+ install (TARGETS trantor
115
+ # IMPORTANT: Add the trantor library to the "export-set"
116
+ EXPORT TrantorTargets
117
+ ARCHIVE DESTINATION "${INSTALL_LIB_DIR} " COMPONENT lib )
118
+
119
+ install (FILES ${public_net_headers} DESTINATION ${INSTALL_INCLUDE_DIR} /trantor/net )
120
+ install (FILES ${public_utils_headers} DESTINATION ${INSTALL_INCLUDE_DIR} /trantor/utils )
121
+
122
+
123
+ # Add all targets to the build-tree export set
124
+ export (TARGETS trantor
125
+ FILE "${PROJECT_BINARY_DIR} /TrantorTargets.cmake" )
126
+
127
+ include (CMakePackageConfigHelpers )
128
+ # ... for the build tree(locally included)
129
+ set (CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR} " )
130
+ configure_package_config_file (cmake/templates/TrantorConfig.cmake.in
131
+ ${CMAKE_CURRENT_BINARY_DIR} /TrantorConfig.cmake
132
+ INSTALL_DESTINATION ${CMAKE_CURRENT_BINARY_DIR}
133
+ PATH_VARS CONF_INCLUDE_DIRS )
134
+ # ... for the install tree
135
+ set (CONF_INCLUDE_DIRS "${INSTALL_INCLUDE_DIR} " )
136
+ configure_package_config_file (cmake/templates/TrantorConfig.cmake.in
137
+ ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY} /TrantorConfig.cmake
138
+ INSTALL_DESTINATION ${INSTALL_TRANTOR_CMAKE_DIR}
139
+ PATH_VARS CONF_INCLUDE_DIRS )
82
140
83
- ADD_LIBRARY ( trantor ${trantor_sources} )
84
- SET_PROPERTY ( TARGET trantor PROPERTY CXX_STANDARD 14 )
85
- SET_PROPERTY ( TARGET trantor PROPERTY CXX_STANDARD_REQUIRED ON )
86
- SET_PROPERTY ( TARGET trantor PROPERTY CXX_EXTENSIONS OFF )
141
+ # version
142
+ write_basic_package_version_file ( ${CMAKE_CURRENT_BINARY_DIR} /TrantorConfigVersion.cmake
143
+ VERSION ${TRANTOR_VERSION}
144
+ COMPATIBILITY SameMajorVersion )
87
145
88
- IF (MAKETEST STREQUAL YES )
89
- ADD_SUBDIRECTORY (trantor/tests )
90
- ENDIF ()
146
+ # Install the TrantorConfig.cmake and TrantorConfigVersion.cmake
147
+ install (FILES
148
+ "${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY} /TrantorConfig.cmake"
149
+ "${CMAKE_CURRENT_BINARY_DIR} /TrantorConfigVersion.cmake"
150
+ DESTINATION "${INSTALL_TRANTOR_CMAKE_DIR} " COMPONENT dev )
91
151
92
- INSTALL (TARGETS trantor DESTINATION lib )
152
+ # Install the export set for use with the install-tree
153
+ install (EXPORT TrantorTargets
154
+ DESTINATION "${INSTALL_TRANTOR_CMAKE_DIR} " COMPONENT dev )
93
155
94
- INSTALL (FILES ${public_net_headers} DESTINATION include /trantor/net )
95
- INSTALL (FILES ${public_utils_headers} DESTINATION include /trantor/utils )
0 commit comments