You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CMakeLists.txt 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. #
  2. # Setup
  3. #
  4. cmake_minimum_required(VERSION 2.8)
  5. # Internal cmake modules
  6. set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
  7. include(CheckIncludeFiles)
  8. include(CheckFunctionExists)
  9. include(CheckLibraryExists)
  10. include(CheckTypeSize)
  11. include(CheckCSourceCompiles)
  12. include(CheckCXXSourceCompiles)
  13. include(CheckCSourceRuns)
  14. include(CMakeMacroLibtoolFile)
  15. project(tigervnc)
  16. set(VERSION 1.3.80)
  17. # The RC version must always be four comma-separated numbers
  18. set(RCVERSION 1,3,80,0)
  19. # Installation paths
  20. set(BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin")
  21. set(DATA_DIR "${CMAKE_INSTALL_PREFIX}/share")
  22. set(MAN_DIR "${DATA_DIR}/man")
  23. set(LOCALE_DIR "${DATA_DIR}/locale")
  24. set(DOC_DIR "${CMAKE_INSTALL_PREFIX}/share/doc/${CMAKE_PROJECT_NAME}-${VERSION}")
  25. if(WIN32)
  26. set(BIN_DIR "${CMAKE_INSTALL_PREFIX}")
  27. set(DOC_DIR "${CMAKE_INSTALL_PREFIX}")
  28. endif()
  29. if(MSVC)
  30. message(FATAL_ERROR "TigerVNC cannot be built with Visual Studio. Please use MinGW")
  31. endif()
  32. set(BUILD "")
  33. execute_process(COMMAND "date" "+%Y%m%d" OUTPUT_VARIABLE BUILD)
  34. if(NOT BUILD)
  35. set(BUILD "")
  36. else()
  37. string(REGEX REPLACE "\n" "" BUILD ${BUILD})
  38. endif()
  39. # Default to optimised builds instead of debug ones. Our code has no bugs ;)
  40. # (CMake makes it fairly easy to toggle this back to Debug if needed)
  41. if(NOT CMAKE_BUILD_TYPE)
  42. set(CMAKE_BUILD_TYPE Release)
  43. endif()
  44. message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
  45. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  46. set(BUILD "${BUILD}d")
  47. endif()
  48. message(STATUS "VERSION = ${VERSION}, BUILD = ${BUILD}")
  49. add_definitions(-D__BUILD__="${BUILD}")
  50. # We want to keep our asserts even in release builds so remove NDEBUG
  51. set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -UNDEBUG")
  52. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -UNDEBUG")
  53. set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -UNDEBUG")
  54. set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -UNDEBUG")
  55. set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -UNDEBUG")
  56. set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -UNDEBUG")
  57. if(NOT DEFINED BUILD_WINVNC)
  58. set(BUILD_WINVNC 1)
  59. endif()
  60. # Minimum version is Windows 2000 (5.0)
  61. if(WIN32)
  62. if(NOT CMAKE_SIZEOF_VOID_P MATCHES 8)
  63. add_definitions(-D_WIN32_IE=0x0500 -D_WIN32_WINNT=0x0500)
  64. else()
  65. set(WIN64 1)
  66. # Win64 doesn't like us requesting a Windows version that didn't have
  67. # 64-bit support. Request XP (5.1) instead.
  68. add_definitions(-D_WIN32_IE=0x0501 -D_WIN32_WINNT=0x0501)
  69. endif()
  70. endif()
  71. if(CMAKE_SIZEOF_VOID_P MATCHES 8)
  72. message(STATUS "64-bit build")
  73. else()
  74. message(STATUS "32-bit build")
  75. endif()
  76. # This ensures that we don't depend on libstdc++ or libgcc
  77. if(CMAKE_COMPILER_IS_GNUCXX AND NOT APPLE AND NOT CYGWIN)
  78. option(BUILD_STATIC
  79. "Link statically against libgcc and libstdc++, if possible" OFF)
  80. if(BUILD_STATIC)
  81. # For some reason, simply passing ${CMAKE_CXX_FLAGS} to the compiler in
  82. # execute_process() doesn't work. Grrr...
  83. if(CMAKE_SIZEOF_VOID_P MATCHES 8)
  84. execute_process(COMMAND ${CMAKE_CXX_COMPILER} -m64
  85. --print-file-name=libstdc++.a OUTPUT_VARIABLE LIBSTDCPLUSPLUS
  86. RESULT_VARIABLE RESULT)
  87. else()
  88. execute_process(COMMAND ${CMAKE_CXX_COMPILER} -m32
  89. --print-file-name=libstdc++.a OUTPUT_VARIABLE LIBSTDCPLUSPLUS
  90. RESULT_VARIABLE RESULT)
  91. endif()
  92. string(REGEX REPLACE "\n" "" LIBSTDCPLUSPLUS ${LIBSTDCPLUSPLUS})
  93. if(RESULT MATCHES 0 AND LIBSTDCPLUSPLUS)
  94. message(STATUS "Linking with static libstdc++:\n ${LIBSTDCPLUSPLUS}")
  95. file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/staticlib)
  96. execute_process(COMMAND ${CMAKE_COMMAND} -E remove
  97. ${CMAKE_BINARY_DIR}/staticlib/libstdc++.a)
  98. if(MINGW)
  99. execute_process(COMMAND ${CMAKE_COMMAND} -E copy
  100. ${LIBSTDCPLUSPLUS} ${CMAKE_BINARY_DIR}/staticlib/libstdc++.a)
  101. else()
  102. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
  103. ${LIBSTDCPLUSPLUS} ${CMAKE_BINARY_DIR}/staticlib/libstdc++.a)
  104. endif()
  105. set(CMAKE_EXE_LINKER_FLAGS
  106. "${CMAKE_EXE_LINKER_FLAGS} -L${CMAKE_BINARY_DIR}/staticlib")
  107. set(CMAKE_SHARED_LINKER_FLAGS
  108. "${CMAKE_SHARED_LINKER_FLAGS} -L${CMAKE_BINARY_DIR}/staticlib")
  109. else()
  110. message(WARNING Cannot find static libstdc++. TigerVNC will depend on dynamic libstdc++.)
  111. endif()
  112. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc")
  113. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
  114. set(CMAKE_SHARED_LINKER_FLAGS
  115. "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
  116. endif()
  117. endif()
  118. # CMake doesn't properly support resource compilation with MinGW. Boo!
  119. if(MINGW)
  120. if(NOT DEFINED RC)
  121. set(CMAKE_RC_COMPILER_INIT windres)
  122. else()
  123. set(CMAKE_RC_COMPILER_INIT ${RC})
  124. endif()
  125. enable_language(RC)
  126. message(STATUS "Resource compiler: ${CMAKE_RC_COMPILER}")
  127. set(CMAKE_RC_COMPILE_OBJECT
  128. "<CMAKE_RC_COMPILER> <FLAGS> <DEFINES> -o <OBJECT> --output-format=coff <SOURCE>")
  129. endif()
  130. # MinGW64 has header support but no library support for IActiveDesktop, so we
  131. # need to check for both the header and library and use our own implementation
  132. # in common/os if either doesn't exist.
  133. if(WIN32)
  134. check_c_source_compiles("#include <windows.h>\n#include <wininet.h>\n#include <shlobj.h>\nint main(int c, char** v) {IActiveDesktop iad; return 0;}" HAVE_ACTIVE_DESKTOP_H)
  135. 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; return 0;}" HAVE_ACTIVE_DESKTOP_L)
  136. endif()
  137. # X11 stuff. It's in a if() so that we can say REQUIRED
  138. if(UNIX AND NOT APPLE)
  139. find_package(X11 REQUIRED)
  140. endif()
  141. # Check for zlib
  142. find_package(ZLIB)
  143. option(USE_INCLUDED_ZLIB "Force use of the bundled zlib")
  144. if(NOT ZLIB_FOUND)
  145. set(USE_INCLUDED_ZLIB 1)
  146. endif()
  147. if(USE_INCLUDED_ZLIB)
  148. message(STATUS "Using included zlib library")
  149. endif()
  150. # Check for gettext
  151. option(ENABLE_NLS "Enable translation of program messages" ON)
  152. if(ENABLE_NLS)
  153. # Tools
  154. find_package(Gettext)
  155. # Gettext needs iconv
  156. find_package(Iconv)
  157. if(ICONV_FOUND)
  158. # Headers and libraries (copied from licq)
  159. set(GETTEXT_FOUND FALSE)
  160. find_path(GETTEXT_INCLUDE_DIR libintl.h)
  161. if(GETTEXT_INCLUDE_DIR)
  162. set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES})
  163. check_function_exists(dgettext LIBC_HAS_DGETTEXT)
  164. if(LIBC_HAS_DGETTEXT)
  165. set(GETTEXT_FOUND TRUE)
  166. else()
  167. find_library(LIBINTL_LIBRARY NAMES intl libintl)
  168. check_library_exists(${LIBINTL_LIBRARY} "dgettext" "" LIBINTL_HAS_DGETTEXT)
  169. if(LIBINTL_HAS_DGETTEXT)
  170. set(GETTEXT_LIBRARIES ${LIBINTL_LIBRARY} ${ICONV_LIBRARIES})
  171. set(GETTEXT_FOUND TRUE)
  172. endif()
  173. endif()
  174. set(CMAKE_REQUIRED_LIBRARIES)
  175. endif()
  176. endif()
  177. if(NOT GETTEXT_FOUND OR NOT ICONV_FOUND)
  178. message(WARNING "Gettext NOT found. Native Language Support disabled.")
  179. set(ENABLE_NLS 0)
  180. endif()
  181. endif()
  182. # Check for libjpeg
  183. find_package(JPEG REQUIRED)
  184. # Warn if it doesn't seem to be the accelerated libjpeg that's found
  185. set(CMAKE_REQUIRED_LIBRARIES ${JPEG_LIBRARIES})
  186. set(CMAKE_REQUIRED_FLAGS -I${JPEG_INCLUDE_DIR})
  187. set(JPEG_TEST_SOURCE "\n
  188. #include <stdio.h>\n
  189. #include <jpeglib.h>\n
  190. int main(void) {\n
  191. struct jpeg_compress_struct cinfo;\n
  192. struct jpeg_error_mgr jerr;\n
  193. cinfo.err=jpeg_std_error(&jerr);\n
  194. jpeg_create_compress(&cinfo);\n
  195. cinfo.input_components = 3;\n
  196. jpeg_set_defaults(&cinfo);\n
  197. cinfo.in_color_space = JCS_EXT_RGB;\n
  198. jpeg_default_colorspace(&cinfo);\n
  199. return 0;\n
  200. }")
  201. if(CMAKE_CROSSCOMPILING)
  202. check_c_source_compiles("${JPEG_TEST_SOURCE}" FOUND_LIBJPEG_TURBO)
  203. else()
  204. check_c_source_runs("${JPEG_TEST_SOURCE}" FOUND_LIBJPEG_TURBO)
  205. endif()
  206. set(CMAKE_REQUIRED_LIBRARIES)
  207. set(CMAKE_REQUIRED_FLAGS)
  208. set(CMAKE_REQUIRED_DEFINITIONS)
  209. if(NOT FOUND_LIBJPEG_TURBO)
  210. message(STATUS "WARNING: You are not using libjpeg-turbo. Performance will suffer.")
  211. endif()
  212. option(BUILD_JAVA "Build Java version of the TigerVNC Viewer" FALSE)
  213. if(BUILD_JAVA)
  214. add_subdirectory(java)
  215. endif()
  216. # Check for FLTK
  217. set(FLTK_SKIP_FLUID TRUE)
  218. set(FLTK_SKIP_OPENGL TRUE)
  219. set(FLTK_SKIP_FORMS TRUE)
  220. find_package(FLTK)
  221. if(UNIX AND NOT APPLE)
  222. # No proper handling for extra X11 libs that FLTK might need...
  223. if(X11_Xft_FOUND)
  224. # Xft headers include references to fontconfig, so we need
  225. # to link to that as well
  226. find_library(FONTCONFIG_LIB fontconfig)
  227. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xft_LIB} ${FONTCONFIG_LIB})
  228. endif()
  229. if(X11_Xinerama_FOUND)
  230. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xinerama_LIB})
  231. endif()
  232. if(X11_Xfixes_FOUND)
  233. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xfixes_LIB})
  234. endif()
  235. if(X11_Xcursor_FOUND)
  236. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xcursor_LIB})
  237. endif()
  238. endif()
  239. if(FLTK_FOUND)
  240. set(CMAKE_REQUIRED_INCLUDES ${FLTK_INCLUDE_DIR})
  241. set(CMAKE_REQUIRED_LIBRARIES ${FLTK_LIBRARIES})
  242. # FLTK STR #2636
  243. 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)
  244. # FLTK STR #2638
  245. check_cxx_source_compiles("#include <FL/Enumerations.H>\nint main(int c, char** v) { return FL_Volume_Down; }" HAVE_FLTK_MEDIAKEYS)
  246. # FLTK STR #2641
  247. check_cxx_source_compiles("#include <FL/Enumerations.H>\nint main(int c, char** v) { return FL_FULLSCREEN; }" HAVE_FLTK_FULLSCREEN)
  248. # FLTK STR #2660
  249. 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)
  250. # FLTK STR #2697
  251. check_cxx_source_compiles("#include <FL/Fl.H>\nint main(int c, char** v) { int X, Y, W, H; Fl::screen_work_area(X, Y, W, H); return 0; }" HAVE_FLTK_WORK_AREA)
  252. # FLTK STR #2816
  253. check_cxx_source_compiles("#include <FL/Fl_Window.H>\nint main(int c, char** v) { Fl_Window::default_icons(0, 0); return 0; }" HAVE_FLTK_ICONS)
  254. # FLTK STR #2860
  255. check_cxx_source_compiles("#include <FL/Fl_Window.H>\nint main(int c, char** v) { void (Fl_Window::*foo)(int,int,int,int) = &Fl_Window::fullscreen_screens; return 0; }" HAVE_FLTK_FULLSCREEN_SCREENS)
  256. set(CMAKE_REQUIRED_INCLUDES)
  257. set(CMAKE_REQUIRED_LIBRARIES)
  258. endif()
  259. # Check for GNUTLS library
  260. option(ENABLE_GNUTLS "Enable protocol encryption and advanced authentication" ON)
  261. if(ENABLE_GNUTLS)
  262. find_package(GnuTLS)
  263. find_package(Gcrypt)
  264. find_package(Gpg_Error)
  265. if (GNUTLS_FOUND)
  266. include_directories(${GNUTLS_INCLUDE_DIR})
  267. if (GCRYPT_FOUND)
  268. include_directories(${GCRYPT_INCLUDE_DIR})
  269. set(GNUTLS_LIBRARIES ${GNUTLS_LIBRARIES};${GCRYPT_LIBRARIES})
  270. set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${GCRYPT_LIBRARIES})
  271. if (GPG_ERROR_FOUND)
  272. include_directories(${GPG_ERROR_INCLUDE_DIR})
  273. set(GNUTLS_LIBRARIES ${GNUTLS_LIBRARIES};${GPG_ERROR_LIBRARIES})
  274. set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${GPG_ERROR_LIBRARIES})
  275. endif()
  276. endif()
  277. add_definitions("-DHAVE_GNUTLS")
  278. add_definitions(${GNUTLS_DEFINITIONS})
  279. # Detect old version of GnuTLS
  280. set(CMAKE_REQUIRED_FLAGS -I${GNUTLS_INCLUDE_DIR})
  281. set(CMAKE_EXTRA_INCLUDE_FILES gnutls/gnutls.h)
  282. set(CMAKE_REQUIRED_LIBRARIES ${GNUTLS_LIBRARIES})
  283. if(WIN32)
  284. set(CMAKE_EXTRA_INCLUDE_FILES gcrypt.h ${CMAKE_EXTRA_INCLUDE_FILES})
  285. set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ws2_32 user32)
  286. endif()
  287. if(ZLIB_FOUND)
  288. # When we build against the static version of GnuTLS, we also use the
  289. # included version of Zlib, but it isn't built yet, so we have to use the
  290. # system's version (if available) to perform this test.
  291. set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES};-lz)
  292. endif()
  293. check_function_exists(gnutls_transport_set_errno HAVE_GNUTLS_SET_ERRNO)
  294. check_function_exists(gnutls_transport_set_global_errno HAVE_GNUTLS_SET_GLOBAL_ERRNO)
  295. check_function_exists(gnutls_x509_crt_print HAVE_GNUTLS_X509_CRT_PRINT)
  296. check_type_size(gnutls_x509_crt_t GNUTLS_X509_CRT_T)
  297. check_type_size(gnutls_datum_t GNUTLS_DATUM_T)
  298. check_type_size(gnutls_pk_algorithm_t GNUTLS_PK_ALGORITHM_T)
  299. check_type_size(gnutls_sign_algorithm_t GNUTLS_SIGN_ALGORITHM_T)
  300. set(CMAKE_REQUIRED_FLAGS)
  301. set(CMAKE_EXTRA_INCLUDE_FILES)
  302. set(CMAKE_REQUIRED_LIBRARIES)
  303. endif()
  304. endif()
  305. # Check for PAM library
  306. option(ENABLE_PAM "Enable PAM authentication support" ON)
  307. if(ENABLE_PAM)
  308. check_include_files(security/pam_appl.h HAVE_PAM_H)
  309. set(CMAKE_REQUIRED_LIBRARIES -lpam)
  310. check_function_exists(pam_start HAVE_PAM_START)
  311. set(CMAKE_REQUIRED_LIBRARIES)
  312. if(HAVE_PAM_H AND HAVE_PAM_START)
  313. set(PAM_LIBS pam)
  314. else()
  315. set(ENABLE_PAM 0)
  316. endif()
  317. endif()
  318. set(HAVE_PAM ${ENABLE_PAM})
  319. # Check for socket functions
  320. if(WIN32)
  321. set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h ws2tcpip.h)
  322. set(CMAKE_REQUIRED_LIBRARIES ws2_32)
  323. else()
  324. set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
  325. endif()
  326. check_function_exists(inet_aton HAVE_INET_ATON)
  327. check_function_exists(getaddrinfo HAVE_GETADDRINFO)
  328. set(CMAKE_EXTRA_INCLUDE_FILES)
  329. set(CMAKE_REQUIRED_LIBRARIES)
  330. # Generate config.h and make sure the source finds it
  331. configure_file(config.h.in config.h)
  332. add_definitions(-DHAVE_CONFIG_H)
  333. include_directories(${CMAKE_BINARY_DIR})
  334. add_subdirectory(common)
  335. if(WIN32)
  336. add_subdirectory(win)
  337. else()
  338. # No interest in building x related parts on Apple
  339. if(NOT APPLE)
  340. add_subdirectory(unix)
  341. endif()
  342. endif()
  343. if(ENABLE_NLS)
  344. add_subdirectory(po)
  345. endif()
  346. option(BUILD_VIEWER "Build TigerVNC viewer" ON)
  347. if(BUILD_VIEWER)
  348. add_subdirectory(vncviewer)
  349. add_subdirectory(media)
  350. endif()
  351. add_subdirectory(tests)
  352. include(cmake/BuildPackages.cmake)
  353. # uninstall
  354. configure_file("${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
  355. "cmake_uninstall.cmake" IMMEDIATE @ONLY)
  356. add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P cmake_uninstall.cmake)