1cmake_minimum_required(VERSION 2.6) 2 3project(LibVNCServer) 4include(CheckFunctionExists) 5include(CheckIncludeFile) 6include(CheckTypeSize) 7include(TestBigEndian) 8include(CheckCSourceCompiles) 9include(CheckCXXSourceCompiles) 10include(CheckCSourceRuns) 11 12set(PACKAGE_NAME "LibVNCServer") 13set(FULL_PACKAGE_NAME "LibVNCServer") 14set(PACKAGE_VERSION "0.9.9") 15set(PROJECT_BUGREPORT_PATH "http://sourceforge.net/projects/libvncserver") 16set(CMAKE_C_FLAGS "-O2 -W -Wall -g") 17set(LIBVNCSERVER_DIR ${CMAKE_SOURCE_DIR}/libvncserver) 18set(COMMON_DIR ${CMAKE_SOURCE_DIR}/common) 19set(LIBVNCCLIENT_DIR ${CMAKE_SOURCE_DIR}/libvncclient) 20set(LIBVNCSRVTEST_DIR ${CMAKE_SOURCE_DIR}/examples) 21set(LIBVNCCLITEST_DIR ${CMAKE_SOURCE_DIR}/client_examples) 22 23 24include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/libvncserver ${CMAKE_SOURCE_DIR}/common) 25 26find_package(ZLIB) 27find_package(JPEG) 28find_package(PNG) 29find_package(SDL) 30find_package(GnuTLS) 31find_package(Threads) 32find_package(X11) 33find_package(OpenSSL) 34find_library(LIBGCRYPT_LIBRARIES gcrypt) 35 36# Check whether the version of libjpeg we found was libjpeg-turbo and print a 37# warning if not. 38set(CMAKE_REQUIRED_LIBRARIES ${JPEG_LIBRARIES}) 39set(CMAKE_REQUIRED_FLAGS -I${JPEG_INCLUDE_DIR}) 40 41set(JPEG_TEST_SOURCE "\n 42 #include <stdio.h>\n 43 #include <jpeglib.h>\n 44 int main(void) {\n 45 struct jpeg_compress_struct cinfo;\n 46 struct jpeg_error_mgr jerr;\n 47 cinfo.err=jpeg_std_error(&jerr);\n 48 jpeg_create_compress(&cinfo);\n 49 cinfo.input_components = 3;\n 50 jpeg_set_defaults(&cinfo);\n 51 cinfo.in_color_space = JCS_EXT_RGB;\n 52 jpeg_default_colorspace(&cinfo);\n 53 return 0;\n 54 }") 55 56if(CMAKE_CROSSCOMPILING) 57 check_c_source_compiles("${JPEG_TEST_SOURCE}" FOUND_LIBJPEG_TURBO) 58else() 59 check_c_source_runs("${JPEG_TEST_SOURCE}" FOUND_LIBJPEG_TURBO) 60endif() 61 62set(CMAKE_REQUIRED_LIBRARIES) 63set(CMAKE_REQUIRED_FLAGS) 64set(CMAKE_REQUIRED_DEFINITIONS) 65 66if(NOT FOUND_LIBJPEG_TURBO) 67 message(WARNING "*** The libjpeg library you are building against is not libjpeg-turbo. Performance will be reduced. You can obtain libjpeg-turbo from: https://sourceforge.net/projects/libjpeg-turbo/files/ ***") 68endif() 69 70set(CMAKE_REQUIRED_LIBRARIES resolv) 71check_function_exists(__b64_ntop HAVE_B64) 72 73if(Threads_FOUND) 74 option(TIGHTVNC_FILETRANSFER "Enable filetransfer" ON) 75endif(Threads_FOUND) 76if (HAVE_B64) 77endif(HAVE_B64) 78if(ZLIB_FOUND) 79 set(LIBVNCSERVER_HAVE_LIBZ 1) 80endif(ZLIB_FOUND) 81if(JPEG_FOUND) 82 set(LIBVNCSERVER_HAVE_LIBJPEG 1) 83endif(JPEG_FOUND) 84if(PNG_FOUND) 85 set(LIBVNCSERVER_HAVE_LIBPNG 1) 86endif(PNG_FOUND) 87option(LIBVNCSERVER_ALLOW24BPP "Allow 24 bpp" ON) 88 89if(GNUTLS_FOUND) 90 set(LIBVNCSERVER_WITH_CLIENT_TLS 1) 91 option(LIBVNCSERVER_WITH_WEBSOCKETS "Build with websockets support (gnutls)" ON) 92 set(WEBSOCKET_LIBRARIES -lresolv ${GNUTLS_LIBRARIES}) 93 set(WSSRCS ${LIBVNCSERVER_DIR}/rfbssl_gnutls ${LIBVNCSERVER_DIR}/rfbcrypto_gnutls) 94elseif(OPENSSL_FOUND) 95 option(LIBVNCSERVER_WITH_WEBSOCKETS "Build with websockets support (openssl)" ON) 96 set(WEBSOCKET_LIBRARIES -lresolv ${OPENSSL_LIBRARIES}) 97 set(WSSRCS ${LIBVNCSERVER_DIR}/rfbssl_openssl ${LIBVNCSERVER_DIR}/rfbcrypto_openssl) 98else() 99 option(LIBVNCSERVER_WITH_WEBSOCKETS "Build with websockets support (no ssl)" ON) 100 set(WEBSOCKET_LIBRARIES -lresolv) 101 set(WSSRCS ${LIBVNCSERVER_DIR}/rfbssl_none.c ${LIBVNCSERVER_DIR}/rfbcrypto_included.c ${COMMON_DIR}/md5.c ${COMMON_DIR}/sha1.c) 102endif() 103 104if(LIBGCRYPT_LIBRARIES) 105 message(STATUS "Found libgcrypt: ${LIBGCRYPT_LIBRARIES}") 106 set(LIBVNCSERVER_WITH_CLIENT_GCRYPT 1) 107endif(LIBGCRYPT_LIBRARIES) 108 109 110check_include_file("fcntl.h" LIBVNCSERVER_HAVE_FCNTL_H) 111check_include_file("netinet/in.h" LIBVNCSERVER_HAVE_NETINET_IN_H) 112check_include_file("sys/socket.h" LIBVNCSERVER_HAVE_SYS_SOCKET_H) 113check_include_file("sys/stat.h" LIBVNCSERVER_HAVE_SYS_STAT_H) 114check_include_file("sys/time.h" LIBVNCSERVER_HAVE_SYS_TIME_H) 115check_include_file("sys/types.h" LIBVNCSERVER_HAVE_SYS_TYPES_H) 116check_include_file("sys/wait.h" LIBVNCSERVER_HAVE_SYS_WAIT_H) 117check_include_file("unistd.h" LIBVNCSERVER_HAVE_UNISTD_H) 118 119# headers needed for check_type_size() 120check_include_file("arpa/inet.h" HAVE_ARPA_INET_H) 121check_include_file("stdint.h" HAVE_STDINT_H) 122check_include_file("stddef.h" HAVE_STDDEF_H) 123check_include_file("sys/types.h" HAVE_SYS_TYPES_H) 124 125check_function_exists(gettimeofday LIBVNCSERVER_HAVE_GETTIMEOFDAY) 126 127if(CMAKE_USE_PTHREADS_INIT) 128 set(LIBVNCSERVER_HAVE_LIBPTHREAD 1) 129endif(CMAKE_USE_PTHREADS_INIT) 130if(LIBVNCSERVER_HAVE_SYS_SOCKET_H) 131 # socklen_t 132 list(APPEND CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h") 133endif(LIBVNCSERVER_HAVE_SYS_SOCKET_H) 134if(HAVE_ARPA_INET_H) 135 # in_addr_t 136 list(APPEND CMAKE_EXTRA_INCLUDE_FILES "arpa/inet.h") 137endif(HAVE_ARPA_INET_H) 138 139check_type_size(pid_t LIBVNCSERVER_PID_T) 140check_type_size(size_t LIBVNCSERVER_SIZE_T) 141check_type_size(socklen_t LIBVNCSERVER_SOCKLEN_T) 142check_type_size(in_addr_t LIBVNCSERVER_IN_ADDR_T) 143if(NOT HAVE_LIBVNCSERVER_IN_ADDR_T) 144 set(LIBVNCSERVER_NEED_INADDR_T 1) 145endif(NOT HAVE_LIBVNCSERVER_IN_ADDR_T) 146 147TEST_BIG_ENDIAN(LIBVNCSERVER_WORDS_BIGENDIAN) 148 149# TODO: 150# LIBVNCSERVER_ENOENT_WORKAROUND 151# inline 152 153configure_file(${CMAKE_SOURCE_DIR}/rfb/rfbconfig.h.cmake ${CMAKE_BINARY_DIR}/rfb/rfbconfig.h) 154configure_file(${CMAKE_SOURCE_DIR}/rfb/rfbint.h.cmake ${CMAKE_BINARY_DIR}/rfb/rfbint.h) 155 156set(LIBVNCSERVER_SOURCES 157 ${LIBVNCSERVER_DIR}/main.c 158 ${LIBVNCSERVER_DIR}/rfbserver.c 159 ${LIBVNCSERVER_DIR}/rfbregion.c 160 ${LIBVNCSERVER_DIR}/auth.c 161 ${LIBVNCSERVER_DIR}/sockets.c 162 ${LIBVNCSERVER_DIR}/stats.c 163 ${LIBVNCSERVER_DIR}/corre.c 164 ${LIBVNCSERVER_DIR}/hextile.c 165 ${LIBVNCSERVER_DIR}/rre.c 166 ${LIBVNCSERVER_DIR}/translate.c 167 ${LIBVNCSERVER_DIR}/cutpaste.c 168 ${LIBVNCSERVER_DIR}/httpd.c 169 ${LIBVNCSERVER_DIR}/cursor.c 170 ${LIBVNCSERVER_DIR}/font.c 171 ${LIBVNCSERVER_DIR}/draw.c 172 ${LIBVNCSERVER_DIR}/selbox.c 173 ${COMMON_DIR}/d3des.c 174 ${COMMON_DIR}/vncauth.c 175 ${LIBVNCSERVER_DIR}/cargs.c 176 ${COMMON_DIR}/minilzo.c 177 ${LIBVNCSERVER_DIR}/ultra.c 178 ${LIBVNCSERVER_DIR}/scale.c 179) 180 181set(LIBVNCCLIENT_SOURCES 182 ${LIBVNCCLIENT_DIR}/cursor.c 183 ${LIBVNCCLIENT_DIR}/listen.c 184 ${LIBVNCCLIENT_DIR}/rfbproto.c 185 ${LIBVNCCLIENT_DIR}/sockets.c 186 ${LIBVNCCLIENT_DIR}/vncviewer.c 187 ${COMMON_DIR}/minilzo.c 188) 189 190if(GNUTLS_FOUND) 191 set(LIBVNCCLIENT_SOURCES 192 ${LIBVNCCLIENT_SOURCES} 193 ${LIBVNCCLIENT_DIR}/tls_gnutls.c 194 ) 195elseif(OPENSSL_FOUND) 196 set(LIBVNCCLIENT_SOURCES 197 ${LIBVNCCLIENT_SOURCES} 198 ${LIBVNCCLIENT_DIR}/tls_openssl.c 199 ) 200else() 201 set(LIBVNCCLIENT_SOURCES 202 ${LIBVNCCLIENT_SOURCES} 203 ${LIBVNCCLIENT_DIR}/tls_none.c 204 ) 205endif() 206 207if(ZLIB_FOUND) 208 add_definitions(-DLIBVNCSERVER_HAVE_LIBZ) 209 include_directories(${ZLIB_INCLUDE_DIR}) 210 set(LIBVNCSERVER_SOURCES 211 ${LIBVNCSERVER_SOURCES} 212 ${LIBVNCSERVER_DIR}/zlib.c 213 ${LIBVNCSERVER_DIR}/zrle.c 214 ${LIBVNCSERVER_DIR}/zrleoutstream.c 215 ${LIBVNCSERVER_DIR}/zrlepalettehelper.c 216 ) 217endif(ZLIB_FOUND) 218 219if(JPEG_FOUND) 220 add_definitions(-DLIBVNCSERVER_HAVE_LIBJPEG) 221 include_directories(${JPEG_INCLUDE_DIR}) 222 set(TIGHT_C ${LIBVNCSERVER_DIR}/tight.c ${COMMON_DIR}/turbojpeg.c) 223endif(JPEG_FOUND) 224 225if(PNG_FOUND) 226 add_definitions(-DLIBVNCSERVER_HAVE_LIBPNG) 227 include_directories(${PNG_INCLUDE_DIR}) 228 set(TIGHT_C ${LIBVNCSERVER_DIR}/tight.c ${COMMON_DIR}/turbojpeg.c) 229endif(PNG_FOUND) 230 231set(LIBVNCSERVER_SOURCES 232 ${LIBVNCSERVER_SOURCES} 233 ${TIGHT_C} 234) 235 236if(TIGHTVNC_FILETRANSFER) 237 set(LIBVNCSERVER_SOURCES 238 ${LIBVNCSERVER_SOURCES} 239 ${LIBVNCSERVER_DIR}/tightvnc-filetransfer/rfbtightserver.c 240 ${LIBVNCSERVER_DIR}/tightvnc-filetransfer/handlefiletransferrequest.c 241 ${LIBVNCSERVER_DIR}/tightvnc-filetransfer/filetransfermsg.c 242 ${LIBVNCSERVER_DIR}/tightvnc-filetransfer/filelistinfo.c 243 ) 244endif(TIGHTVNC_FILETRANSFER) 245 246if(LIBVNCSERVER_WITH_WEBSOCKETS) 247 add_definitions(-DLIBVNCSERVER_WITH_WEBSOCKETS) 248 set(LIBVNCSERVER_SOURCES 249 ${LIBVNCSERVER_SOURCES} 250 ${LIBVNCSERVER_DIR}/websockets.c 251 ${WSSRCS} 252 ) 253endif(LIBVNCSERVER_WITH_WEBSOCKETS) 254 255 256add_library(vncclient SHARED ${LIBVNCCLIENT_SOURCES}) 257add_library(vncserver SHARED ${LIBVNCSERVER_SOURCES}) 258if(WIN32) 259 set(ADDITIONAL_LIBS ws2_32) 260endif(WIN32) 261 262target_link_libraries(vncclient 263 ${ADDITIONAL_LIBS} 264 ${ZLIB_LIBRARIES} 265 ${JPEG_LIBRARIES} 266) 267target_link_libraries(vncserver 268 ${ADDITIONAL_LIBS} 269 ${ZLIB_LIBRARIES} 270 ${JPEG_LIBRARIES} 271 ${PNG_LIBRARIES} 272 ${WEBSOCKET_LIBRARIES} 273) 274 275SET_TARGET_PROPERTIES(vncclient vncserver 276 PROPERTIES SOVERSION "0.0.0" 277) 278 279# tests 280set(LIBVNCSERVER_TESTS 281 backchannel 282 camera 283 colourmaptest 284 example 285 fontsel 286 pnmshow 287 pnmshow24 288 regiontest 289 rotate 290 simple 291 simple15 292 storepasswd 293 vncev 294 ) 295 296if(Threads_FOUND) 297 set(LIBVNCSERVER_TESTS 298 ${LIBVNCSERVER_TESTS} 299 blooptest 300 ) 301endif(Threads_FOUND) 302 303if(TIGHTVNC_FILETRANSFER) 304 set(LIBVNCSERVER_TESTS 305 ${LIBVNCSERVER_TESTS} 306 filetransfer 307 ) 308endif(TIGHTVNC_FILETRANSFER) 309 310if(MACOS) 311 set(LIBVNCSERVER_TESTS 312 ${LIBVNCSERVER_TESTS} 313 mac 314 ) 315endif(MACOS) 316 317set(LIBVNCCLIENT_TESTS 318 backchannel 319 ppmtest 320) 321 322if(SDL_FOUND) 323 include_directories(${SDL_INCLUDE_DIR}) 324 set(LIBVNCCLIENT_TESTS 325 ${LIBVNCCLIENT_TESTS} 326 SDLvncviewer 327 ) 328 set(SDLvncviewer_EXTRA_SOURCES scrap.c) 329endif(SDL_FOUND) 330 331if(HAVE_FFMPEG) 332 set(LIBVNCCLIENT_TESTS 333 ${LIBVNCCLIENT_TESTS} 334 vnc2mpg 335 ) 336endif(HAVE_FFMPEG) 337 338 339file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/examples) 340foreach(test ${LIBVNCSERVER_TESTS}) 341 add_executable(examples/${test} ${LIBVNCSRVTEST_DIR}/${test}.c) 342 target_link_libraries(examples/${test} vncserver ${CMAKE_THREAD_LIBS_INIT}) 343endforeach(test ${LIBVNCSERVER_TESTS}) 344 345file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/client_examples) 346foreach(test ${LIBVNCCLIENT_TESTS}) 347 add_executable(client_examples/${test} ${LIBVNCCLITEST_DIR}/${test}.c ${LIBVNCCLITEST_DIR}/${${test}_EXTRA_SOURCES} ) 348 target_link_libraries(client_examples/${test} vncclient ${CMAKE_THREAD_LIBS_INIT} ${GNUTLS_LIBRARIES} ${X11_LIBRARIES} ${SDL_LIBRARY} ${FFMPEG_LIBRARIES}) 349endforeach(test ${LIBVNCCLIENT_TESTS}) 350 351install_targets(/lib vncserver) 352install_targets(/lib vncclient) 353install_files(/include/rfb FILES 354 rfb/keysym.h 355 rfb/rfb.h 356 rfb/rfbclient.h 357 rfb/rfbconfig.h 358 rfb/rfbint.h 359 rfb/rfbproto.h 360 rfb/rfbregion.h 361) 362