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

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