DRC | 180c016 | 2010-10-27 07:20:27 +0000 | [diff] [blame] | 1 | # |
| 2 | # Setup |
| 3 | # |
| 4 | |
| 5 | cmake_minimum_required(VERSION 2.6) |
| 6 | |
Pierre Ossman | 7f44326 | 2011-03-08 13:06:46 +0000 | [diff] [blame] | 7 | include(CheckIncludeFiles) |
| 8 | include(CheckFunctionExists) |
| 9 | include(CheckTypeSize) |
| 10 | include(CheckCSourceCompiles) |
Pierre Ossman | 89f868a | 2011-04-11 11:59:31 +0000 | [diff] [blame] | 11 | include(CheckCXXSourceCompiles) |
Pierre Ossman | 7f44326 | 2011-03-08 13:06:46 +0000 | [diff] [blame] | 12 | |
DRC | 180c016 | 2010-10-27 07:20:27 +0000 | [diff] [blame] | 13 | project(TigerVNC) |
| 14 | set(VERSION 1.0.90) |
| 15 | |
| 16 | # The RC version must always be four comma-separated numbers |
| 17 | set(RCVERSION 1,0,90,0) |
| 18 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 19 | # Manual toggle until we can deprecate the old viewers |
| 20 | option(BUILD_NEW_VNCVIEWER "Build the new FLTK based vncviewer instead of the old ones") |
| 21 | |
Pierre Ossman | 8f64ef7 | 2011-03-08 16:32:49 +0000 | [diff] [blame] | 22 | # Compatibility variables for the migration from autotools |
| 23 | add_definitions(-DPACKAGE_NAME="${CMAKE_PROJECT_NAME}") |
| 24 | add_definitions(-DPACKAGE_VERSION="${VERSION}") |
| 25 | add_definitions(-DLOCALEDIR="${CMAKE_INSTALL_PREFIX}/share/locale") |
| 26 | |
Pierre Ossman | e811516 | 2011-03-03 12:51:38 +0000 | [diff] [blame] | 27 | # Try to encode today's date into the build id. We assume that MSVC |
| 28 | # means we need to use a native Windows method, otherwise we assume |
| 29 | # some kind of Unix system. The id will be empty if things fail. |
| 30 | set(BUILD "") |
| 31 | if(MSVC) |
DRC | 180c016 | 2010-10-27 07:20:27 +0000 | [diff] [blame] | 32 | execute_process(COMMAND "${CMAKE_SOURCE_DIR}/cmakescripts/getdate.bat" |
| 33 | OUTPUT_VARIABLE BUILD) |
DRC | 180c016 | 2010-10-27 07:20:27 +0000 | [diff] [blame] | 34 | else() |
Pierre Ossman | e811516 | 2011-03-03 12:51:38 +0000 | [diff] [blame] | 35 | execute_process(COMMAND "date" "+%Y%m%d" OUTPUT_VARIABLE BUILD) |
| 36 | endif() |
| 37 | |
| 38 | if(NOT BUILD) |
| 39 | set(BUILD "") |
| 40 | else() |
| 41 | string(REGEX REPLACE "\n" "" BUILD ${BUILD}) |
DRC | 180c016 | 2010-10-27 07:20:27 +0000 | [diff] [blame] | 42 | endif() |
| 43 | |
Pierre Ossman | 2c66a63 | 2011-03-03 12:52:59 +0000 | [diff] [blame] | 44 | # Default to optimised builds instead of debug ones. Our code has no bugs ;) |
| 45 | # (CMake makes it fairly easy to toggle this back to Debug if needed) |
DRC | 180c016 | 2010-10-27 07:20:27 +0000 | [diff] [blame] | 46 | if(NOT CMAKE_BUILD_TYPE) |
| 47 | set(CMAKE_BUILD_TYPE Release) |
| 48 | endif() |
| 49 | |
| 50 | message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}") |
| 51 | |
| 52 | # This only works if building from the command line. There is currently no way |
| 53 | # to set a variable's value based on the build type when using the MSVC IDE. |
| 54 | if(CMAKE_BUILD_TYPE STREQUAL "Debug") |
| 55 | set(BUILD "${BUILD}d") |
| 56 | endif() |
| 57 | |
| 58 | message(STATUS "VERSION = ${VERSION}, BUILD = ${BUILD}") |
| 59 | |
| 60 | if(NOT DEFINED BUILD_WINVNC) |
| 61 | if(MSVC) |
| 62 | set(BUILD_WINVNC 1) |
| 63 | else() |
| 64 | set(BUILD_WINVNC 0) |
| 65 | endif() |
| 66 | endif() |
| 67 | |
| 68 | if(MSVC) |
| 69 | # Use the static C library for all build types |
| 70 | foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE |
| 71 | CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO |
| 72 | CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE |
| 73 | CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) |
| 74 | if(${var} MATCHES "/MD") |
| 75 | string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}") |
| 76 | endif() |
| 77 | endforeach() |
| 78 | |
| 79 | # NOTE: 4244 and 4267 are 64-bit to 32-bit conversion warnings, so normally |
| 80 | # it is not a good idea to disable them, but we do this to duplicate the |
| 81 | # behavior of GCC, which is less strict. |
| 82 | add_definitions(-wd4244 -wd4267 -wd4800 -wd4996) |
| 83 | endif() |
| 84 | |
Pierre Ossman | 9640f44 | 2011-03-08 13:12:33 +0000 | [diff] [blame] | 85 | # Minimum version is Windows 2000 (5.0) |
| 86 | if(NOT CMAKE_SIZEOF_VOID_P MATCHES 8) |
| 87 | add_definitions(-D_WIN32_IE=0x0500 -D_WIN32_WINNT=0x0500) |
| 88 | else() |
| 89 | # Win64 doesn't like us requesting a Windows version that didn't have |
| 90 | # 64-bit support. Request XP (5.1) instead. |
| 91 | add_definitions(-D_WIN32_IE=0x0501 -D_WIN32_WINNT=0x0501) |
| 92 | endif() |
| 93 | |
Pierre Ossman | 69314c7 | 2011-03-08 12:18:13 +0000 | [diff] [blame] | 94 | if(CMAKE_SIZEOF_VOID_P MATCHES 8) |
DRC | 180c016 | 2010-10-27 07:20:27 +0000 | [diff] [blame] | 95 | message(STATUS "64-bit build") |
| 96 | else() |
| 97 | message(STATUS "32-bit build") |
| 98 | endif() |
| 99 | |
| 100 | # CMake doesn't properly support resource compilation with MinGW. Boo! |
| 101 | if(MINGW) |
| 102 | if(NOT DEFINED RC) |
| 103 | set(CMAKE_RC_COMPILER_INIT windres) |
| 104 | else() |
| 105 | set(CMAKE_RC_COMPILER_INIT ${RC}) |
| 106 | endif() |
| 107 | enable_language(RC) |
| 108 | message(STATUS "Resource compiler: ${CMAKE_RC_COMPILER}") |
| 109 | set(CMAKE_RC_COMPILE_OBJECT |
| 110 | "<CMAKE_RC_COMPILER> <FLAGS> <DEFINES> -o <OBJECT> --output-format=coff <SOURCE>") |
| 111 | endif() |
| 112 | |
Pierre Ossman | 8f64ef7 | 2011-03-08 16:32:49 +0000 | [diff] [blame] | 113 | # X11 stuff. It's in a if() so that we can say REQUIRED |
| 114 | if(UNIX) |
| 115 | find_package(X11 REQUIRED) |
| 116 | endif() |
| 117 | |
Pierre Ossman | a7769f2 | 2011-03-03 09:44:49 +0000 | [diff] [blame] | 118 | # Check for zlib |
| 119 | find_package(ZLIB) |
| 120 | option(USE_INCLUDED_ZLIB "Force use of the bundled zlib") |
| 121 | if(NOT ZLIB_FOUND) |
| 122 | message(STATUS "System zlib not found. Using included zlib") |
| 123 | set(USE_INCLUDED_ZLIB 1) |
| 124 | endif() |
| 125 | |
Pierre Ossman | 4c6bd4c | 2011-03-03 09:55:21 +0000 | [diff] [blame] | 126 | # Check for libjpeg |
| 127 | find_package(JPEG REQUIRED) |
| 128 | |
Pierre Ossman | 6fa0749 | 2011-03-04 11:35:24 +0000 | [diff] [blame] | 129 | # Warn if it doesn't seem to be the accelerated libjpeg that's found |
Pierre Ossman | 6fa0749 | 2011-03-04 11:35:24 +0000 | [diff] [blame] | 130 | check_c_source_compiles("#include <stdio.h>\n#include <jpeglib.h>\nint main(int c, char** v) { return JCS_EXT_RGBX; }" FOUND_JPEG_TURBO) |
| 131 | if(NOT FOUND_JPEG_TURBO) |
| 132 | message(STATUS "WARNING: You are not using libjpeg-turbo. Performance will suffer.") |
| 133 | endif() |
| 134 | |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 135 | # Check for FLTK |
| 136 | if(BUILD_NEW_VNCVIEWER) |
| 137 | set(FLTK_SKIP_FLUID TRUE) |
| 138 | set(FLTK_SKIP_OPENGL TRUE) |
| 139 | find_package(FLTK COMPONENTS REQUIRED) |
Pierre Ossman | 89f868a | 2011-04-11 11:59:31 +0000 | [diff] [blame] | 140 | |
| 141 | # FLTK STR #2599 |
| 142 | set(CMAKE_REQUIRED_INCLUDES ${FLTK_INCLUDE_DIR}) |
| 143 | set(CMAKE_REQUIRED_LIBRARIES ${FLTK_LIBRARIES}) |
| 144 | check_cxx_source_compiles("#include <FL/Fl.H>\nint main(int c, char** v) { Fl::event_compose_symbol(); return 0; }" HAVE_FLTK_DEAD_KEYS) |
| 145 | set(CMAKE_REQUIRED_INCLUDES) |
| 146 | set(CMAKE_REQUIRED_LIBRARIES) |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 147 | endif() |
| 148 | |
Adam Tkac | 125bd25 | 2011-01-19 14:20:34 +0000 | [diff] [blame] | 149 | # Check for GNUTLS library |
| 150 | find_package(GnuTLS) |
| 151 | if(GNUTLS_FOUND) |
| 152 | include_directories(${GNUTLS_INCLUDE_DIR}) |
| 153 | add_definitions("-DHAVE_GNUTLS") |
| 154 | add_definitions(${GNUTLS_DEFINITIONS}) |
Henrik Andersson | 2a032ad | 2011-03-08 15:32:24 +0000 | [diff] [blame] | 155 | |
| 156 | # Detect old version of GnuTLS |
| 157 | set(CMAKE_EXTRA_INCLUDE_FILES gnutls/gnutls.h) |
| 158 | set(CMAKE_REQUIRED_LIBRARIES gnutls) |
| 159 | check_function_exists(gnutls_transport_set_global_errno HAVE_OLD_GNUTLS) |
| 160 | check_function_exists(gnutls_x509_crt_print HAVE_GNUTLS_X509_CRT_PRINT) |
Pierre Ossman | d0f0f03 | 2011-03-08 15:37:34 +0000 | [diff] [blame] | 161 | check_type_size(gnutls_x509_crt_t GNUTLS_X509_CRT_T) |
Henrik Andersson | 2a032ad | 2011-03-08 15:32:24 +0000 | [diff] [blame] | 162 | check_type_size(gnutls_datum_t GNUTLS_DATUM_T) |
| 163 | check_type_size(gnutls_pk_algorithm_t GNUTLS_PK_ALGORITHM_T) |
| 164 | check_type_size(gnutls_sign_algorithm_t GNUTLS_SIGN_ALGORITHM_T) |
| 165 | set(CMAKE_EXTRA_INCLUDE_FILES) |
| 166 | set(CMAKE_REQUIRED_LIBRARIES) |
Adam Tkac | 125bd25 | 2011-01-19 14:20:34 +0000 | [diff] [blame] | 167 | endif() |
| 168 | |
Pierre Ossman | ee0e362 | 2011-03-08 13:08:15 +0000 | [diff] [blame] | 169 | # Check for socket functions |
Henrik Andersson | e1fd8e1 | 2011-03-08 13:00:12 +0000 | [diff] [blame] | 170 | if(WIN32) |
Pierre Ossman | 0153e23 | 2011-03-08 13:05:27 +0000 | [diff] [blame] | 171 | set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h ws2tcpip.h) |
Henrik Andersson | e1fd8e1 | 2011-03-08 13:00:12 +0000 | [diff] [blame] | 172 | set(CMAKE_REQUIRED_LIBRARIES ws2_32) |
Pierre Ossman | 0153e23 | 2011-03-08 13:05:27 +0000 | [diff] [blame] | 173 | else() |
| 174 | set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h) |
Henrik Andersson | e1fd8e1 | 2011-03-08 13:00:12 +0000 | [diff] [blame] | 175 | endif() |
DRC | 6375809 | 2010-11-09 19:24:12 +0000 | [diff] [blame] | 176 | check_function_exists(inet_aton HAVE_INET_ATON) |
| 177 | check_function_exists(inet_ntop HAVE_INET_NTOP) |
Henrik Andersson | e1fd8e1 | 2011-03-08 13:00:12 +0000 | [diff] [blame] | 178 | check_type_size(socklen_t SOCKLEN_T) |
DRC | 6375809 | 2010-11-09 19:24:12 +0000 | [diff] [blame] | 179 | set(CMAKE_EXTRA_INCLUDE_FILES) |
| 180 | set(CMAKE_REQUIRED_LIBRARIES) |
Pierre Ossman | ee0e362 | 2011-03-08 13:08:15 +0000 | [diff] [blame] | 181 | |
| 182 | # Check for the newer standard string functions |
DRC | 6375809 | 2010-11-09 19:24:12 +0000 | [diff] [blame] | 183 | check_function_exists(snprintf HAVE_SNPRINTF) |
| 184 | check_function_exists(strcasecmp HAVE_STRCASECMP) |
| 185 | check_function_exists(strncasecmp HAVE_STRNCASECMP) |
| 186 | check_function_exists(vsnprintf HAVE_VSNPRINTF) |
Pierre Ossman | ee0e362 | 2011-03-08 13:08:15 +0000 | [diff] [blame] | 187 | |
| 188 | # Generate config.h and make sure the source finds it |
DRC | 6375809 | 2010-11-09 19:24:12 +0000 | [diff] [blame] | 189 | configure_file(config.h.cmake.in config.h) |
| 190 | add_definitions(-DHAVE_CONFIG_H) |
| 191 | include_directories(${CMAKE_BINARY_DIR}) |
DRC | 180c016 | 2010-10-27 07:20:27 +0000 | [diff] [blame] | 192 | |
DRC | 180c016 | 2010-10-27 07:20:27 +0000 | [diff] [blame] | 193 | add_subdirectory(common) |
Pierre Ossman | 8f64ef7 | 2011-03-08 16:32:49 +0000 | [diff] [blame] | 194 | |
| 195 | if(WIN32) |
| 196 | add_subdirectory(win) |
| 197 | else() |
| 198 | add_subdirectory(unix) |
| 199 | endif() |
Pierre Ossman | 5156d5e | 2011-03-09 09:42:34 +0000 | [diff] [blame] | 200 | |
| 201 | if(BUILD_NEW_VNCVIEWER) |
| 202 | add_subdirectory(vncviewer) |
| 203 | endif() |