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