您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CMakeLists.txt 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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_TIMESTAMP "")
  33. execute_process(COMMAND "date" "+%Y-%m-%d %H:%M" OUTPUT_VARIABLE BUILD_TIMESTAMP)
  34. if(NOT BUILD_TIMESTAMP)
  35. set(BUILD_TIMESTAMP "")
  36. else()
  37. string(REGEX REPLACE "\n" "" BUILD_TIMESTAMP ${BUILD_TIMESTAMP})
  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. message(STATUS "VERSION = ${VERSION}")
  46. add_definitions(-DBUILD_TIMESTAMP="${BUILD_TIMESTAMP}")
  47. # We want to keep our asserts even in release builds so remove NDEBUG
  48. set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -UNDEBUG")
  49. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -UNDEBUG")
  50. set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -UNDEBUG")
  51. set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -UNDEBUG")
  52. set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -UNDEBUG")
  53. set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -UNDEBUG")
  54. if(NOT DEFINED BUILD_WINVNC)
  55. set(BUILD_WINVNC 1)
  56. endif()
  57. # Minimum version is Windows 2000 (5.0)
  58. if(WIN32)
  59. if(NOT CMAKE_SIZEOF_VOID_P MATCHES 8)
  60. add_definitions(-D_WIN32_IE=0x0500 -D_WIN32_WINNT=0x0500)
  61. else()
  62. set(WIN64 1)
  63. # Win64 doesn't like us requesting a Windows version that didn't have
  64. # 64-bit support. Request XP (5.1) instead.
  65. add_definitions(-D_WIN32_IE=0x0501 -D_WIN32_WINNT=0x0501)
  66. endif()
  67. endif()
  68. if(CMAKE_SIZEOF_VOID_P MATCHES 8)
  69. message(STATUS "64-bit build")
  70. else()
  71. message(STATUS "32-bit build")
  72. endif()
  73. # CMake doesn't properly support resource compilation with MinGW. Boo!
  74. if(MINGW)
  75. if(NOT DEFINED RC)
  76. set(CMAKE_RC_COMPILER_INIT windres)
  77. else()
  78. set(CMAKE_RC_COMPILER_INIT ${RC})
  79. endif()
  80. enable_language(RC)
  81. message(STATUS "Resource compiler: ${CMAKE_RC_COMPILER}")
  82. set(CMAKE_RC_COMPILE_OBJECT
  83. "<CMAKE_RC_COMPILER> <FLAGS> <DEFINES> -o <OBJECT> --output-format=coff <SOURCE>")
  84. endif()
  85. # MinGW64 has header support but no library support for IActiveDesktop, so we
  86. # need to check for both the header and library and use our own implementation
  87. # in common/os if either doesn't exist.
  88. if(WIN32)
  89. 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)
  90. 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)
  91. endif()
  92. # X11 stuff. It's in a if() so that we can say REQUIRED
  93. if(UNIX AND NOT APPLE)
  94. find_package(X11 REQUIRED)
  95. endif()
  96. # Check for zlib
  97. find_package(ZLIB)
  98. option(USE_INCLUDED_ZLIB "Force use of the bundled zlib")
  99. if(NOT ZLIB_FOUND)
  100. set(USE_INCLUDED_ZLIB 1)
  101. endif()
  102. if(USE_INCLUDED_ZLIB)
  103. message(STATUS "Using included zlib library")
  104. endif()
  105. # Check for gettext
  106. option(ENABLE_NLS "Enable translation of program messages" ON)
  107. if(ENABLE_NLS)
  108. # Tools
  109. find_package(Gettext)
  110. # Gettext needs iconv
  111. find_package(Iconv)
  112. if(ICONV_FOUND)
  113. # Headers and libraries (copied from licq)
  114. set(GETTEXT_FOUND FALSE)
  115. find_path(GETTEXT_INCLUDE_DIR libintl.h)
  116. if(GETTEXT_INCLUDE_DIR)
  117. set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES})
  118. check_function_exists(dgettext LIBC_HAS_DGETTEXT)
  119. if(LIBC_HAS_DGETTEXT)
  120. set(GETTEXT_FOUND TRUE)
  121. else()
  122. find_library(LIBINTL_LIBRARY NAMES intl libintl)
  123. check_library_exists(${LIBINTL_LIBRARY} "dgettext" "" LIBINTL_HAS_DGETTEXT)
  124. if(LIBINTL_HAS_DGETTEXT)
  125. set(GETTEXT_LIBRARIES ${LIBINTL_LIBRARY} ${ICONV_LIBRARIES})
  126. set(GETTEXT_FOUND TRUE)
  127. endif()
  128. endif()
  129. set(CMAKE_REQUIRED_LIBRARIES)
  130. endif()
  131. endif()
  132. if(NOT GETTEXT_FOUND OR NOT ICONV_FOUND)
  133. message(WARNING "Gettext NOT found. Native Language Support disabled.")
  134. set(ENABLE_NLS 0)
  135. endif()
  136. endif()
  137. # Check for libjpeg
  138. find_package(JPEG REQUIRED)
  139. # Warn if it doesn't seem to be the accelerated libjpeg that's found
  140. set(CMAKE_REQUIRED_LIBRARIES ${JPEG_LIBRARIES})
  141. set(CMAKE_REQUIRED_FLAGS -I${JPEG_INCLUDE_DIR})
  142. set(JPEG_TEST_SOURCE "\n
  143. #include <stdio.h>\n
  144. #include <jpeglib.h>\n
  145. int main(void) {\n
  146. struct jpeg_compress_struct cinfo;\n
  147. struct jpeg_error_mgr jerr;\n
  148. cinfo.err=jpeg_std_error(&jerr);\n
  149. jpeg_create_compress(&cinfo);\n
  150. cinfo.input_components = 3;\n
  151. jpeg_set_defaults(&cinfo);\n
  152. cinfo.in_color_space = JCS_EXT_RGB;\n
  153. jpeg_default_colorspace(&cinfo);\n
  154. return 0;\n
  155. }")
  156. if(CMAKE_CROSSCOMPILING)
  157. check_c_source_compiles("${JPEG_TEST_SOURCE}" FOUND_LIBJPEG_TURBO)
  158. else()
  159. check_c_source_runs("${JPEG_TEST_SOURCE}" FOUND_LIBJPEG_TURBO)
  160. endif()
  161. set(CMAKE_REQUIRED_LIBRARIES)
  162. set(CMAKE_REQUIRED_FLAGS)
  163. set(CMAKE_REQUIRED_DEFINITIONS)
  164. if(NOT FOUND_LIBJPEG_TURBO)
  165. message(STATUS "WARNING: You are not using libjpeg-turbo. Performance will suffer.")
  166. endif()
  167. option(BUILD_JAVA "Build Java version of the TigerVNC Viewer" FALSE)
  168. if(BUILD_JAVA)
  169. add_subdirectory(java)
  170. endif()
  171. # Check for FLTK
  172. set(FLTK_SKIP_FLUID TRUE)
  173. set(FLTK_SKIP_OPENGL TRUE)
  174. set(FLTK_SKIP_FORMS TRUE)
  175. find_package(FLTK)
  176. if(UNIX AND NOT APPLE)
  177. # No proper handling for extra X11 libs that FLTK might need...
  178. if(X11_Xft_FOUND)
  179. # Xft headers include references to fontconfig, so we need
  180. # to link to that as well
  181. find_library(FONTCONFIG_LIB fontconfig)
  182. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xft_LIB} ${FONTCONFIG_LIB})
  183. endif()
  184. if(X11_Xinerama_FOUND)
  185. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xinerama_LIB})
  186. endif()
  187. if(X11_Xfixes_FOUND)
  188. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xfixes_LIB})
  189. endif()
  190. if(X11_Xcursor_FOUND)
  191. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xcursor_LIB})
  192. endif()
  193. endif()
  194. if(FLTK_FOUND)
  195. set(CMAKE_REQUIRED_INCLUDES ${FLTK_INCLUDE_DIR})
  196. set(CMAKE_REQUIRED_LIBRARIES ${FLTK_LIBRARIES})
  197. # FLTK STR #2636
  198. 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)
  199. # FLTK STR #2638
  200. check_cxx_source_compiles("#include <FL/Enumerations.H>\nint main(int c, char** v) { return FL_Volume_Down; }" HAVE_FLTK_MEDIAKEYS)
  201. # FLTK STR #2641
  202. check_cxx_source_compiles("#include <FL/Enumerations.H>\nint main(int c, char** v) { return FL_FULLSCREEN; }" HAVE_FLTK_FULLSCREEN)
  203. # FLTK STR #2660
  204. 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)
  205. # FLTK STR #2697
  206. 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)
  207. # FLTK STR #2816
  208. 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)
  209. # FLTK STR #2860
  210. 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)
  211. # FLTK STR #xxxx
  212. check_cxx_source_compiles("#include <FL/Fl.H>\nint main(int c, char** v) { Fl::add_system_handler(NULL, NULL); return 0; }" HAVE_FLTK_XHANDLERS)
  213. # FLTK STR #xxxx
  214. check_cxx_source_compiles("#include <FL/Fl.H>\nint main(int c, char** v) { Fl::disable_im(); return 0; }" HAVE_FLTK_IM)
  215. set(CMAKE_REQUIRED_INCLUDES)
  216. set(CMAKE_REQUIRED_LIBRARIES)
  217. endif()
  218. # Check for GNUTLS library
  219. option(ENABLE_GNUTLS "Enable protocol encryption and advanced authentication" ON)
  220. if(ENABLE_GNUTLS)
  221. find_package(GnuTLS)
  222. if (GNUTLS_FOUND)
  223. include_directories(${GNUTLS_INCLUDE_DIR})
  224. add_definitions("-DHAVE_GNUTLS")
  225. add_definitions(${GNUTLS_DEFINITIONS})
  226. # Detect old version of GnuTLS
  227. set(CMAKE_REQUIRED_FLAGS -I${GNUTLS_INCLUDE_DIR})
  228. set(CMAKE_EXTRA_INCLUDE_FILES gnutls/gnutls.h)
  229. set(CMAKE_REQUIRED_LIBRARIES ${GNUTLS_LIBRARIES})
  230. if(WIN32)
  231. set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ws2_32 user32)
  232. endif()
  233. if(ZLIB_FOUND)
  234. # When we build against the static version of GnuTLS, we also use the
  235. # included version of Zlib, but it isn't built yet, so we have to use the
  236. # system's version (if available) to perform this test.
  237. set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES};-lz)
  238. endif()
  239. check_function_exists(gnutls_transport_set_errno HAVE_GNUTLS_SET_ERRNO)
  240. check_function_exists(gnutls_transport_set_global_errno HAVE_GNUTLS_SET_GLOBAL_ERRNO)
  241. check_function_exists(gnutls_x509_crt_print HAVE_GNUTLS_X509_CRT_PRINT)
  242. check_type_size(gnutls_x509_crt_t GNUTLS_X509_CRT_T)
  243. check_type_size(gnutls_datum_t GNUTLS_DATUM_T)
  244. check_type_size(gnutls_pk_algorithm_t GNUTLS_PK_ALGORITHM_T)
  245. check_type_size(gnutls_sign_algorithm_t GNUTLS_SIGN_ALGORITHM_T)
  246. set(CMAKE_REQUIRED_FLAGS)
  247. set(CMAKE_EXTRA_INCLUDE_FILES)
  248. set(CMAKE_REQUIRED_LIBRARIES)
  249. endif()
  250. endif()
  251. # Check for PAM library
  252. option(ENABLE_PAM "Enable PAM authentication support" ON)
  253. if(ENABLE_PAM)
  254. check_include_files(security/pam_appl.h HAVE_PAM_H)
  255. set(CMAKE_REQUIRED_LIBRARIES -lpam)
  256. check_function_exists(pam_start HAVE_PAM_START)
  257. set(CMAKE_REQUIRED_LIBRARIES)
  258. if(HAVE_PAM_H AND HAVE_PAM_START)
  259. set(PAM_LIBS pam)
  260. else()
  261. set(ENABLE_PAM 0)
  262. endif()
  263. endif()
  264. set(HAVE_PAM ${ENABLE_PAM})
  265. # Check for socket functions
  266. if(WIN32)
  267. set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h ws2tcpip.h)
  268. set(CMAKE_REQUIRED_LIBRARIES ws2_32)
  269. else()
  270. set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
  271. endif()
  272. check_function_exists(inet_aton HAVE_INET_ATON)
  273. check_function_exists(getaddrinfo HAVE_GETADDRINFO)
  274. set(CMAKE_EXTRA_INCLUDE_FILES)
  275. set(CMAKE_REQUIRED_LIBRARIES)
  276. # Generate config.h and make sure the source finds it
  277. configure_file(config.h.in config.h)
  278. add_definitions(-DHAVE_CONFIG_H)
  279. include_directories(${CMAKE_BINARY_DIR})
  280. include(cmake/StaticBuild.cmake)
  281. add_subdirectory(common)
  282. if(WIN32)
  283. add_subdirectory(win)
  284. else()
  285. # No interest in building x related parts on Apple
  286. if(NOT APPLE)
  287. add_subdirectory(unix)
  288. endif()
  289. endif()
  290. if(ENABLE_NLS)
  291. add_subdirectory(po)
  292. endif()
  293. option(BUILD_VIEWER "Build TigerVNC viewer" ON)
  294. if(BUILD_VIEWER)
  295. add_subdirectory(vncviewer)
  296. add_subdirectory(media)
  297. endif()
  298. add_subdirectory(tests)
  299. include(cmake/BuildPackages.cmake)
  300. # uninstall
  301. configure_file("${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
  302. "cmake_uninstall.cmake" IMMEDIATE @ONLY)
  303. add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P cmake_uninstall.cmake)