blob: 64360aa542621e688009b316f6c80c82841bc572 [file] [log] [blame]
DRC180c0162010-10-27 07:20:27 +00001#
2# Setup
3#
4
5cmake_minimum_required(VERSION 2.6)
6
Pierre Ossman7f443262011-03-08 13:06:46 +00007include(CheckIncludeFiles)
8include(CheckFunctionExists)
9include(CheckTypeSize)
10include(CheckCSourceCompiles)
11
DRC180c0162010-10-27 07:20:27 +000012project(TigerVNC)
13set(VERSION 1.0.90)
14
15# The RC version must always be four comma-separated numbers
16set(RCVERSION 1,0,90,0)
17
Pierre Ossmane8115162011-03-03 12:51:38 +000018# 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.
21set(BUILD "")
22if(MSVC)
DRC180c0162010-10-27 07:20:27 +000023 execute_process(COMMAND "${CMAKE_SOURCE_DIR}/cmakescripts/getdate.bat"
24 OUTPUT_VARIABLE BUILD)
DRC180c0162010-10-27 07:20:27 +000025else()
Pierre Ossmane8115162011-03-03 12:51:38 +000026 execute_process(COMMAND "date" "+%Y%m%d" OUTPUT_VARIABLE BUILD)
27endif()
28
29if(NOT BUILD)
30 set(BUILD "")
31else()
32 string(REGEX REPLACE "\n" "" BUILD ${BUILD})
DRC180c0162010-10-27 07:20:27 +000033endif()
34
Pierre Ossman2c66a632011-03-03 12:52:59 +000035# 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)
DRC180c0162010-10-27 07:20:27 +000037if(NOT CMAKE_BUILD_TYPE)
38 set(CMAKE_BUILD_TYPE Release)
39endif()
40
41message(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.
45if(CMAKE_BUILD_TYPE STREQUAL "Debug")
46 set(BUILD "${BUILD}d")
47endif()
48
49message(STATUS "VERSION = ${VERSION}, BUILD = ${BUILD}")
50
51if(NOT DEFINED BUILD_WINVNC)
52 if(MSVC)
53 set(BUILD_WINVNC 1)
54 else()
55 set(BUILD_WINVNC 0)
56 endif()
57endif()
58
59if(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)
74endif()
75
Pierre Ossman9640f442011-03-08 13:12:33 +000076# Minimum version is Windows 2000 (5.0)
77if(NOT CMAKE_SIZEOF_VOID_P MATCHES 8)
78 add_definitions(-D_WIN32_IE=0x0500 -D_WIN32_WINNT=0x0500)
79else()
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)
83endif()
84
Pierre Ossman69314c72011-03-08 12:18:13 +000085if(CMAKE_SIZEOF_VOID_P MATCHES 8)
DRC180c0162010-10-27 07:20:27 +000086 message(STATUS "64-bit build")
87else()
88 message(STATUS "32-bit build")
89endif()
90
91# CMake doesn't properly support resource compilation with MinGW. Boo!
92if(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>")
102endif()
103
Pierre Ossmana7769f22011-03-03 09:44:49 +0000104# Check for zlib
105find_package(ZLIB)
106option(USE_INCLUDED_ZLIB "Force use of the bundled zlib")
107if(NOT ZLIB_FOUND)
108 message(STATUS "System zlib not found. Using included zlib")
109 set(USE_INCLUDED_ZLIB 1)
110endif()
111
Pierre Ossman4c6bd4c2011-03-03 09:55:21 +0000112# Check for libjpeg
113find_package(JPEG REQUIRED)
114
Pierre Ossman6fa07492011-03-04 11:35:24 +0000115# Warn if it doesn't seem to be the accelerated libjpeg that's found
Pierre Ossman6fa07492011-03-04 11:35:24 +0000116check_c_source_compiles("#include <stdio.h>\n#include <jpeglib.h>\nint main(int c, char** v) { return JCS_EXT_RGBX; }" FOUND_JPEG_TURBO)
117if(NOT FOUND_JPEG_TURBO)
118 message(STATUS "WARNING: You are not using libjpeg-turbo. Performance will suffer.")
119endif()
120
Adam Tkac125bd252011-01-19 14:20:34 +0000121# Check for GNUTLS library
122find_package(GnuTLS)
123if(GNUTLS_FOUND)
124 include_directories(${GNUTLS_INCLUDE_DIR})
125 add_definitions("-DHAVE_GNUTLS")
126 add_definitions(${GNUTLS_DEFINITIONS})
Henrik Andersson2a032ad2011-03-08 15:32:24 +0000127
128 # Detect old version of GnuTLS
129 set(CMAKE_EXTRA_INCLUDE_FILES gnutls/gnutls.h)
130 set(CMAKE_REQUIRED_LIBRARIES gnutls)
131 check_function_exists(gnutls_transport_set_global_errno HAVE_OLD_GNUTLS)
132 check_function_exists(gnutls_x509_crt_print HAVE_GNUTLS_X509_CRT_PRINT)
133 check_type_size(gnutls_x509_crt_t GNUTLS_CRT_T)
134 check_type_size(gnutls_datum_t GNUTLS_DATUM_T)
135 check_type_size(gnutls_pk_algorithm_t GNUTLS_PK_ALGORITHM_T)
136 check_type_size(gnutls_sign_algorithm_t GNUTLS_SIGN_ALGORITHM_T)
137 set(CMAKE_EXTRA_INCLUDE_FILES)
138 set(CMAKE_REQUIRED_LIBRARIES)
Adam Tkac125bd252011-01-19 14:20:34 +0000139endif()
140
Pierre Ossmanee0e3622011-03-08 13:08:15 +0000141# Check for socket functions
Henrik Anderssone1fd8e12011-03-08 13:00:12 +0000142if(WIN32)
Pierre Ossman0153e232011-03-08 13:05:27 +0000143 set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h ws2tcpip.h)
Henrik Anderssone1fd8e12011-03-08 13:00:12 +0000144 set(CMAKE_REQUIRED_LIBRARIES ws2_32)
Pierre Ossman0153e232011-03-08 13:05:27 +0000145else()
146 set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
Henrik Anderssone1fd8e12011-03-08 13:00:12 +0000147endif()
DRC63758092010-11-09 19:24:12 +0000148check_function_exists(inet_aton HAVE_INET_ATON)
149check_function_exists(inet_ntop HAVE_INET_NTOP)
Henrik Anderssone1fd8e12011-03-08 13:00:12 +0000150check_type_size(socklen_t SOCKLEN_T)
DRC63758092010-11-09 19:24:12 +0000151set(CMAKE_EXTRA_INCLUDE_FILES)
152set(CMAKE_REQUIRED_LIBRARIES)
Pierre Ossmanee0e3622011-03-08 13:08:15 +0000153
154# Check for the newer standard string functions
DRC63758092010-11-09 19:24:12 +0000155check_function_exists(snprintf HAVE_SNPRINTF)
156check_function_exists(strcasecmp HAVE_STRCASECMP)
157check_function_exists(strncasecmp HAVE_STRNCASECMP)
158check_function_exists(vsnprintf HAVE_VSNPRINTF)
Pierre Ossmanee0e3622011-03-08 13:08:15 +0000159
160# Generate config.h and make sure the source finds it
DRC63758092010-11-09 19:24:12 +0000161configure_file(config.h.cmake.in config.h)
162add_definitions(-DHAVE_CONFIG_H)
163include_directories(${CMAKE_BINARY_DIR})
DRC180c0162010-10-27 07:20:27 +0000164
DRC180c0162010-10-27 07:20:27 +0000165add_subdirectory(common)
166add_subdirectory(win)