blob: ba72c99236bdf7905ca5dc8fa4f8bcd3de1d4bb3 [file] [log] [blame]
DRC180c0162010-10-27 07:20:27 +00001#
2# Setup
3#
4
DRCaeff3312011-06-07 04:51:57 +00005cmake_minimum_required(VERSION 2.8)
DRC180c0162010-10-27 07:20:27 +00006
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
Henrik Andersson23029cc2011-06-09 09:13:23 +000017include(CMakeMacroLibtoolFile)
18
Peter Åstrandbb445ef2011-04-28 09:29:13 +000019project(tigervnc)
DRCde30d952011-06-24 20:05:06 +000020set(VERSION 1.1.80)
DRC180c0162010-10-27 07:20:27 +000021
22# The RC version must always be four comma-separated numbers
DRCde30d952011-06-24 20:05:06 +000023set(RCVERSION 1,1,80,0)
DRC180c0162010-10-27 07:20:27 +000024
Pierre Ossman5156d5e2011-03-09 09:42:34 +000025# Manual toggle until we can deprecate the old viewers
DRCde22ae92011-06-23 16:45:18 +000026option(BUILD_NEW_VNCVIEWER "Build the new FLTK based vncviewer instead of the old ones" ON)
Pierre Ossman5156d5e2011-03-09 09:42:34 +000027
Pierre Ossman8f64ef72011-03-08 16:32:49 +000028# Compatibility variables for the migration from autotools
29add_definitions(-DPACKAGE_NAME="${CMAKE_PROJECT_NAME}")
30add_definitions(-DPACKAGE_VERSION="${VERSION}")
31add_definitions(-DLOCALEDIR="${CMAKE_INSTALL_PREFIX}/share/locale")
32
Pierre Ossmane8115162011-03-03 12:51:38 +000033# Try to encode today's date into the build id. We assume that MSVC
34# means we need to use a native Windows method, otherwise we assume
35# some kind of Unix system. The id will be empty if things fail.
36set(BUILD "")
37if(MSVC)
Pierre Ossmanb232b5f2011-04-28 14:38:04 +000038 execute_process(COMMAND "${CMAKE_SOURCE_DIR}/cmake/getdate.bat"
DRC180c0162010-10-27 07:20:27 +000039 OUTPUT_VARIABLE BUILD)
DRC180c0162010-10-27 07:20:27 +000040else()
Pierre Ossmane8115162011-03-03 12:51:38 +000041 execute_process(COMMAND "date" "+%Y%m%d" OUTPUT_VARIABLE BUILD)
42endif()
43
44if(NOT BUILD)
45 set(BUILD "")
46else()
47 string(REGEX REPLACE "\n" "" BUILD ${BUILD})
DRC180c0162010-10-27 07:20:27 +000048endif()
49
Pierre Ossman2c66a632011-03-03 12:52:59 +000050# Default to optimised builds instead of debug ones. Our code has no bugs ;)
51# (CMake makes it fairly easy to toggle this back to Debug if needed)
DRC180c0162010-10-27 07:20:27 +000052if(NOT CMAKE_BUILD_TYPE)
53 set(CMAKE_BUILD_TYPE Release)
54endif()
55
56message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
57
58# This only works if building from the command line. There is currently no way
59# to set a variable's value based on the build type when using the MSVC IDE.
60if(CMAKE_BUILD_TYPE STREQUAL "Debug")
61 set(BUILD "${BUILD}d")
62endif()
63
64message(STATUS "VERSION = ${VERSION}, BUILD = ${BUILD}")
65
66if(NOT DEFINED BUILD_WINVNC)
67 if(MSVC)
68 set(BUILD_WINVNC 1)
69 else()
70 set(BUILD_WINVNC 0)
71 endif()
72endif()
73
74if(MSVC)
75 # Use the static C library for all build types
76 foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
77 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
78 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
79 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
80 if(${var} MATCHES "/MD")
81 string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
82 endif()
83 endforeach()
84
85 # NOTE: 4244 and 4267 are 64-bit to 32-bit conversion warnings, so normally
86 # it is not a good idea to disable them, but we do this to duplicate the
87 # behavior of GCC, which is less strict.
88 add_definitions(-wd4244 -wd4267 -wd4800 -wd4996)
89endif()
90
Pierre Ossman9640f442011-03-08 13:12:33 +000091# Minimum version is Windows 2000 (5.0)
DRC2301beb2011-06-22 05:46:53 +000092if(WIN32)
93 if(NOT CMAKE_SIZEOF_VOID_P MATCHES 8)
94 add_definitions(-D_WIN32_IE=0x0500 -D_WIN32_WINNT=0x0500)
95 else()
DRC7cf9fbc2011-07-06 07:23:51 +000096 set(WIN64 1)
DRC2301beb2011-06-22 05:46:53 +000097 # Win64 doesn't like us requesting a Windows version that didn't have
98 # 64-bit support. Request XP (5.1) instead.
99 add_definitions(-D_WIN32_IE=0x0501 -D_WIN32_WINNT=0x0501)
100 endif()
Pierre Ossman9640f442011-03-08 13:12:33 +0000101endif()
102
Pierre Ossman69314c72011-03-08 12:18:13 +0000103if(CMAKE_SIZEOF_VOID_P MATCHES 8)
DRC180c0162010-10-27 07:20:27 +0000104 message(STATUS "64-bit build")
105else()
106 message(STATUS "32-bit build")
107endif()
108
109# CMake doesn't properly support resource compilation with MinGW. Boo!
110if(MINGW)
111 if(NOT DEFINED RC)
112 set(CMAKE_RC_COMPILER_INIT windres)
113 else()
114 set(CMAKE_RC_COMPILER_INIT ${RC})
115 endif()
116 enable_language(RC)
117 message(STATUS "Resource compiler: ${CMAKE_RC_COMPILER}")
118 set(CMAKE_RC_COMPILE_OBJECT
119 "<CMAKE_RC_COMPILER> <FLAGS> <DEFINES> -o <OBJECT> --output-format=coff <SOURCE>")
120endif()
121
Pierre Ossman8f64ef72011-03-08 16:32:49 +0000122# X11 stuff. It's in a if() so that we can say REQUIRED
DRC1b7abb92011-06-23 19:12:08 +0000123if(UNIX AND NOT APPLE)
Pierre Ossman8f64ef72011-03-08 16:32:49 +0000124 find_package(X11 REQUIRED)
125endif()
126
Pierre Ossmana7769f22011-03-03 09:44:49 +0000127# Check for zlib
128find_package(ZLIB)
129option(USE_INCLUDED_ZLIB "Force use of the bundled zlib")
130if(NOT ZLIB_FOUND)
131 message(STATUS "System zlib not found. Using included zlib")
132 set(USE_INCLUDED_ZLIB 1)
133endif()
134
Peter Åstrandbb445ef2011-04-28 09:29:13 +0000135# Check for gettext
136option(ENABLE_NLS "Enable translation of program messages" ON)
Pierre Ossmanb232b5f2011-04-28 14:38:04 +0000137if(ENABLE_NLS)
138 # Tools
DRC2690f7a2011-06-24 04:17:02 +0000139 find_package(Gettext)
Pierre Ossmanb232b5f2011-04-28 14:38:04 +0000140 set(LOCALE_DIR "${CMAKE_INSTALL_PREFIX}/share/locale")
141
142 # Gettext needs iconv
DRC2690f7a2011-06-24 04:17:02 +0000143 find_package(Iconv)
Pierre Ossmanb232b5f2011-04-28 14:38:04 +0000144
DRC2690f7a2011-06-24 04:17:02 +0000145 if(ICONV_FOUND)
146 # Headers and libraries (copied from licq)
147 set(GETTEXT_FOUND FALSE)
Pierre Ossmanb232b5f2011-04-28 14:38:04 +0000148
DRC2690f7a2011-06-24 04:17:02 +0000149 find_path(GETTEXT_INCLUDE_DIR libintl.h)
150 if(GETTEXT_INCLUDE_DIR)
151 set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES})
152 check_function_exists(dgettext LIBC_HAS_DGETTEXT)
153 if(LIBC_HAS_DGETTEXT)
Pierre Ossmanb232b5f2011-04-28 14:38:04 +0000154 set(GETTEXT_FOUND TRUE)
DRC2690f7a2011-06-24 04:17:02 +0000155 else()
156 find_library(LIBINTL_LIBRARY NAMES intl libintl)
157 check_library_exists(${LIBINTL_LIBRARY} "dgettext" "" LIBINTL_HAS_DGETTEXT)
158 if(LIBINTL_HAS_DGETTEXT)
159 set(GETTEXT_LIBRARIES ${LIBINTL_LIBRARY} ${ICONV_LIBRARIES})
160 set(GETTEXT_FOUND TRUE)
161 endif()
Pierre Ossmanb232b5f2011-04-28 14:38:04 +0000162 endif()
DRC2690f7a2011-06-24 04:17:02 +0000163 set(CMAKE_REQUIRED_LIBRARIES)
Pierre Ossmanb232b5f2011-04-28 14:38:04 +0000164 endif()
Pierre Ossmanb232b5f2011-04-28 14:38:04 +0000165 endif()
166
167 if(NOT GETTEXT_FOUND)
DRC2690f7a2011-06-24 04:17:02 +0000168 message(WARNING "Gettext NOT found. Native Language Support disabled.")
169 set(ENABLE_NLS 0)
Pierre Ossmanb232b5f2011-04-28 14:38:04 +0000170 endif()
171endif()
Peter Åstrandbb445ef2011-04-28 09:29:13 +0000172
Pierre Ossman4c6bd4c2011-03-03 09:55:21 +0000173# Check for libjpeg
174find_package(JPEG REQUIRED)
175
Pierre Ossman6fa07492011-03-04 11:35:24 +0000176# Warn if it doesn't seem to be the accelerated libjpeg that's found
DRC63b40b72011-06-07 01:47:38 +0000177set(CMAKE_REQUIRED_LIBRARIES ${JPEG_LIBRARIES})
178set(CMAKE_REQUIRED_FLAGS -I${JPEG_INCLUDE_DIR})
DRCfe06e612011-06-07 01:55:12 +0000179
DRC1953b512011-06-24 04:19:36 +0000180check_c_source_compiles("#include <stdio.h>\n#include <jpeglib.h>\nint main(int c, char** v) { return JCS_EXT_RGBX; }" FOUND_LIBJPEG_TURBO)
DRCfe06e612011-06-07 01:55:12 +0000181
182set(CMAKE_REQUIRED_LIBRARIES)
183set(CMAKE_REQUIRED_FLAGS)
184
DRC1953b512011-06-24 04:19:36 +0000185if(NOT FOUND_LIBJPEG_TURBO)
Pierre Ossman6fa07492011-03-04 11:35:24 +0000186 message(STATUS "WARNING: You are not using libjpeg-turbo. Performance will suffer.")
187endif()
188
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000189# Check for FLTK
190if(BUILD_NEW_VNCVIEWER)
191 set(FLTK_SKIP_FLUID TRUE)
192 set(FLTK_SKIP_OPENGL TRUE)
DRC71f21992011-06-23 09:30:15 +0000193 set(FLTK_SKIP_IMAGES TRUE)
194 set(FLTK_SKIP_FORMS TRUE)
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000195 find_package(FLTK COMPONENTS REQUIRED)
Pierre Ossman89f868a2011-04-11 11:59:31 +0000196
DRC1b7abb92011-06-23 19:12:08 +0000197 if(NOT APPLE)
198 # No proper handling for extra X11 libs that FLTK might need...
199 if(X11_Xft_FOUND)
200 set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xft_LIB})
201 endif()
202 if(X11_Xinerama_FOUND)
203 set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xinerama_LIB})
204 endif()
205 if(X11_Xfixes_FOUND)
206 set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xfixes_LIB})
207 endif()
208 if(X11_Xcursor_FOUND)
209 set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xcursor_LIB})
210 endif()
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000211 endif()
Pierre Ossman4a6be4a2011-05-19 14:49:18 +0000212
Pierre Ossman89f868a2011-04-11 11:59:31 +0000213 set(CMAKE_REQUIRED_INCLUDES ${FLTK_INCLUDE_DIR})
214 set(CMAKE_REQUIRED_LIBRARIES ${FLTK_LIBRARIES})
Pierre Ossman4a6be4a2011-05-19 14:49:18 +0000215
216 # FLTK STR #2599
DRCfdb348e2011-06-10 17:29:35 +0000217 check_cxx_source_compiles("#include <FL/Fl_Widget.H>\nint main(int c, char** v) { void (Fl_Widget::*foo)() = &Fl_Widget::set_simple_keyboard; return 0; }" HAVE_FLTK_DEAD_KEYS)
Pierre Ossman4a6be4a2011-05-19 14:49:18 +0000218
219 # FLTK STR #2636
220 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)
221
Pierre Ossmancb0cffe2011-05-20 14:55:10 +0000222 # FLTK STR #2638
223 check_cxx_source_compiles("#include <FL/Enumerations.H>\nint main(int c, char** v) { return FL_Volume_Down; }" HAVE_FLTK_MEDIAKEYS)
224
Pierre Ossman4c613d32011-05-26 14:14:06 +0000225 # FLTK STR #2641
226 check_cxx_source_compiles("#include <FL/Enumerations.H>\nint main(int c, char** v) { return FL_FULLSCREEN; }" HAVE_FLTK_FULLSCREEN)
227
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000228 # FLTK STR #2660
229 check_cxx_source_compiles("#include <FL/Fl_Window.H>\nint main(int c, char** v) { void (Fl_Window::*foo)(const Fl_RGB_Image*,int,int) = &Fl_Window::cursor; return 0; }" HAVE_FLTK_CURSOR)
230
Pierre Ossman89f868a2011-04-11 11:59:31 +0000231 set(CMAKE_REQUIRED_INCLUDES)
232 set(CMAKE_REQUIRED_LIBRARIES)
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000233endif()
234
Adam Tkac125bd252011-01-19 14:20:34 +0000235# Check for GNUTLS library
Pierre Ossman95064202011-05-30 12:22:39 +0000236option(ENABLE_GNUTLS "Enable protocol encryption and advanced authentication" ON)
Pierre Ossman32c88c42011-05-27 11:50:58 +0000237if(ENABLE_GNUTLS)
Pierre Ossman95064202011-05-30 12:22:39 +0000238 find_package(GnuTLS)
239 if (GNUTLS_FOUND)
240 include_directories(${GNUTLS_INCLUDE_DIR})
241 add_definitions("-DHAVE_GNUTLS")
242 add_definitions(${GNUTLS_DEFINITIONS})
243
244 # Detect old version of GnuTLS
DRC17331b92011-06-07 04:07:20 +0000245 set(CMAKE_REQUIRED_FLAGS -I${GNUTLS_INCLUDE_DIR})
Pierre Ossman95064202011-05-30 12:22:39 +0000246 set(CMAKE_EXTRA_INCLUDE_FILES gnutls/gnutls.h)
DRC17331b92011-06-07 04:07:20 +0000247 set(CMAKE_REQUIRED_LIBRARIES ${GNUTLS_LIBRARIES})
DRC56e625c2011-06-24 03:19:28 +0000248 if(WIN32)
249 set(CMAKE_EXTRA_INCLUDE_FILES gcrypt.h ${CMAKE_EXTRA_INCLUDE_FILES})
250 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ws2_32 user32)
251 endif()
DRC17331b92011-06-07 04:07:20 +0000252 if(ZLIB_FOUND)
253 # When we build against the static version of GnuTLS, we also use the
254 # included version of Zlib, but it isn't built yet, so we have to use the
255 # system's version (if available) to perform this test.
256 set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES};-lz)
257 endif()
Pierre Ossman95064202011-05-30 12:22:39 +0000258 check_function_exists(gnutls_transport_set_global_errno HAVE_OLD_GNUTLS)
259 check_function_exists(gnutls_x509_crt_print HAVE_GNUTLS_X509_CRT_PRINT)
260 check_type_size(gnutls_x509_crt_t GNUTLS_X509_CRT_T)
261 check_type_size(gnutls_datum_t GNUTLS_DATUM_T)
262 check_type_size(gnutls_pk_algorithm_t GNUTLS_PK_ALGORITHM_T)
263 check_type_size(gnutls_sign_algorithm_t GNUTLS_SIGN_ALGORITHM_T)
DRC17331b92011-06-07 04:07:20 +0000264 set(CMAKE_REQUIRED_FLAGS)
Pierre Ossman95064202011-05-30 12:22:39 +0000265 set(CMAKE_EXTRA_INCLUDE_FILES)
266 set(CMAKE_REQUIRED_LIBRARIES)
267 endif()
Adam Tkac125bd252011-01-19 14:20:34 +0000268endif()
269
DRC777290b2011-06-22 00:18:17 +0000270# Check for PAM library
271option(ENABLE_PAM "Enable PAM authentication support" ON)
272if(ENABLE_PAM)
273 check_include_files(security/pam_appl.h HAVE_PAM_H)
274 set(CMAKE_REQUIRED_LIBRARIES -lpam)
275 check_function_exists(pam_start HAVE_PAM_START)
276 set(CMAKE_REQUIRED_LIBRARIES)
277 if(HAVE_PAM_H AND HAVE_PAM_START)
278 set(PAM_LIBS pam)
279 else()
280 set(ENABLE_PAM 0)
281 endif()
282endif()
283set(HAVE_PAM ${ENABLE_PAM})
284
Pierre Ossmanee0e3622011-03-08 13:08:15 +0000285# Check for socket functions
Henrik Anderssone1fd8e12011-03-08 13:00:12 +0000286if(WIN32)
Pierre Ossman0153e232011-03-08 13:05:27 +0000287 set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h ws2tcpip.h)
Henrik Anderssone1fd8e12011-03-08 13:00:12 +0000288 set(CMAKE_REQUIRED_LIBRARIES ws2_32)
Pierre Ossman0153e232011-03-08 13:05:27 +0000289else()
290 set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
Henrik Anderssone1fd8e12011-03-08 13:00:12 +0000291endif()
DRC63758092010-11-09 19:24:12 +0000292check_function_exists(inet_aton HAVE_INET_ATON)
293check_function_exists(inet_ntop HAVE_INET_NTOP)
Henrik Anderssone1fd8e12011-03-08 13:00:12 +0000294check_type_size(socklen_t SOCKLEN_T)
DRC63758092010-11-09 19:24:12 +0000295set(CMAKE_EXTRA_INCLUDE_FILES)
296set(CMAKE_REQUIRED_LIBRARIES)
Pierre Ossmanee0e3622011-03-08 13:08:15 +0000297
298# Check for the newer standard string functions
DRC63758092010-11-09 19:24:12 +0000299check_function_exists(snprintf HAVE_SNPRINTF)
300check_function_exists(strcasecmp HAVE_STRCASECMP)
301check_function_exists(strncasecmp HAVE_STRNCASECMP)
302check_function_exists(vsnprintf HAVE_VSNPRINTF)
Pierre Ossmanee0e3622011-03-08 13:08:15 +0000303
304# Generate config.h and make sure the source finds it
DRC1980dd52011-06-24 19:28:27 +0000305configure_file(config.h.in config.h)
DRC63758092010-11-09 19:24:12 +0000306add_definitions(-DHAVE_CONFIG_H)
307include_directories(${CMAKE_BINARY_DIR})
DRC180c0162010-10-27 07:20:27 +0000308
DRC180c0162010-10-27 07:20:27 +0000309add_subdirectory(common)
Pierre Ossman8f64ef72011-03-08 16:32:49 +0000310
311if(WIN32)
312 add_subdirectory(win)
313else()
Henrik Anderssona7a38a62011-06-10 13:05:09 +0000314 # No interest in building x related parts on Apple
315 if(NOT APPLE)
316 add_subdirectory(unix)
317 endif()
Pierre Ossman8f64ef72011-03-08 16:32:49 +0000318endif()
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000319
320if(BUILD_NEW_VNCVIEWER)
DRCd0b64c92011-06-07 04:07:41 +0000321 if(ENABLE_NLS)
322 add_subdirectory(po)
323 endif()
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000324 add_subdirectory(vncviewer)
325endif()
DRC1a184072011-06-24 06:55:18 +0000326
327include(cmake/BuildPackages.cmake)
DRCb7140022011-06-25 07:33:57 +0000328
329# uninstall
330configure_file("${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
331 "cmake_uninstall.cmake" IMMEDIATE @ONLY)
332
333add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P cmake_uninstall.cmake)