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