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

CMakeLists.txt 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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(CMakeMacroLibtoolFile)
  14. project(tigervnc)
  15. set(VERSION 1.0.90)
  16. # The RC version must always be four comma-separated numbers
  17. set(RCVERSION 1,0,90,0)
  18. # Manual toggle until we can deprecate the old viewers
  19. option(BUILD_NEW_VNCVIEWER "Build the new FLTK based vncviewer instead of the old ones" ON)
  20. # Compatibility variables for the migration from autotools
  21. add_definitions(-DPACKAGE_NAME="${CMAKE_PROJECT_NAME}")
  22. add_definitions(-DPACKAGE_VERSION="${VERSION}")
  23. add_definitions(-DLOCALEDIR="${CMAKE_INSTALL_PREFIX}/share/locale")
  24. # Try to encode today's date into the build id. We assume that MSVC
  25. # means we need to use a native Windows method, otherwise we assume
  26. # some kind of Unix system. The id will be empty if things fail.
  27. set(BUILD "")
  28. if(MSVC)
  29. execute_process(COMMAND "${CMAKE_SOURCE_DIR}/cmake/getdate.bat"
  30. OUTPUT_VARIABLE BUILD)
  31. else()
  32. execute_process(COMMAND "date" "+%Y%m%d" OUTPUT_VARIABLE BUILD)
  33. endif()
  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. # This only works if building from the command line. There is currently no way
  46. # to set a variable's value based on the build type when using the MSVC IDE.
  47. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  48. set(BUILD "${BUILD}d")
  49. endif()
  50. message(STATUS "VERSION = ${VERSION}, BUILD = ${BUILD}")
  51. if(NOT DEFINED BUILD_WINVNC)
  52. if(MSVC)
  53. set(BUILD_WINVNC 1)
  54. else()
  55. set(BUILD_WINVNC 0)
  56. endif()
  57. endif()
  58. if(MSVC)
  59. # Use the static C library for all build types
  60. foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
  61. CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
  62. CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
  63. CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
  64. if(${var} MATCHES "/MD")
  65. string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
  66. endif()
  67. endforeach()
  68. # NOTE: 4244 and 4267 are 64-bit to 32-bit conversion warnings, so normally
  69. # it is not a good idea to disable them, but we do this to duplicate the
  70. # behavior of GCC, which is less strict.
  71. add_definitions(-wd4244 -wd4267 -wd4800 -wd4996)
  72. endif()
  73. # Minimum version is Windows 2000 (5.0)
  74. if(WIN32)
  75. if(NOT CMAKE_SIZEOF_VOID_P MATCHES 8)
  76. add_definitions(-D_WIN32_IE=0x0500 -D_WIN32_WINNT=0x0500)
  77. else()
  78. # Win64 doesn't like us requesting a Windows version that didn't have
  79. # 64-bit support. Request XP (5.1) instead.
  80. add_definitions(-D_WIN32_IE=0x0501 -D_WIN32_WINNT=0x0501)
  81. endif()
  82. endif()
  83. if(CMAKE_SIZEOF_VOID_P MATCHES 8)
  84. message(STATUS "64-bit build")
  85. else()
  86. message(STATUS "32-bit build")
  87. endif()
  88. # CMake doesn't properly support resource compilation with MinGW. Boo!
  89. if(MINGW)
  90. if(NOT DEFINED RC)
  91. set(CMAKE_RC_COMPILER_INIT windres)
  92. else()
  93. set(CMAKE_RC_COMPILER_INIT ${RC})
  94. endif()
  95. enable_language(RC)
  96. message(STATUS "Resource compiler: ${CMAKE_RC_COMPILER}")
  97. set(CMAKE_RC_COMPILE_OBJECT
  98. "<CMAKE_RC_COMPILER> <FLAGS> <DEFINES> -o <OBJECT> --output-format=coff <SOURCE>")
  99. endif()
  100. # X11 stuff. It's in a if() so that we can say REQUIRED
  101. if(UNIX AND NOT APPLE)
  102. find_package(X11 REQUIRED)
  103. endif()
  104. # Check for zlib
  105. find_package(ZLIB)
  106. option(USE_INCLUDED_ZLIB "Force use of the bundled zlib")
  107. if(NOT ZLIB_FOUND)
  108. message(STATUS "System zlib not found. Using included zlib")
  109. set(USE_INCLUDED_ZLIB 1)
  110. endif()
  111. # Check for gettext
  112. option(ENABLE_NLS "Enable translation of program messages" ON)
  113. if(ENABLE_NLS)
  114. # Tools
  115. find_package(Gettext)
  116. set(LOCALE_DIR "${CMAKE_INSTALL_PREFIX}/share/locale")
  117. # Gettext needs iconv
  118. find_package(Iconv)
  119. if(ICONV_FOUND)
  120. # Headers and libraries (copied from licq)
  121. set(GETTEXT_FOUND FALSE)
  122. find_path(GETTEXT_INCLUDE_DIR libintl.h)
  123. if(GETTEXT_INCLUDE_DIR)
  124. set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES})
  125. check_function_exists(dgettext LIBC_HAS_DGETTEXT)
  126. if(LIBC_HAS_DGETTEXT)
  127. set(GETTEXT_FOUND TRUE)
  128. else()
  129. find_library(LIBINTL_LIBRARY NAMES intl libintl)
  130. check_library_exists(${LIBINTL_LIBRARY} "dgettext" "" LIBINTL_HAS_DGETTEXT)
  131. if(LIBINTL_HAS_DGETTEXT)
  132. set(GETTEXT_LIBRARIES ${LIBINTL_LIBRARY} ${ICONV_LIBRARIES})
  133. set(GETTEXT_FOUND TRUE)
  134. endif()
  135. endif()
  136. set(CMAKE_REQUIRED_LIBRARIES)
  137. endif()
  138. endif()
  139. if(NOT GETTEXT_FOUND)
  140. message(WARNING "Gettext NOT found. Native Language Support disabled.")
  141. set(ENABLE_NLS 0)
  142. endif()
  143. endif()
  144. # Check for libjpeg
  145. find_package(JPEG REQUIRED)
  146. # Warn if it doesn't seem to be the accelerated libjpeg that's found
  147. set(CMAKE_REQUIRED_LIBRARIES ${JPEG_LIBRARIES})
  148. set(CMAKE_REQUIRED_FLAGS -I${JPEG_INCLUDE_DIR})
  149. check_c_source_compiles("#include <stdio.h>\n#include <jpeglib.h>\nint main(int c, char** v) { return JCS_EXT_RGBX; }" FOUND_LIBJPEG_TURBO)
  150. set(CMAKE_REQUIRED_LIBRARIES)
  151. set(CMAKE_REQUIRED_FLAGS)
  152. if(NOT FOUND_LIBJPEG_TURBO)
  153. message(STATUS "WARNING: You are not using libjpeg-turbo. Performance will suffer.")
  154. endif()
  155. # Check for FLTK
  156. if(BUILD_NEW_VNCVIEWER)
  157. set(FLTK_SKIP_FLUID TRUE)
  158. set(FLTK_SKIP_OPENGL TRUE)
  159. set(FLTK_SKIP_IMAGES TRUE)
  160. set(FLTK_SKIP_FORMS TRUE)
  161. find_package(FLTK COMPONENTS REQUIRED)
  162. if(NOT APPLE)
  163. # No proper handling for extra X11 libs that FLTK might need...
  164. if(X11_Xft_FOUND)
  165. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xft_LIB})
  166. endif()
  167. if(X11_Xinerama_FOUND)
  168. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xinerama_LIB})
  169. endif()
  170. if(X11_Xfixes_FOUND)
  171. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xfixes_LIB})
  172. endif()
  173. if(X11_Xcursor_FOUND)
  174. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xcursor_LIB})
  175. endif()
  176. endif()
  177. set(CMAKE_REQUIRED_INCLUDES ${FLTK_INCLUDE_DIR})
  178. set(CMAKE_REQUIRED_LIBRARIES ${FLTK_LIBRARIES})
  179. # FLTK STR #2599
  180. 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)
  181. # FLTK STR #2636
  182. 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)
  183. # FLTK STR #2638
  184. check_cxx_source_compiles("#include <FL/Enumerations.H>\nint main(int c, char** v) { return FL_Volume_Down; }" HAVE_FLTK_MEDIAKEYS)
  185. # FLTK STR #2641
  186. check_cxx_source_compiles("#include <FL/Enumerations.H>\nint main(int c, char** v) { return FL_FULLSCREEN; }" HAVE_FLTK_FULLSCREEN)
  187. # FLTK STR #2660
  188. 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)
  189. set(CMAKE_REQUIRED_INCLUDES)
  190. set(CMAKE_REQUIRED_LIBRARIES)
  191. endif()
  192. # Check for GNUTLS library
  193. option(ENABLE_GNUTLS "Enable protocol encryption and advanced authentication" ON)
  194. if(ENABLE_GNUTLS)
  195. find_package(GnuTLS)
  196. if (GNUTLS_FOUND)
  197. include_directories(${GNUTLS_INCLUDE_DIR})
  198. add_definitions("-DHAVE_GNUTLS")
  199. add_definitions(${GNUTLS_DEFINITIONS})
  200. # Detect old version of GnuTLS
  201. set(CMAKE_REQUIRED_FLAGS -I${GNUTLS_INCLUDE_DIR})
  202. set(CMAKE_EXTRA_INCLUDE_FILES gnutls/gnutls.h)
  203. set(CMAKE_REQUIRED_LIBRARIES ${GNUTLS_LIBRARIES})
  204. if(WIN32)
  205. set(CMAKE_EXTRA_INCLUDE_FILES gcrypt.h ${CMAKE_EXTRA_INCLUDE_FILES})
  206. set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ws2_32 user32)
  207. endif()
  208. if(ZLIB_FOUND)
  209. # When we build against the static version of GnuTLS, we also use the
  210. # included version of Zlib, but it isn't built yet, so we have to use the
  211. # system's version (if available) to perform this test.
  212. set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES};-lz)
  213. endif()
  214. check_function_exists(gnutls_transport_set_global_errno HAVE_OLD_GNUTLS)
  215. check_function_exists(gnutls_x509_crt_print HAVE_GNUTLS_X509_CRT_PRINT)
  216. check_type_size(gnutls_x509_crt_t GNUTLS_X509_CRT_T)
  217. check_type_size(gnutls_datum_t GNUTLS_DATUM_T)
  218. check_type_size(gnutls_pk_algorithm_t GNUTLS_PK_ALGORITHM_T)
  219. check_type_size(gnutls_sign_algorithm_t GNUTLS_SIGN_ALGORITHM_T)
  220. set(CMAKE_REQUIRED_FLAGS)
  221. set(CMAKE_EXTRA_INCLUDE_FILES)
  222. set(CMAKE_REQUIRED_LIBRARIES)
  223. endif()
  224. endif()
  225. # Check for PAM library
  226. option(ENABLE_PAM "Enable PAM authentication support" ON)
  227. if(ENABLE_PAM)
  228. check_include_files(security/pam_appl.h HAVE_PAM_H)
  229. set(CMAKE_REQUIRED_LIBRARIES -lpam)
  230. check_function_exists(pam_start HAVE_PAM_START)
  231. set(CMAKE_REQUIRED_LIBRARIES)
  232. if(HAVE_PAM_H AND HAVE_PAM_START)
  233. set(PAM_LIBS pam)
  234. else()
  235. set(ENABLE_PAM 0)
  236. endif()
  237. endif()
  238. set(HAVE_PAM ${ENABLE_PAM})
  239. # Check for socket functions
  240. if(WIN32)
  241. set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h ws2tcpip.h)
  242. set(CMAKE_REQUIRED_LIBRARIES ws2_32)
  243. else()
  244. set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
  245. endif()
  246. check_function_exists(inet_aton HAVE_INET_ATON)
  247. check_function_exists(inet_ntop HAVE_INET_NTOP)
  248. check_type_size(socklen_t SOCKLEN_T)
  249. set(CMAKE_EXTRA_INCLUDE_FILES)
  250. set(CMAKE_REQUIRED_LIBRARIES)
  251. # Check for the newer standard string functions
  252. check_function_exists(snprintf HAVE_SNPRINTF)
  253. check_function_exists(strcasecmp HAVE_STRCASECMP)
  254. check_function_exists(strncasecmp HAVE_STRNCASECMP)
  255. check_function_exists(vsnprintf HAVE_VSNPRINTF)
  256. # Generate config.h and make sure the source finds it
  257. configure_file(config.h.in config.h)
  258. add_definitions(-DHAVE_CONFIG_H)
  259. include_directories(${CMAKE_BINARY_DIR})
  260. add_subdirectory(common)
  261. if(WIN32)
  262. add_subdirectory(win)
  263. else()
  264. # No interest in building x related parts on Apple
  265. if(NOT APPLE)
  266. add_subdirectory(unix)
  267. endif()
  268. endif()
  269. if(BUILD_NEW_VNCVIEWER)
  270. if(ENABLE_NLS)
  271. add_subdirectory(po)
  272. endif()
  273. add_subdirectory(vncviewer)
  274. endif()
  275. include(cmake/BuildPackages.cmake)