-
Notifications
You must be signed in to change notification settings - Fork 8
/
CMakeLists.txt
205 lines (164 loc) · 6.03 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
cmake_minimum_required( VERSION 2.6 )
project( wsh C )
set( APPLICATION_VERSION_MAJOR "1" )
set( APPLICATION_VERSION_MINOR "0" )
set( APPLICATION_VERSION_PATCH "0" )
set( APPLICATION_VERSION_EXTRA "rc5" )
set( APPLICATION_VERSION
"${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}${APPLICATION_VERSION_EXTRA}"
)
set( LIBRARY_VERSION
"${APPLICATION_VERSION_MAJOR}.${APPLICATION_VERSION_MINOR}.${APPLICATION_VERSION_PATCH}"
)
set( LIBRARY_SOVERSION "${APPLICATION_VERSION_MAJOR}" )
option( BUILD_SERVER "Build wsh server" ON )
option( BUILD_CLIENT "Build wsh client" ON )
option( BUILD_UTILS "Build wsh utilities" ON )
option( BUILD_TESTS "Build wsh unit tests" OFF )
option( WITH_RANGE "Use libcrange as an host expansion lib" OFF )
set( LIBEXEC_PATH "${CMAKE_INSTALL_PREFIX}/libexec" CACHE STRING "Location for helper programs" )
set( CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules )
include( CheckCCompilerFlag )
include( CheckFunctionExists )
include( CheckIncludeFile )
include( CheckLibraryExists )
include( CheckSymbolExists )
include( Compiler )
include( Coverage )
include( CPack )
include( MacroEnsureOutOfSourceBuild )
include( OS )
if( LINKEDIN )
include( LinkedIn )
endif( LINKEDIN )
set( GLIB2_MIN_VERSION "2.32.0" )
macro_ensure_out_of_source_build( "You must build outside of the source tree" )
set( CMAKE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/build )
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_OUTPUT_DIRECTORY}/bin )
set( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_OUTPUT_DIRECTORY}/lib )
set( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_OUTPUT_DIRECTORY}/lib )
if( OPENBSD )
set( CMAKE_INSTALL_FULL_MANDIR ${CMAKE_INSTALL_PREFIX} )
else( OPENBSD )
set( CMAKE_INSTALL_FULL_MANDIR ${CMAKE_INSTALL_PREFIX}/share )
endif( OPENBSD )
set( WSH_INCLUDE_DIRS ${CMAKE_OUTPUT_DIRECTORY}/gen ${CMAKE_SOURCE_DIR}/library/src )
set( WSH_LIBRARIES wsh )
check_include_file( termios.h HAVE_TERMIOS_H )
check_include_file( unistd.h HAVE_UNISTD_H )
if( CMAKE_BUILD_TYPE STREQUAL "Debug" )
add_definitions( -DDEBUG )
endif( CMAKE_BUILD_TYPE STREQUAL "Debug" )
# Global deps
# https://raw.github.com/stevedekorte/io/master/modules/FindGLIB2.cmake
find_package( GLIB2 REQUIRED )
string( REPLACE ";" " " GLIB2_LDFLAGS_STRIPPED "${GLIB2_LDFLAGS}" )
set( GLIB2_LDFLAGS "${GLIB2_LDFLAGS_STRIPPED}" )
# https://github.com/Pronghorn/pronghorn/blob/master/FindPROTOBUF-C.cmake
find_package( PROTOBUF-C REQUIRED )
find_package( Threads REQUIRED )
find_package( SSH REQUIRED )
find_package( Curses )
check_include_file( term.h HAVE_TERM_H )
# Optional dep
if( WITH_RANGE )
find_package( CRANGE )
if( LIBCRANGE_LIBRARY )
find_package( APR REQUIRED )
endif( LIBCRANGE_LIBRARY )
endif( WITH_RANGE )
set( CMAKE_REQUIRED_INCLUDES ${LIBSSH_INCLUDE_DIR} ${GLIB2_INCLUDE_DIRS} ${PROTOBUF_INCLUDE_DIR} )
set( CMAKE_REQUIRED_LIBRARIES ${LIBSSH_LIBRARY} ${GLIB2_LIBRARIES} ${PROTOBUF_LIBRARIES} )
# Deal with linker crap
if( NOT LIB_INSTALL_DIR )
set( libdir "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}" )
else( NOT LIB_INSTALL_DIR )
set( libdir "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}" )
endif( NOT LIB_INSTALL_DIR )
set( CMAKE_INSTALL_RPATH "${libdir}" )
set( CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE )
list( FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES
"${libdir}" isSystemDir )
if( "${isSystemDir}" STREQUAL "-1" )
set( CMAKE_INSTALL_RPATH "${libdir}" )
endif( "${isSystemDir}" STREQUAL "-1" )
# This is a hack to get around problems with the custom cmake libs I found
if( IS_DIRECTORY /usr/local/lib )
link_directories( /usr/local/lib )
endif( IS_DIRECTORY /usr/local/lib )
if( IS_DIRECTORY /usr/pkg/lib )
link_directories( /usr/pkg/lib )
endif( IS_DIRECTORY /usr/pkg/lib )
# Function tests
if( HAVE_C11 )
check_symbol_exists( memset_s string.h HAVE_MEMSET_S )
endif( HAVE_C11 )
check_symbol_exists( explicit_bzero string.h HAVE_EXPLICIT_BZERO )
check_symbol_exists( g_get_num_processors glib.h HAVE_G_GETNUM_PROCESSORS )
check_symbol_exists( closefrom "stdlib.h;unistd.h" HAVE_CLOSEFROM )
check_symbol_exists( ssh_get_server_publickey libssh/libssh.h HAVE_SSH_GET_SERVER_PUBLICKEY )
configure_file( ${CMAKE_SOURCE_DIR}/config.h.in ${CMAKE_SOURCE_DIR}/config.h )
# We need to set these per target
set( ORIG_CFLAGS ${CMAKE_C_FLAGS} )
set( CMAKE_C_FLAGS "${ORIG_CFLAGS} ${WSH_LIB_COMPILER_FLAGS}" )
set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GLIB2_LDFLAGS} ${WSH_EXE_LINKER_FLAGS}" )
set( CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${GLIB2_LDFLAGS} ${WSH_LIB_LINKER_FLAGS}" )
add_subdirectory( library/src )
if( BUILD_TESTS )
# enable testing for whole project
enable_testing()
add_subdirectory( library/test )
endif( BUILD_TESTS )
if( BUILD_UTILS )
set( CMAKE_C_FLAGS "${ORIG_CFLAGS} ${WSH_EXE_COMPILER_FLAGS}" )
add_subdirectory( util/src )
if( BUILD_TESTS )
#add_subdirectory( util/test )
endif( BUILD_TESTS )
install(
FILES man/wsh-add-hostkeys.1
DESTINATION ${CMAKE_INSTALL_FULL_MANDIR}/man/man1
COMPONENT doc
)
endif( BUILD_UTILS )
if( BUILD_SERVER )
set( CMAKE_C_FLAGS "${ORIG_CFLAGS} ${WSH_EXE_COMPILER_FLAGS}" )
add_subdirectory( server/src )
if( BUILD_TESTS )
add_subdirectory( server/test )
endif( BUILD_TESTS )
install(
FILES man/wshd.1
DESTINATION ${CMAKE_INSTALL_FULL_MANDIR}/man/man1
COMPONENT doc
)
endif( BUILD_SERVER )
if( BUILD_CLIENT )
set( CMAKE_C_FLAGS "${ORIG_CFLAGS} ${WSH_EXE_COMPILER_FLAGS}" )
add_subdirectory( client/src )
if( BUILD_TESTS )
add_subdirectory( client/test )
endif( BUILD_TESTS )
install(
FILES man/wshc.1 man/wscp.1
DESTINATION ${CMAKE_INSTALL_FULL_MANDIR}/man/man1
COMPONENT doc
)
endif( BUILD_CLIENT )
## Build docs
add_custom_target( doc
COMMAND doxygen ../Doxyfile
)
add_custom_target( indent
COMMAND find ../client ../server ../library -name '*.[hc]' -print0 | xargs -0
astyle --style=google --indent=tab -xC80 -xL --indent-cases
--indent-switches
)
add_custom_target( etags
COMMAND find ../client ../server ../library -name '*.[hc]' -print0 | xargs -0
etags
)
add_custom_target( tags
COMMAND find ../client ../server ../library -name '*.[hc]' -print0 | xargs -0
ectags
)