blob: b5415ec02420337d8de10b660e7c971edc7b7556 [file] [log] [blame]
DRC180c0162010-10-27 07:20:27 +00001#
2# Setup
3#
4
5cmake_minimum_required(VERSION 2.6)
6
Pierre Ossmanb232b5f2011-04-28 14:38:04 +00007# Internal cmake modules
8set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
9
Pierre Ossman7f443262011-03-08 13:06:46 +000010include(CheckIncludeFiles)
11include(CheckFunctionExists)
Pierre Ossmanb232b5f2011-04-28 14:38:04 +000012include(CheckLibraryExists)
Pierre Ossman7f443262011-03-08 13:06:46 +000013include(CheckTypeSize)
14include(CheckCSourceCompiles)
Pierre Ossman89f868a2011-04-11 11:59:31 +000015include(CheckCXXSourceCompiles)
Pierre Ossman7f443262011-03-08 13:06:46 +000016
Peter Åstrandbb445ef2011-04-28 09:29:13 +000017project(tigervnc)
DRC180c0162010-10-27 07:20:27 +000018set(VERSION 1.0.90)
19
20# The RC version must always be four comma-separated numbers
21set(RCVERSION 1,0,90,0)
22
Pierre Ossman5156d5e2011-03-09 09:42:34 +000023# Manual toggle until we can deprecate the old viewers
24option(BUILD_NEW_VNCVIEWER "Build the new FLTK based vncviewer instead of the old ones")
25
Pierre Ossman8f64ef72011-03-08 16:32:49 +000026# Compatibility variables for the migration from autotools
27add_definitions(-DPACKAGE_NAME="${CMAKE_PROJECT_NAME}")
28add_definitions(-DPACKAGE_VERSION="${VERSION}")
29add_definitions(-DLOCALEDIR="${CMAKE_INSTALL_PREFIX}/share/locale")
30
Pierre Ossmane8115162011-03-03 12:51:38 +000031# Try to encode today's date into the build id. We assume that MSVC
32# means we need to use a native Windows method, otherwise we assume
33# some kind of Unix system. The id will be empty if things fail.
34set(BUILD "")
35if(MSVC)
Pierre Ossmanb232b5f2011-04-28 14:38:04 +000036 execute_process(COMMAND "${CMAKE_SOURCE_DIR}/cmake/getdate.bat"
DRC180c0162010-10-27 07:20:27 +000037 OUTPUT_VARIABLE BUILD)
DRC180c0162010-10-27 07:20:27 +000038else()
Pierre Ossmane8115162011-03-03 12:51:38 +000039 execute_process(COMMAND "date" "+%Y%m%d" OUTPUT_VARIABLE BUILD)
40endif()
41
42if(NOT BUILD)
43 set(BUILD "")
44else()
45 string(REGEX REPLACE "\n" "" BUILD ${BUILD})
DRC180c0162010-10-27 07:20:27 +000046endif()
47
Pierre Ossman2c66a632011-03-03 12:52:59 +000048# Default to optimised builds instead of debug ones. Our code has no bugs ;)
49# (CMake makes it fairly easy to toggle this back to Debug if needed)
DRC180c0162010-10-27 07:20:27 +000050if(NOT CMAKE_BUILD_TYPE)
51 set(CMAKE_BUILD_TYPE Release)
52endif()
53
54message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
55
56# This only works if building from the command line. There is currently no way
57# to set a variable's value based on the build type when using the MSVC IDE.
58if(CMAKE_BUILD_TYPE STREQUAL "Debug")
59 set(BUILD "${BUILD}d")
60endif()
61
62message(STATUS "VERSION = ${VERSION}, BUILD = ${BUILD}")
63
64if(NOT DEFINED BUILD_WINVNC)
65 if(MSVC)
66 set(BUILD_WINVNC 1)
67 else()
68 set(BUILD_WINVNC 0)
69 endif()
70endif()
71
72if(MSVC)
73 # Use the static C library for all build types
74 foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
75 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
76 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
77 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
78 if(${var} MATCHES "/MD")
79 string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
80 endif()
81 endforeach()
82
83 # NOTE: 4244 and 4267 are 64-bit to 32-bit conversion warnings, so normally
84 # it is not a good idea to disable them, but we do this to duplicate the
85 # behavior of GCC, which is less strict.
86 add_definitions(-wd4244 -wd4267 -wd4800 -wd4996)
87endif()
88
Pierre Ossman9640f442011-03-08 13:12:33 +000089# Minimum version is Windows 2000 (5.0)
90if(NOT CMAKE_SIZEOF_VOID_P MATCHES 8)
91 add_definitions(-D_WIN32_IE=0x0500 -D_WIN32_WINNT=0x0500)
92else()
93 # Win64 doesn't like us requesting a Windows version that didn't have
94 # 64-bit support. Request XP (5.1) instead.
95 add_definitions(-D_WIN32_IE=0x0501 -D_WIN32_WINNT=0x0501)
96endif()
97
Pierre Ossman69314c72011-03-08 12:18:13 +000098if(CMAKE_SIZEOF_VOID_P MATCHES 8)
DRC180c0162010-10-27 07:20:27 +000099 message(STATUS "64-bit build")
100else()
101 message(STATUS "32-bit build")
102endif()
103
104# CMake doesn't properly support resource compilation with MinGW. Boo!
105if(MINGW)
106 if(NOT DEFINED RC)
107 set(CMAKE_RC_COMPILER_INIT windres)
108 else()
109 set(CMAKE_RC_COMPILER_INIT ${RC})
110 endif()
111 enable_language(RC)
112 message(STATUS "Resource compiler: ${CMAKE_RC_COMPILER}")
113 set(CMAKE_RC_COMPILE_OBJECT
114 "<CMAKE_RC_COMPILER> <FLAGS> <DEFINES> -o <OBJECT> --output-format=coff <SOURCE>")
115endif()
116
Pierre Ossman8f64ef72011-03-08 16:32:49 +0000117# X11 stuff. It's in a if() so that we can say REQUIRED
118if(UNIX)
119 find_package(X11 REQUIRED)
120endif()
121
Pierre Ossmana7769f22011-03-03 09:44:49 +0000122# Check for zlib
123find_package(ZLIB)
124option(USE_INCLUDED_ZLIB "Force use of the bundled zlib")
125if(NOT ZLIB_FOUND)
126 message(STATUS "System zlib not found. Using included zlib")
127 set(USE_INCLUDED_ZLIB 1)
128endif()
129
Peter Åstrandbb445ef2011-04-28 09:29:13 +0000130# Check for gettext
131option(ENABLE_NLS "Enable translation of program messages" ON)
Pierre Ossmanb232b5f2011-04-28 14:38:04 +0000132if(ENABLE_NLS)
133 # Tools
134 find_package(Gettext REQUIRED)
135 set(LOCALE_DIR "${CMAKE_INSTALL_PREFIX}/share/locale")
136
137 # Gettext needs iconv
138 find_package(Iconv REQUIRED)
139
140 # Headers and libraries (copied from licq)
141 set(GETTEXT_FOUND FALSE)
142
143 find_path(GETTEXT_INCLUDE_DIR libintl.h)
144 if(GETTEXT_INCLUDE_DIR)
145 set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES})
146 check_function_exists(dgettext LIBC_HAS_DGETTEXT)
147 if(LIBC_HAS_DGETTEXT)
148 set(GETTEXT_FOUND TRUE)
149 else()
150 find_library(LIBINTL_LIBRARY NAMES intl libintl)
151 check_library_exists(${LIBINTL_LIBRARY} "dgettext" "" LIBINTL_HAS_DGETTEXT)
152 if(LIBINTL_HAS_DGETTEXT)
153 set(GETTEXT_LIBRARIES ${LIBINTL_LIBRARY})
154 set(GETTEXT_FOUND TRUE)
155 endif()
156 endif()
157 set(CMAKE_REQUIRED_LIBRARIES)
158 endif()
159
160 if(NOT GETTEXT_FOUND)
161 message(FATAL_ERROR "Gettext NOT found")
162 endif()
163endif()
Peter Åstrandbb445ef2011-04-28 09:29:13 +0000164
Pierre Ossman4c6bd4c2011-03-03 09:55:21 +0000165# Check for libjpeg
166find_package(JPEG REQUIRED)
167
Pierre Ossman6fa07492011-03-04 11:35:24 +0000168# Warn if it doesn't seem to be the accelerated libjpeg that's found
DRC63b40b72011-06-07 01:47:38 +0000169set(CMAKE_REQUIRED_LIBRARIES ${JPEG_LIBRARIES})
170set(CMAKE_REQUIRED_FLAGS -I${JPEG_INCLUDE_DIR})
DRCfe06e612011-06-07 01:55:12 +0000171
Pierre Ossman6fa07492011-03-04 11:35:24 +0000172check_c_source_compiles("#include <stdio.h>\n#include <jpeglib.h>\nint main(int c, char** v) { return JCS_EXT_RGBX; }" FOUND_JPEG_TURBO)
DRCfe06e612011-06-07 01:55:12 +0000173
174set(CMAKE_REQUIRED_LIBRARIES)
175set(CMAKE_REQUIRED_FLAGS)
176
Pierre Ossman6fa07492011-03-04 11:35:24 +0000177if(NOT FOUND_JPEG_TURBO)
178 message(STATUS "WARNING: You are not using libjpeg-turbo. Performance will suffer.")
179endif()
180
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000181# Check for FLTK
182if(BUILD_NEW_VNCVIEWER)
183 set(FLTK_SKIP_FLUID TRUE)
184 set(FLTK_SKIP_OPENGL TRUE)
185 find_package(FLTK COMPONENTS REQUIRED)
Pierre Ossman89f868a2011-04-11 11:59:31 +0000186
Pierre Ossman4a6be4a2011-05-19 14:49:18 +0000187 # No proper handling for extra X11 libs that FLTK might need...
Pierre Ossman34dde792011-05-24 07:49:09 +0000188 if(X11_Xft_FOUND)
189 set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xft_LIB})
190 endif()
191 if(X11_Xinerama_FOUND)
192 set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xinerama_LIB})
193 endif()
Pierre Ossman4a6be4a2011-05-19 14:49:18 +0000194 if(X11_Xfixes_FOUND)
195 set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xfixes_LIB})
196 endif()
197
Pierre Ossman89f868a2011-04-11 11:59:31 +0000198 set(CMAKE_REQUIRED_INCLUDES ${FLTK_INCLUDE_DIR})
199 set(CMAKE_REQUIRED_LIBRARIES ${FLTK_LIBRARIES})
Pierre Ossman4a6be4a2011-05-19 14:49:18 +0000200
201 # FLTK STR #2599
Pierre Ossmanf8c5ef62011-05-13 12:47:54 +0000202 check_cxx_source_compiles("#include <FL/Fl_Widget.H>\nint main(int c, char** v) { void *foo = (void*)&Fl_Widget::set_simple_keyboard; return 0; }" HAVE_FLTK_DEAD_KEYS)
Pierre Ossman4a6be4a2011-05-19 14:49:18 +0000203
204 # FLTK STR #2636
205 check_cxx_source_compiles("#include <FL/Fl.H>\nint main(int c, char** v) { Fl::add_clipboard_notify(NULL, NULL); return 0; }" HAVE_FLTK_CLIPBOARD)
206
Pierre Ossmancb0cffe2011-05-20 14:55:10 +0000207 # FLTK STR #2638
208 check_cxx_source_compiles("#include <FL/Enumerations.H>\nint main(int c, char** v) { return FL_Volume_Down; }" HAVE_FLTK_MEDIAKEYS)
209
Pierre Ossman4c613d32011-05-26 14:14:06 +0000210 # FLTK STR #2641
211 check_cxx_source_compiles("#include <FL/Enumerations.H>\nint main(int c, char** v) { return FL_FULLSCREEN; }" HAVE_FLTK_FULLSCREEN)
212
Pierre Ossman89f868a2011-04-11 11:59:31 +0000213 set(CMAKE_REQUIRED_INCLUDES)
214 set(CMAKE_REQUIRED_LIBRARIES)
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000215endif()
216
Adam Tkac125bd252011-01-19 14:20:34 +0000217# Check for GNUTLS library
Pierre Ossman95064202011-05-30 12:22:39 +0000218option(ENABLE_GNUTLS "Enable protocol encryption and advanced authentication" ON)
Pierre Ossman32c88c42011-05-27 11:50:58 +0000219if(ENABLE_GNUTLS)
Pierre Ossman95064202011-05-30 12:22:39 +0000220 find_package(GnuTLS)
221 if (GNUTLS_FOUND)
222 include_directories(${GNUTLS_INCLUDE_DIR})
223 add_definitions("-DHAVE_GNUTLS")
224 add_definitions(${GNUTLS_DEFINITIONS})
225
226 # Detect old version of GnuTLS
DRC17331b92011-06-07 04:07:20 +0000227 set(CMAKE_REQUIRED_FLAGS -I${GNUTLS_INCLUDE_DIR})
Pierre Ossman95064202011-05-30 12:22:39 +0000228 set(CMAKE_EXTRA_INCLUDE_FILES gnutls/gnutls.h)
DRC17331b92011-06-07 04:07:20 +0000229 set(CMAKE_REQUIRED_LIBRARIES ${GNUTLS_LIBRARIES})
230 if(ZLIB_FOUND)
231 # When we build against the static version of GnuTLS, we also use the
232 # included version of Zlib, but it isn't built yet, so we have to use the
233 # system's version (if available) to perform this test.
234 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES};-lz)
235 endif()
Pierre Ossman95064202011-05-30 12:22:39 +0000236 check_function_exists(gnutls_transport_set_global_errno HAVE_OLD_GNUTLS)
237 check_function_exists(gnutls_x509_crt_print HAVE_GNUTLS_X509_CRT_PRINT)
238 check_type_size(gnutls_x509_crt_t GNUTLS_X509_CRT_T)
239 check_type_size(gnutls_datum_t GNUTLS_DATUM_T)
240 check_type_size(gnutls_pk_algorithm_t GNUTLS_PK_ALGORITHM_T)
241 check_type_size(gnutls_sign_algorithm_t GNUTLS_SIGN_ALGORITHM_T)
DRC17331b92011-06-07 04:07:20 +0000242 set(CMAKE_REQUIRED_FLAGS)
Pierre Ossman95064202011-05-30 12:22:39 +0000243 set(CMAKE_EXTRA_INCLUDE_FILES)
244 set(CMAKE_REQUIRED_LIBRARIES)
245 endif()
Adam Tkac125bd252011-01-19 14:20:34 +0000246endif()
247
Pierre Ossmanee0e3622011-03-08 13:08:15 +0000248# Check for socket functions
Henrik Anderssone1fd8e12011-03-08 13:00:12 +0000249if(WIN32)
Pierre Ossman0153e232011-03-08 13:05:27 +0000250 set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h ws2tcpip.h)
Henrik Anderssone1fd8e12011-03-08 13:00:12 +0000251 set(CMAKE_REQUIRED_LIBRARIES ws2_32)
Pierre Ossman0153e232011-03-08 13:05:27 +0000252else()
253 set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
Henrik Anderssone1fd8e12011-03-08 13:00:12 +0000254endif()
DRC63758092010-11-09 19:24:12 +0000255check_function_exists(inet_aton HAVE_INET_ATON)
256check_function_exists(inet_ntop HAVE_INET_NTOP)
Henrik Anderssone1fd8e12011-03-08 13:00:12 +0000257check_type_size(socklen_t SOCKLEN_T)
DRC63758092010-11-09 19:24:12 +0000258set(CMAKE_EXTRA_INCLUDE_FILES)
259set(CMAKE_REQUIRED_LIBRARIES)
Pierre Ossmanee0e3622011-03-08 13:08:15 +0000260
261# Check for the newer standard string functions
DRC63758092010-11-09 19:24:12 +0000262check_function_exists(snprintf HAVE_SNPRINTF)
263check_function_exists(strcasecmp HAVE_STRCASECMP)
264check_function_exists(strncasecmp HAVE_STRNCASECMP)
265check_function_exists(vsnprintf HAVE_VSNPRINTF)
Pierre Ossmanee0e3622011-03-08 13:08:15 +0000266
267# Generate config.h and make sure the source finds it
DRC63758092010-11-09 19:24:12 +0000268configure_file(config.h.cmake.in config.h)
269add_definitions(-DHAVE_CONFIG_H)
270include_directories(${CMAKE_BINARY_DIR})
DRC180c0162010-10-27 07:20:27 +0000271
DRC180c0162010-10-27 07:20:27 +0000272add_subdirectory(common)
Pierre Ossman8f64ef72011-03-08 16:32:49 +0000273
274if(WIN32)
275 add_subdirectory(win)
276else()
277 add_subdirectory(unix)
278endif()
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000279
280if(BUILD_NEW_VNCVIEWER)
DRCd0b64c92011-06-07 04:07:41 +0000281 if(ENABLE_NLS)
282 add_subdirectory(po)
283 endif()
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000284 add_subdirectory(vncviewer)
285endif()