Home | History | Annotate | Download | only in libvncserver
      1 cmake_minimum_required(VERSION 2.6)
      2 
      3 project(LibVNCServer)
      4 include(CheckFunctionExists)
      5 include(CheckIncludeFile)
      6 include(CheckTypeSize)
      7 include(TestBigEndian)
      8 include(CheckCSourceCompiles)
      9 include(CheckCXXSourceCompiles)
     10 include(CheckCSourceRuns)
     11 
     12 set(PACKAGE_NAME           "LibVNCServer")
     13 set(FULL_PACKAGE_NAME      "LibVNCServer")
     14 set(PACKAGE_VERSION        "0.9.10")
     15 set(VERSION_MAJOR          "0")
     16 set(VERSION_MINOR          "9")
     17 set(VERSION_PATCHLEVEL     "10")
     18 set(PROJECT_BUGREPORT_PATH "http://sourceforge.net/projects/libvncserver")
     19 set(CMAKE_C_FLAGS "-O2 -W -Wall -g")
     20 set(LIBVNCSERVER_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libvncserver)
     21 set(COMMON_DIR ${CMAKE_CURRENT_SOURCE_DIR}/common)
     22 set(LIBVNCCLIENT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libvncclient)
     23 set(LIBVNCSRVTEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/examples)
     24 set(LIBVNCCLITEST_DIR ${CMAKE_CURRENT_SOURCE_DIR}/client_examples)
     25 
     26 
     27 include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/libvncserver ${CMAKE_CURRENT_SOURCE_DIR}/common)
     28 
     29 find_package(ZLIB)
     30 find_package(JPEG)
     31 find_package(PNG)
     32 find_package(SDL)
     33 find_package(GnuTLS)
     34 find_package(Threads)
     35 find_package(X11)
     36 find_package(OpenSSL)
     37 find_library(LIBGCRYPT_LIBRARIES gcrypt)
     38 
     39 # Check whether the version of libjpeg we found was libjpeg-turbo and print a
     40 # warning if not.
     41 set(CMAKE_REQUIRED_LIBRARIES ${JPEG_LIBRARIES})
     42 set(CMAKE_REQUIRED_FLAGS -I${JPEG_INCLUDE_DIR})
     43 
     44 set(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 
     59 if(CMAKE_CROSSCOMPILING)
     60   check_c_source_compiles("${JPEG_TEST_SOURCE}" FOUND_LIBJPEG_TURBO)
     61 else()
     62   check_c_source_runs("${JPEG_TEST_SOURCE}" FOUND_LIBJPEG_TURBO)
     63 endif()
     64 
     65 set(CMAKE_REQUIRED_LIBRARIES)
     66 set(CMAKE_REQUIRED_FLAGS)
     67 set(CMAKE_REQUIRED_DEFINITIONS)
     68 
     69 if(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/ ***")
     71 endif()
     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.
     78 check_function_exists(__b64_ntop HAVE_B64_IN_LIBC)
     79 if(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)
     87 endif(NOT HAVE_B64_IN_LIBC)
     88 
     89 if(Threads_FOUND)
     90   option(TIGHTVNC_FILETRANSFER "Enable filetransfer" ON)
     91 endif(Threads_FOUND)
     92 if(ZLIB_FOUND)
     93   set(LIBVNCSERVER_HAVE_LIBZ 1)
     94 endif(ZLIB_FOUND)
     95 if(JPEG_FOUND)
     96   set(LIBVNCSERVER_HAVE_LIBJPEG 1)
     97 endif(JPEG_FOUND)
     98 if(PNG_FOUND)
     99   set(LIBVNCSERVER_HAVE_LIBPNG 1)
    100 endif(PNG_FOUND)
    101 option(LIBVNCSERVER_ALLOW24BPP "Allow 24 bpp" ON)
    102 
    103 if(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)
    108 elseif(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)
    112 else()
    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)
    116 endif()
    117 
    118 if(LIBGCRYPT_LIBRARIES)
    119   message(STATUS "Found libgcrypt: ${LIBGCRYPT_LIBRARIES}")
    120   set(LIBVNCSERVER_WITH_CLIENT_GCRYPT 1)
    121   set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} ${LIBGCRYPT_LIBRARIES})
    122 endif(LIBGCRYPT_LIBRARIES)
    123 
    124 
    125 check_include_file("endian.h"      LIBVNCSERVER_HAVE_ENDIAN_H)
    126 check_include_file("fcntl.h"       LIBVNCSERVER_HAVE_FCNTL_H)
    127 check_include_file("netinet/in.h"  LIBVNCSERVER_HAVE_NETINET_IN_H)
    128 check_include_file("sys/endian.h"  LIBVNCSERVER_HAVE_SYS_ENDIAN_H)
    129 check_include_file("sys/socket.h"  LIBVNCSERVER_HAVE_SYS_SOCKET_H)
    130 check_include_file("sys/stat.h"    LIBVNCSERVER_HAVE_SYS_STAT_H)
    131 check_include_file("sys/time.h"    LIBVNCSERVER_HAVE_SYS_TIME_H)
    132 check_include_file("sys/types.h"   LIBVNCSERVER_HAVE_SYS_TYPES_H)
    133 check_include_file("sys/wait.h"    LIBVNCSERVER_HAVE_SYS_WAIT_H)
    134 check_include_file("unistd.h"      LIBVNCSERVER_HAVE_UNISTD_H)
    135 
    136 # headers needed for check_type_size()
    137 check_include_file("arpa/inet.h"   HAVE_ARPA_INET_H)
    138 check_include_file("stdint.h"      HAVE_STDINT_H)
    139 check_include_file("stddef.h"      HAVE_STDDEF_H)
    140 check_include_file("sys/types.h"   HAVE_SYS_TYPES_H)
    141 
    142 check_function_exists(gettimeofday    LIBVNCSERVER_HAVE_GETTIMEOFDAY)
    143 
    144 if(CMAKE_USE_PTHREADS_INIT)
    145   set(LIBVNCSERVER_HAVE_LIBPTHREAD 1)
    146 endif(CMAKE_USE_PTHREADS_INIT)
    147 if(LIBVNCSERVER_HAVE_SYS_SOCKET_H)
    148   # socklen_t
    149   list(APPEND CMAKE_EXTRA_INCLUDE_FILES "sys/socket.h")
    150 endif(LIBVNCSERVER_HAVE_SYS_SOCKET_H)
    151 if(HAVE_ARPA_INET_H)
    152   # in_addr_t
    153   list(APPEND CMAKE_EXTRA_INCLUDE_FILES "arpa/inet.h")
    154 endif(HAVE_ARPA_INET_H)
    155 
    156 check_type_size(pid_t     LIBVNCSERVER_PID_T)
    157 check_type_size(size_t    LIBVNCSERVER_SIZE_T)
    158 check_type_size(socklen_t LIBVNCSERVER_SOCKLEN_T)
    159 check_type_size(in_addr_t LIBVNCSERVER_IN_ADDR_T)
    160 if(NOT HAVE_LIBVNCSERVER_IN_ADDR_T)
    161   set(LIBVNCSERVER_NEED_INADDR_T 1)
    162 endif(NOT HAVE_LIBVNCSERVER_IN_ADDR_T)
    163 
    164 TEST_BIG_ENDIAN(LIBVNCSERVER_WORDS_BIGENDIAN)
    165 
    166 # TODO:
    167 # LIBVNCSERVER_ENOENT_WORKAROUND
    168 # inline
    169 
    170 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/rfb/rfbconfig.h.cmake ${CMAKE_BINARY_DIR}/rfb/rfbconfig.h)
    171 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/rfb/rfbint.h.cmake ${CMAKE_BINARY_DIR}/rfb/rfbint.h)
    172 
    173 set(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 
    198 set(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 
    207 if(GNUTLS_FOUND)
    208   set(LIBVNCCLIENT_SOURCES
    209     ${LIBVNCCLIENT_SOURCES}
    210     ${LIBVNCCLIENT_DIR}/tls_gnutls.c
    211   )
    212 elseif(OPENSSL_FOUND)
    213   set(LIBVNCCLIENT_SOURCES
    214     ${LIBVNCCLIENT_SOURCES}
    215     ${LIBVNCCLIENT_DIR}/tls_openssl.c
    216   )
    217 else()
    218   set(LIBVNCCLIENT_SOURCES
    219     ${LIBVNCCLIENT_SOURCES}
    220     ${LIBVNCCLIENT_DIR}/tls_none.c
    221   )
    222 endif()
    223 
    224 if(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   )
    234 endif(ZLIB_FOUND)
    235 
    236 if(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)
    240 endif(JPEG_FOUND)
    241 
    242 if(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)
    246 endif(PNG_FOUND)
    247 
    248 set(LIBVNCSERVER_SOURCES
    249     ${LIBVNCSERVER_SOURCES}
    250     ${TIGHT_C}
    251 )
    252 
    253 if(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   )
    261 endif(TIGHTVNC_FILETRANSFER)
    262 
    263 if(LIBVNCSERVER_WITH_WEBSOCKETS)
    264   add_definitions(-DLIBVNCSERVER_WITH_WEBSOCKETS)
    265   set(LIBVNCSERVER_SOURCES
    266     ${LIBVNCSERVER_SOURCES}
    267     ${LIBVNCSERVER_DIR}/websockets.c
    268     ${WSSRCS}
    269   )
    270 endif(LIBVNCSERVER_WITH_WEBSOCKETS)
    271 
    272 
    273 add_library(vncclient SHARED ${LIBVNCCLIENT_SOURCES})
    274 add_library(vncserver SHARED ${LIBVNCSERVER_SOURCES})
    275 if(WIN32)
    276   set(ADDITIONAL_LIBS ${ADDITIONAL_LIBS} ws2_32)
    277 endif(WIN32)
    278 
    279 target_link_libraries(vncclient
    280                       ${ADDITIONAL_LIBS}
    281                       ${ZLIB_LIBRARIES}
    282                       ${JPEG_LIBRARIES}
    283                       ${GNUTLS_LIBRARIES}
    284 )
    285 target_link_libraries(vncserver
    286                       ${ADDITIONAL_LIBS}
    287                       ${ZLIB_LIBRARIES}
    288                       ${JPEG_LIBRARIES}
    289 		      ${PNG_LIBRARIES}
    290 		      ${WEBSOCKET_LIBRARIES}
    291 )
    292 
    293 SET_TARGET_PROPERTIES(vncclient vncserver
    294     PROPERTIES SOVERSION "0.0.0"
    295 )
    296 
    297 # tests
    298 set(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 
    314 if(Threads_FOUND)
    315   set(LIBVNCSERVER_TESTS
    316     ${LIBVNCSERVER_TESTS}
    317     blooptest
    318   )
    319 endif(Threads_FOUND)
    320 
    321 if(TIGHTVNC_FILETRANSFER)
    322   set(LIBVNCSERVER_TESTS
    323     ${LIBVNCSERVER_TESTS}
    324     filetransfer
    325   )
    326 endif(TIGHTVNC_FILETRANSFER)
    327 
    328 if(MACOS)
    329   set(LIBVNCSERVER_TESTS
    330     ${LIBVNCSERVER_TESTS}
    331     mac
    332   )
    333 endif(MACOS)
    334 
    335 set(LIBVNCCLIENT_TESTS
    336     backchannel
    337     ppmtest
    338 )
    339 
    340 if(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)
    347 endif(SDL_FOUND)
    348 
    349 if(HAVE_FFMPEG)
    350   set(LIBVNCCLIENT_TESTS
    351     ${LIBVNCCLIENT_TESTS}
    352     vnc2mpg
    353   )
    354 endif(HAVE_FFMPEG)
    355 
    356 
    357 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/examples)
    358 foreach(test ${LIBVNCSERVER_TESTS})
    359   add_executable(examples/${test} ${LIBVNCSRVTEST_DIR}/${test}.c)
    360   target_link_libraries(examples/${test} vncserver ${CMAKE_THREAD_LIBS_INIT})
    361 endforeach(test ${LIBVNCSERVER_TESTS})
    362 
    363 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/client_examples)
    364 foreach(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})
    367 endforeach(test ${LIBVNCCLIENT_TESTS})
    368 
    369 install_targets(/lib vncserver)
    370 install_targets(/lib vncclient)
    371 install_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