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