blob: 7a9a7ce1bbf49a9fe85e87eab821207ec3efd9d9 [file] [log] [blame]
DRC180c0162010-10-27 07:20:27 +00001#
2# Setup
3#
4
Bernhard M. Wiedemanne27c8962018-11-18 08:14:50 +01005cmake_minimum_required(VERSION 2.8.11)
Pierre Ossman4b9c1ff2016-04-04 13:17:38 +02006if(POLICY CMP0022)
7 cmake_policy(SET CMP0022 OLD)
8endif()
DRC180c0162010-10-27 07:20:27 +00009
Pierre Ossmanb232b5f2011-04-28 14:38:04 +000010# Internal cmake modules
11set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
12
Pierre Ossman7f443262011-03-08 13:06:46 +000013include(CheckIncludeFiles)
14include(CheckFunctionExists)
Pierre Ossmanb232b5f2011-04-28 14:38:04 +000015include(CheckLibraryExists)
Pierre Ossman7f443262011-03-08 13:06:46 +000016include(CheckTypeSize)
17include(CheckCSourceCompiles)
Pierre Ossman89f868a2011-04-11 11:59:31 +000018include(CheckCXXSourceCompiles)
DRC4e326a02011-07-28 08:06:39 +000019include(CheckCSourceRuns)
Pierre Ossman7f443262011-03-08 13:06:46 +000020
Henrik Andersson23029cc2011-06-09 09:13:23 +000021include(CMakeMacroLibtoolFile)
22
Peter Åstrandbb445ef2011-04-28 09:29:13 +000023project(tigervnc)
Pierre Ossman1f8d9982018-06-13 16:27:53 +020024set(VERSION 1.9.80)
DRC180c0162010-10-27 07:20:27 +000025
26# The RC version must always be four comma-separated numbers
Pierre Ossman1f8d9982018-06-13 16:27:53 +020027set(RCVERSION 1,9,80,0)
DRC180c0162010-10-27 07:20:27 +000028
Pierre Ossman95e28f72012-03-27 10:24:53 +000029# Installation paths
30set(BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin")
31set(DATA_DIR "${CMAKE_INSTALL_PREFIX}/share")
32set(MAN_DIR "${DATA_DIR}/man")
33set(LOCALE_DIR "${DATA_DIR}/locale")
34set(DOC_DIR "${CMAKE_INSTALL_PREFIX}/share/doc/${CMAKE_PROJECT_NAME}-${VERSION}")
35
36if(WIN32)
37set(BIN_DIR "${CMAKE_INSTALL_PREFIX}")
38set(DOC_DIR "${CMAKE_INSTALL_PREFIX}")
39endif()
40
Pierre Ossmane8115162011-03-03 12:51:38 +000041if(MSVC)
DRC60d61582012-01-18 08:10:21 +000042 message(FATAL_ERROR "TigerVNC cannot be built with Visual Studio. Please use MinGW")
Pierre Ossmane8115162011-03-03 12:51:38 +000043endif()
44
Pierre Ossman5945d732014-09-22 13:13:15 +020045if(NOT BUILD_TIMESTAMP)
Bernhard M. Wiedemanne27c8962018-11-18 08:14:50 +010046 STRING(TIMESTAMP BUILD_TIMESTAMP "%Y-%m-%d %H:%M" UTC)
DRC180c0162010-10-27 07:20:27 +000047endif()
48
Pierre Ossman2c66a632011-03-03 12:52:59 +000049# Default to optimised builds instead of debug ones. Our code has no bugs ;)
50# (CMake makes it fairly easy to toggle this back to Debug if needed)
DRC180c0162010-10-27 07:20:27 +000051if(NOT CMAKE_BUILD_TYPE)
52 set(CMAKE_BUILD_TYPE Release)
53endif()
54
55message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
56
Pierre Ossman5945d732014-09-22 13:13:15 +020057message(STATUS "VERSION = ${VERSION}")
DRC872e5dd2015-10-17 18:55:08 -050058message(STATUS "BUILD_TIMESTAMP = ${BUILD_TIMESTAMP}")
Pierre Ossman5945d732014-09-22 13:13:15 +020059add_definitions(-DBUILD_TIMESTAMP="${BUILD_TIMESTAMP}")
DRC180c0162010-10-27 07:20:27 +000060
Pierre Ossman8eaa1902014-03-19 12:43:51 +000061# We want to keep our asserts even in release builds so remove NDEBUG
62set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -UNDEBUG")
63set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -UNDEBUG")
64set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -UNDEBUG")
65set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -UNDEBUG")
66set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -UNDEBUG")
67set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -UNDEBUG")
68
Pierre Ossmand5391142018-04-13 13:49:43 +020069# Make sure we get a sane C version
70set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
71
Pierre Ossman7ca879f2015-03-03 16:02:03 +010072# Tell the compiler to be stringent
73set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wformat=2")
74set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wformat=2")
Pierre Ossman123d59c2015-03-03 16:50:47 +010075# Make sure we catch these issues whilst developing
76IF(CMAKE_BUILD_TYPE MATCHES Debug)
Pierre Ossmanbeb59a42018-11-07 21:36:05 +010077 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=vla")
78 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=vla")
Pierre Ossman123d59c2015-03-03 16:50:47 +010079ENDIF()
Pierre Ossman7ca879f2015-03-03 16:02:03 +010080
Pierre Ossman86640e82015-09-29 09:40:20 +020081option(ENABLE_ASAN "Enable address sanitizer support" OFF)
82if(ENABLE_ASAN AND NOT WIN32 AND NOT APPLE)
83 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
84 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
85endif()
86
Pierre Ossmanb74728f2015-11-13 14:06:35 +010087option(ENABLE_TSAN "Enable thread sanitizer support" OFF)
88if(ENABLE_TSAN AND NOT WIN32 AND NOT APPLE AND CMAKE_SIZEOF_VOID_P MATCHES 8)
89 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread")
90 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
91endif()
92
DRC180c0162010-10-27 07:20:27 +000093if(NOT DEFINED BUILD_WINVNC)
DRC3080ec42011-10-12 20:00:55 +000094 set(BUILD_WINVNC 1)
DRC180c0162010-10-27 07:20:27 +000095endif()
96
Pierre Ossman1cc323d2015-11-12 12:17:34 +010097# Minimum version is Windows Vista/2008 (6.0)
DRC2301beb2011-06-22 05:46:53 +000098if(WIN32)
Pierre Ossman1cc323d2015-11-12 12:17:34 +010099 add_definitions(-D_WIN32_WINNT=0x0600)
Pierre Ossman9640f442011-03-08 13:12:33 +0000100endif()
101
Pierre Ossman69314c72011-03-08 12:18:13 +0000102if(CMAKE_SIZEOF_VOID_P MATCHES 8)
DRC180c0162010-10-27 07:20:27 +0000103 message(STATUS "64-bit build")
104else()
105 message(STATUS "32-bit build")
106endif()
107
Joel Teichroebec712012016-07-12 20:52:04 -0700108# Versions of CMake before 2.8.7 do not properly support resource compilation
109# with MinGW. Boo!
110if(MINGW AND "${CMAKE_VERSION}" VERSION_LESS "2.8.7")
DRC180c0162010-10-27 07:20:27 +0000111 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
DRC3080ec42011-10-12 20:00:55 +0000122# MinGW64 has header support but no library support for IActiveDesktop, so we
123# need to check for both the header and library and use our own implementation
DRCccc09692011-11-08 06:57:58 +0000124# in common/os if either doesn't exist.
DRC3080ec42011-10-12 20:00:55 +0000125if(WIN32)
Peter Åstrand (astrand)f6ebe212018-04-23 10:30:30 +0200126 check_c_source_compiles("#include <windows.h>\n#include <wininet.h>\n#include <shlobj.h>\nint main(int c, char** v) {IActiveDesktop iad; (void)iad; return 0;}" HAVE_ACTIVE_DESKTOP_H)
127 check_c_source_compiles("#include <windows.h>\n#include <wininet.h>\n#include <shlobj.h>\nint main(int c, char** v) {GUID i = CLSID_ActiveDesktop; (void)i; return 0;}" HAVE_ACTIVE_DESKTOP_L)
DRC3080ec42011-10-12 20:00:55 +0000128endif()
129
Pierre Ossman8f64ef72011-03-08 16:32:49 +0000130# X11 stuff. It's in a if() so that we can say REQUIRED
DRC1b7abb92011-06-23 19:12:08 +0000131if(UNIX AND NOT APPLE)
Pierre Ossman8f64ef72011-03-08 16:32:49 +0000132 find_package(X11 REQUIRED)
133endif()
134
Pierre Ossmana7769f22011-03-03 09:44:49 +0000135# Check for zlib
Pierre Ossmancc8c6a22015-02-03 09:54:49 +0100136find_package(ZLIB REQUIRED)
Pierre Ossmana7769f22011-03-03 09:44:49 +0000137
Peter Åstrandbb445ef2011-04-28 09:29:13 +0000138# Check for gettext
139option(ENABLE_NLS "Enable translation of program messages" ON)
Pierre Ossmanb232b5f2011-04-28 14:38:04 +0000140if(ENABLE_NLS)
141 # Tools
DRC2690f7a2011-06-24 04:17:02 +0000142 find_package(Gettext)
Pierre Ossmanb232b5f2011-04-28 14:38:04 +0000143
144 # Gettext needs iconv
DRC2690f7a2011-06-24 04:17:02 +0000145 find_package(Iconv)
Pierre Ossmanb232b5f2011-04-28 14:38:04 +0000146
DRC2690f7a2011-06-24 04:17:02 +0000147 if(ICONV_FOUND)
148 # Headers and libraries (copied from licq)
149 set(GETTEXT_FOUND FALSE)
Pierre Ossmanb232b5f2011-04-28 14:38:04 +0000150
DRC2690f7a2011-06-24 04:17:02 +0000151 find_path(GETTEXT_INCLUDE_DIR libintl.h)
152 if(GETTEXT_INCLUDE_DIR)
153 set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES})
Pierre Ossman14c563a2016-03-10 17:08:32 +0100154 set(CMAKE_REQUIRED_FLAGS -fno-builtin-dgettext)
DRC2690f7a2011-06-24 04:17:02 +0000155 check_function_exists(dgettext LIBC_HAS_DGETTEXT)
156 if(LIBC_HAS_DGETTEXT)
Pierre Ossmanb232b5f2011-04-28 14:38:04 +0000157 set(GETTEXT_FOUND TRUE)
DRC2690f7a2011-06-24 04:17:02 +0000158 else()
159 find_library(LIBINTL_LIBRARY NAMES intl libintl)
Pierre Ossman210b4b52016-03-29 13:31:21 +0200160 if(LIBINTL_LIBRARY)
161 check_library_exists(${LIBINTL_LIBRARY} "dgettext" "" LIBINTL_HAS_DGETTEXT)
162 if(LIBINTL_HAS_DGETTEXT)
163 set(GETTEXT_LIBRARIES ${LIBINTL_LIBRARY} ${ICONV_LIBRARIES})
164 set(GETTEXT_FOUND TRUE)
165 endif()
DRC2690f7a2011-06-24 04:17:02 +0000166 endif()
Pierre Ossmanb232b5f2011-04-28 14:38:04 +0000167 endif()
DRC2690f7a2011-06-24 04:17:02 +0000168 set(CMAKE_REQUIRED_LIBRARIES)
Pierre Ossman14c563a2016-03-10 17:08:32 +0100169 set(CMAKE_REQUIRED_FLAGS)
Pierre Ossmanb232b5f2011-04-28 14:38:04 +0000170 endif()
Pierre Ossmanb232b5f2011-04-28 14:38:04 +0000171 endif()
172
DRC37596dd2011-11-08 08:38:58 +0000173 if(NOT GETTEXT_FOUND OR NOT ICONV_FOUND)
DRC2690f7a2011-06-24 04:17:02 +0000174 message(WARNING "Gettext NOT found. Native Language Support disabled.")
175 set(ENABLE_NLS 0)
Pierre Ossmanb232b5f2011-04-28 14:38:04 +0000176 endif()
177endif()
Peter Åstrandbb445ef2011-04-28 09:29:13 +0000178
Pierre Ossman4c6bd4c2011-03-03 09:55:21 +0000179# Check for libjpeg
180find_package(JPEG REQUIRED)
181
Pierre Ossman6fa07492011-03-04 11:35:24 +0000182# Warn if it doesn't seem to be the accelerated libjpeg that's found
DRC63b40b72011-06-07 01:47:38 +0000183set(CMAKE_REQUIRED_LIBRARIES ${JPEG_LIBRARIES})
184set(CMAKE_REQUIRED_FLAGS -I${JPEG_INCLUDE_DIR})
DRCfe06e612011-06-07 01:55:12 +0000185
DRCcebb1ce2011-08-01 20:25:40 +0000186set(JPEG_TEST_SOURCE "\n
DRC4e326a02011-07-28 08:06:39 +0000187 #include <stdio.h>\n
188 #include <jpeglib.h>\n
189 int main(void) {\n
190 struct jpeg_compress_struct cinfo;\n
191 struct jpeg_error_mgr jerr;\n
192 cinfo.err=jpeg_std_error(&jerr);\n
193 jpeg_create_compress(&cinfo);\n
194 cinfo.input_components = 3;\n
195 jpeg_set_defaults(&cinfo);\n
196 cinfo.in_color_space = JCS_EXT_RGB;\n
197 jpeg_default_colorspace(&cinfo);\n
198 return 0;\n
DRCcebb1ce2011-08-01 20:25:40 +0000199 }")
200
201if(CMAKE_CROSSCOMPILING)
202 check_c_source_compiles("${JPEG_TEST_SOURCE}" FOUND_LIBJPEG_TURBO)
203else()
204 check_c_source_runs("${JPEG_TEST_SOURCE}" FOUND_LIBJPEG_TURBO)
205endif()
DRCfe06e612011-06-07 01:55:12 +0000206
207set(CMAKE_REQUIRED_LIBRARIES)
208set(CMAKE_REQUIRED_FLAGS)
DRC4e326a02011-07-28 08:06:39 +0000209set(CMAKE_REQUIRED_DEFINITIONS)
DRCfe06e612011-06-07 01:55:12 +0000210
DRC1953b512011-06-24 04:19:36 +0000211if(NOT FOUND_LIBJPEG_TURBO)
Pierre Ossman6fa07492011-03-04 11:35:24 +0000212 message(STATUS "WARNING: You are not using libjpeg-turbo. Performance will suffer.")
213endif()
214
DRCfd9f3192015-10-16 03:28:58 -0500215include_directories(${JPEG_INCLUDE_DIR})
216
DRC7636ad02011-10-04 04:03:34 +0000217option(BUILD_JAVA "Build Java version of the TigerVNC Viewer" FALSE)
218if(BUILD_JAVA)
DRCc19ab9e2011-10-07 05:38:00 +0000219 add_subdirectory(java)
DRC7636ad02011-10-04 04:03:34 +0000220endif()
221
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000222# Check for FLTK
DRC3591fa52011-11-03 19:01:18 +0000223set(FLTK_SKIP_FLUID TRUE)
224set(FLTK_SKIP_OPENGL TRUE)
DRC3591fa52011-11-03 19:01:18 +0000225set(FLTK_SKIP_FORMS TRUE)
226find_package(FLTK)
Pierre Ossman89f868a2011-04-11 11:59:31 +0000227
DRC16457a22012-01-17 23:33:29 +0000228if(UNIX AND NOT APPLE)
DRC3591fa52011-11-03 19:01:18 +0000229 # No proper handling for extra X11 libs that FLTK might need...
230 if(X11_Xft_FOUND)
Pierre Ossmane43d1aa2012-03-27 10:29:50 +0000231 # Xft headers include references to fontconfig, so we need
232 # to link to that as well
233 find_library(FONTCONFIG_LIB fontconfig)
234 set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xft_LIB} ${FONTCONFIG_LIB})
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000235 endif()
DRC3591fa52011-11-03 19:01:18 +0000236 if(X11_Xinerama_FOUND)
237 set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xinerama_LIB})
DRC2ff39b82011-07-28 08:38:59 +0000238 endif()
DRC3591fa52011-11-03 19:01:18 +0000239 if(X11_Xfixes_FOUND)
240 set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xfixes_LIB})
DRC2ff39b82011-07-28 08:38:59 +0000241 endif()
DRC3591fa52011-11-03 19:01:18 +0000242 if(X11_Xcursor_FOUND)
243 set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xcursor_LIB})
DRC2ff39b82011-07-28 08:38:59 +0000244 endif()
Peter Åstrand (astrand)c4bc5a82015-02-10 12:21:05 +0100245 if(X11_Xrender_FOUND)
246 set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xrender_LIB})
247 endif()
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000248endif()
249
Adam Tkac125bd252011-01-19 14:20:34 +0000250# Check for GNUTLS library
Pierre Ossman95064202011-05-30 12:22:39 +0000251option(ENABLE_GNUTLS "Enable protocol encryption and advanced authentication" ON)
Pierre Ossman32c88c42011-05-27 11:50:58 +0000252if(ENABLE_GNUTLS)
Pierre Ossman95064202011-05-30 12:22:39 +0000253 find_package(GnuTLS)
254 if (GNUTLS_FOUND)
255 include_directories(${GNUTLS_INCLUDE_DIR})
256 add_definitions("-DHAVE_GNUTLS")
257 add_definitions(${GNUTLS_DEFINITIONS})
Pierre Ossman95064202011-05-30 12:22:39 +0000258 endif()
Adam Tkac125bd252011-01-19 14:20:34 +0000259endif()
260
DRC777290b2011-06-22 00:18:17 +0000261# Check for PAM library
262option(ENABLE_PAM "Enable PAM authentication support" ON)
263if(ENABLE_PAM)
264 check_include_files(security/pam_appl.h HAVE_PAM_H)
265 set(CMAKE_REQUIRED_LIBRARIES -lpam)
266 check_function_exists(pam_start HAVE_PAM_START)
267 set(CMAKE_REQUIRED_LIBRARIES)
268 if(HAVE_PAM_H AND HAVE_PAM_START)
269 set(PAM_LIBS pam)
270 else()
271 set(ENABLE_PAM 0)
272 endif()
273endif()
274set(HAVE_PAM ${ENABLE_PAM})
275
Pierre Ossmanee0e3622011-03-08 13:08:15 +0000276# Generate config.h and make sure the source finds it
DRC1980dd52011-06-24 19:28:27 +0000277configure_file(config.h.in config.h)
DRC63758092010-11-09 19:24:12 +0000278add_definitions(-DHAVE_CONFIG_H)
279include_directories(${CMAKE_BINARY_DIR})
DRC180c0162010-10-27 07:20:27 +0000280
Pierre Ossmanf95272d2014-10-17 13:59:35 +0200281include(cmake/StaticBuild.cmake)
282
DRC180c0162010-10-27 07:20:27 +0000283add_subdirectory(common)
Pierre Ossman8f64ef72011-03-08 16:32:49 +0000284
285if(WIN32)
286 add_subdirectory(win)
287else()
Henrik Anderssona7a38a62011-06-10 13:05:09 +0000288 # No interest in building x related parts on Apple
289 if(NOT APPLE)
290 add_subdirectory(unix)
291 endif()
Pierre Ossman8f64ef72011-03-08 16:32:49 +0000292endif()
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000293
DRC3591fa52011-11-03 19:01:18 +0000294if(ENABLE_NLS)
295 add_subdirectory(po)
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000296endif()
Pierre Ossman64127702012-03-27 12:33:36 +0000297
Peter Åstrand889b4892014-02-20 08:04:17 +0000298option(BUILD_VIEWER "Build TigerVNC viewer" ON)
299if(BUILD_VIEWER)
300 add_subdirectory(vncviewer)
301 add_subdirectory(media)
302endif()
DRC1a184072011-06-24 06:55:18 +0000303
Pierre Ossman236c03c2014-07-04 14:12:49 +0200304add_subdirectory(tests)
305
Pierre Ossman64127702012-03-27 12:33:36 +0000306
DRC1a184072011-06-24 06:55:18 +0000307include(cmake/BuildPackages.cmake)
DRCb7140022011-06-25 07:33:57 +0000308
309# uninstall
310configure_file("${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
311 "cmake_uninstall.cmake" IMMEDIATE @ONLY)
312
313add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P cmake_uninstall.cmake)