blob: b8507ab0d0b41c9d2d366ebeb30f6a915388e728 [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 Ossman5156d5e2011-03-09 09:42:34 +000018# Manual toggle until we can deprecate the old viewers
19option(BUILD_NEW_VNCVIEWER "Build the new FLTK based vncviewer instead of the old ones")
20
Pierre Ossman8f64ef72011-03-08 16:32:49 +000021# Compatibility variables for the migration from autotools
22add_definitions(-DPACKAGE_NAME="${CMAKE_PROJECT_NAME}")
23add_definitions(-DPACKAGE_VERSION="${VERSION}")
24add_definitions(-DLOCALEDIR="${CMAKE_INSTALL_PREFIX}/share/locale")
25
Pierre Ossmane8115162011-03-03 12:51:38 +000026# 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.
29set(BUILD "")
30if(MSVC)
DRC180c0162010-10-27 07:20:27 +000031 execute_process(COMMAND "${CMAKE_SOURCE_DIR}/cmakescripts/getdate.bat"
32 OUTPUT_VARIABLE BUILD)
DRC180c0162010-10-27 07:20:27 +000033else()
Pierre Ossmane8115162011-03-03 12:51:38 +000034 execute_process(COMMAND "date" "+%Y%m%d" OUTPUT_VARIABLE BUILD)
35endif()
36
37if(NOT BUILD)
38 set(BUILD "")
39else()
40 string(REGEX REPLACE "\n" "" BUILD ${BUILD})
DRC180c0162010-10-27 07:20:27 +000041endif()
42
Pierre Ossman2c66a632011-03-03 12:52:59 +000043# 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)
DRC180c0162010-10-27 07:20:27 +000045if(NOT CMAKE_BUILD_TYPE)
46 set(CMAKE_BUILD_TYPE Release)
47endif()
48
49message(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.
53if(CMAKE_BUILD_TYPE STREQUAL "Debug")
54 set(BUILD "${BUILD}d")
55endif()
56
57message(STATUS "VERSION = ${VERSION}, BUILD = ${BUILD}")
58
59if(NOT DEFINED BUILD_WINVNC)
60 if(MSVC)
61 set(BUILD_WINVNC 1)
62 else()
63 set(BUILD_WINVNC 0)
64 endif()
65endif()
66
67if(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)
82endif()
83
Pierre Ossman9640f442011-03-08 13:12:33 +000084# Minimum version is Windows 2000 (5.0)
85if(NOT CMAKE_SIZEOF_VOID_P MATCHES 8)
86 add_definitions(-D_WIN32_IE=0x0500 -D_WIN32_WINNT=0x0500)
87else()
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)
91endif()
92
Pierre Ossman69314c72011-03-08 12:18:13 +000093if(CMAKE_SIZEOF_VOID_P MATCHES 8)
DRC180c0162010-10-27 07:20:27 +000094 message(STATUS "64-bit build")
95else()
96 message(STATUS "32-bit build")
97endif()
98
99# CMake doesn't properly support resource compilation with MinGW. Boo!
100if(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>")
110endif()
111
Pierre Ossman8f64ef72011-03-08 16:32:49 +0000112# X11 stuff. It's in a if() so that we can say REQUIRED
113if(UNIX)
114 find_package(X11 REQUIRED)
115endif()
116
Pierre Ossmana7769f22011-03-03 09:44:49 +0000117# Check for zlib
118find_package(ZLIB)
119option(USE_INCLUDED_ZLIB "Force use of the bundled zlib")
120if(NOT ZLIB_FOUND)
121 message(STATUS "System zlib not found. Using included zlib")
122 set(USE_INCLUDED_ZLIB 1)
123endif()
124
Pierre Ossman4c6bd4c2011-03-03 09:55:21 +0000125# Check for libjpeg
126find_package(JPEG REQUIRED)
127
Pierre Ossman6fa07492011-03-04 11:35:24 +0000128# Warn if it doesn't seem to be the accelerated libjpeg that's found
Pierre Ossman6fa07492011-03-04 11:35:24 +0000129check_c_source_compiles("#include <stdio.h>\n#include <jpeglib.h>\nint main(int c, char** v) { return JCS_EXT_RGBX; }" FOUND_JPEG_TURBO)
130if(NOT FOUND_JPEG_TURBO)
131 message(STATUS "WARNING: You are not using libjpeg-turbo. Performance will suffer.")
132endif()
133
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000134# Check for FLTK
135if(BUILD_NEW_VNCVIEWER)
136 set(FLTK_SKIP_FLUID TRUE)
137 set(FLTK_SKIP_OPENGL TRUE)
138 find_package(FLTK COMPONENTS REQUIRED)
139endif()
140
Adam Tkac125bd252011-01-19 14:20:34 +0000141# Check for GNUTLS library
142find_package(GnuTLS)
143if(GNUTLS_FOUND)
144 include_directories(${GNUTLS_INCLUDE_DIR})
145 add_definitions("-DHAVE_GNUTLS")
146 add_definitions(${GNUTLS_DEFINITIONS})
Henrik Andersson2a032ad2011-03-08 15:32:24 +0000147
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 Ossmand0f0f032011-03-08 15:37:34 +0000153 check_type_size(gnutls_x509_crt_t GNUTLS_X509_CRT_T)
Henrik Andersson2a032ad2011-03-08 15:32:24 +0000154 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 Tkac125bd252011-01-19 14:20:34 +0000159endif()
160
Pierre Ossmanee0e3622011-03-08 13:08:15 +0000161# Check for socket functions
Henrik Anderssone1fd8e12011-03-08 13:00:12 +0000162if(WIN32)
Pierre Ossman0153e232011-03-08 13:05:27 +0000163 set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h ws2tcpip.h)
Henrik Anderssone1fd8e12011-03-08 13:00:12 +0000164 set(CMAKE_REQUIRED_LIBRARIES ws2_32)
Pierre Ossman0153e232011-03-08 13:05:27 +0000165else()
166 set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
Henrik Anderssone1fd8e12011-03-08 13:00:12 +0000167endif()
DRC63758092010-11-09 19:24:12 +0000168check_function_exists(inet_aton HAVE_INET_ATON)
169check_function_exists(inet_ntop HAVE_INET_NTOP)
Henrik Anderssone1fd8e12011-03-08 13:00:12 +0000170check_type_size(socklen_t SOCKLEN_T)
DRC63758092010-11-09 19:24:12 +0000171set(CMAKE_EXTRA_INCLUDE_FILES)
172set(CMAKE_REQUIRED_LIBRARIES)
Pierre Ossmanee0e3622011-03-08 13:08:15 +0000173
174# Check for the newer standard string functions
DRC63758092010-11-09 19:24:12 +0000175check_function_exists(snprintf HAVE_SNPRINTF)
176check_function_exists(strcasecmp HAVE_STRCASECMP)
177check_function_exists(strncasecmp HAVE_STRNCASECMP)
178check_function_exists(vsnprintf HAVE_VSNPRINTF)
Pierre Ossmanee0e3622011-03-08 13:08:15 +0000179
180# Generate config.h and make sure the source finds it
DRC63758092010-11-09 19:24:12 +0000181configure_file(config.h.cmake.in config.h)
182add_definitions(-DHAVE_CONFIG_H)
183include_directories(${CMAKE_BINARY_DIR})
DRC180c0162010-10-27 07:20:27 +0000184
DRC180c0162010-10-27 07:20:27 +0000185add_subdirectory(common)
Pierre Ossman8f64ef72011-03-08 16:32:49 +0000186
187if(WIN32)
188 add_subdirectory(win)
189else()
190 add_subdirectory(unix)
191endif()
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000192
193if(BUILD_NEW_VNCVIEWER)
194 add_subdirectory(vncviewer)
195endif()