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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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.1.80)
  17. # The RC version must always be four comma-separated numbers
  18. set(RCVERSION 1,1,80,0)
  19. # Manual toggle until we can deprecate the old viewers
  20. option(BUILD_NEW_VNCVIEWER "Build the new FLTK based vncviewer instead of the old ones" ON)
  21. # Compatibility variables for the migration from autotools
  22. add_definitions(-DPACKAGE_NAME="${CMAKE_PROJECT_NAME}")
  23. add_definitions(-DPACKAGE_VERSION="${VERSION}")
  24. add_definitions(-DLOCALEDIR="${CMAKE_INSTALL_PREFIX}/share/locale")
  25. # Try to encode today's date into the build id. We assume that MSVC
  26. # means we need to use a native Windows method, otherwise we assume
  27. # some kind of Unix system. The id will be empty if things fail.
  28. set(BUILD "")
  29. if(MSVC)
  30. execute_process(COMMAND "${CMAKE_SOURCE_DIR}/cmake/getdate.bat"
  31. OUTPUT_VARIABLE BUILD)
  32. else()
  33. execute_process(COMMAND "date" "+%Y%m%d" OUTPUT_VARIABLE BUILD)
  34. endif()
  35. if(NOT BUILD)
  36. set(BUILD "")
  37. else()
  38. string(REGEX REPLACE "\n" "" BUILD ${BUILD})
  39. endif()
  40. # Default to optimised builds instead of debug ones. Our code has no bugs ;)
  41. # (CMake makes it fairly easy to toggle this back to Debug if needed)
  42. if(NOT CMAKE_BUILD_TYPE)
  43. set(CMAKE_BUILD_TYPE Release)
  44. endif()
  45. message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
  46. # This only works if building from the command line. There is currently no way
  47. # to set a variable's value based on the build type when using the MSVC IDE.
  48. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  49. set(BUILD "${BUILD}d")
  50. endif()
  51. message(STATUS "VERSION = ${VERSION}, BUILD = ${BUILD}")
  52. add_definitions(-D__BUILD__="${BUILD}")
  53. if(NOT DEFINED BUILD_WINVNC)
  54. if(MSVC)
  55. set(BUILD_WINVNC 1)
  56. else()
  57. set(BUILD_WINVNC 0)
  58. endif()
  59. endif()
  60. if(MSVC)
  61. # Use the static C library for all build types
  62. foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
  63. CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
  64. CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
  65. CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
  66. if(${var} MATCHES "/MD")
  67. string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
  68. endif()
  69. endforeach()
  70. # NOTE: 4244 and 4267 are 64-bit to 32-bit conversion warnings, so normally
  71. # it is not a good idea to disable them, but we do this to duplicate the
  72. # behavior of GCC, which is less strict.
  73. add_definitions(-wd4244 -wd4267 -wd4800 -wd4996)
  74. # Avoid linker warning when doing Debug build if dependent libraries are
  75. # linked with the Release version of the static C library.
  76. set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /NODEFAULTLIB:LIBCMT")
  77. endif()
  78. # Minimum version is Windows 2000 (5.0)
  79. if(WIN32)
  80. if(NOT CMAKE_SIZEOF_VOID_P MATCHES 8)
  81. add_definitions(-D_WIN32_IE=0x0500 -D_WIN32_WINNT=0x0500)
  82. else()
  83. set(WIN64 1)
  84. # Win64 doesn't like us requesting a Windows version that didn't have
  85. # 64-bit support. Request XP (5.1) instead.
  86. add_definitions(-D_WIN32_IE=0x0501 -D_WIN32_WINNT=0x0501)
  87. endif()
  88. endif()
  89. if(CMAKE_SIZEOF_VOID_P MATCHES 8)
  90. message(STATUS "64-bit build")
  91. else()
  92. message(STATUS "32-bit build")
  93. endif()
  94. # This ensures that we don't depend on libstdc++ or libgcc
  95. if(CMAKE_COMPILER_IS_GNUCXX AND NOT APPLE AND NOT CYGWIN)
  96. option(BUILD_STATIC
  97. "Link statically against libgcc and libstdc++, if possible" OFF)
  98. if(BUILD_STATIC)
  99. # For some reason, simply passing ${CMAKE_CXX_FLAGS} to the compiler in
  100. # execute_process() doesn't work. Grrr...
  101. if(CMAKE_SIZEOF_VOID_P MATCHES 8)
  102. execute_process(COMMAND ${CMAKE_CXX_COMPILER} -m64
  103. --print-file-name=libstdc++.a OUTPUT_VARIABLE LIBSTDCPLUSPLUS
  104. RESULT_VARIABLE RESULT)
  105. else()
  106. execute_process(COMMAND ${CMAKE_CXX_COMPILER} -m32
  107. --print-file-name=libstdc++.a OUTPUT_VARIABLE LIBSTDCPLUSPLUS
  108. RESULT_VARIABLE RESULT)
  109. endif()
  110. string(REGEX REPLACE "\n" "" LIBSTDCPLUSPLUS ${LIBSTDCPLUSPLUS})
  111. if(RESULT MATCHES 0 AND LIBSTDCPLUSPLUS)
  112. message(STATUS "Linking with static libstdc++:\n ${LIBSTDCPLUSPLUS}")
  113. file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/staticlib)
  114. execute_process(COMMAND ${CMAKE_COMMAND} -E remove
  115. ${CMAKE_BINARY_DIR}/staticlib/libstdc++.a)
  116. if(MINGW)
  117. execute_process(COMMAND ${CMAKE_COMMAND} -E copy
  118. ${LIBSTDCPLUSPLUS} ${CMAKE_BINARY_DIR}/staticlib/libstdc++.a)
  119. else()
  120. execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
  121. ${LIBSTDCPLUSPLUS} ${CMAKE_BINARY_DIR}/staticlib/libstdc++.a)
  122. endif()
  123. set(CMAKE_EXE_LINKER_FLAGS
  124. "${CMAKE_EXE_LINKER_FLAGS} -L${CMAKE_BINARY_DIR}/staticlib")
  125. set(CMAKE_SHARED_LINKER_FLAGS
  126. "${CMAKE_SHARED_LINKER_FLAGS} -L${CMAKE_BINARY_DIR}/staticlib")
  127. else()
  128. message(WARNING Cannot find static libstdc++. TigerVNC will depend on dynamic libstdc++.)
  129. endif()
  130. add_definitions(-static-libgcc)
  131. set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc")
  132. set(CMAKE_SHARED_LINKER_FLAGS
  133. "${CMAKE_SHARED_LINKER_FLAGS} -static-libgcc")
  134. endif()
  135. endif()
  136. # CMake doesn't properly support resource compilation with MinGW. Boo!
  137. if(MINGW)
  138. if(NOT DEFINED RC)
  139. set(CMAKE_RC_COMPILER_INIT windres)
  140. else()
  141. set(CMAKE_RC_COMPILER_INIT ${RC})
  142. endif()
  143. enable_language(RC)
  144. message(STATUS "Resource compiler: ${CMAKE_RC_COMPILER}")
  145. set(CMAKE_RC_COMPILE_OBJECT
  146. "<CMAKE_RC_COMPILER> <FLAGS> <DEFINES> -o <OBJECT> --output-format=coff <SOURCE>")
  147. endif()
  148. # X11 stuff. It's in a if() so that we can say REQUIRED
  149. if(UNIX AND NOT APPLE)
  150. find_package(X11 REQUIRED)
  151. endif()
  152. # Check for zlib
  153. find_package(ZLIB)
  154. option(USE_INCLUDED_ZLIB "Force use of the bundled zlib")
  155. if(NOT ZLIB_FOUND)
  156. set(USE_INCLUDED_ZLIB 1)
  157. endif()
  158. if(USE_INCLUDED_ZLIB)
  159. message(STATUS "Using included zlib library")
  160. endif()
  161. # Check for gettext
  162. option(ENABLE_NLS "Enable translation of program messages" ON)
  163. if(ENABLE_NLS)
  164. # Tools
  165. find_package(Gettext)
  166. set(LOCALE_DIR "${CMAKE_INSTALL_PREFIX}/share/locale")
  167. # Gettext needs iconv
  168. find_package(Iconv)
  169. if(ICONV_FOUND)
  170. # Headers and libraries (copied from licq)
  171. set(GETTEXT_FOUND FALSE)
  172. find_path(GETTEXT_INCLUDE_DIR libintl.h)
  173. if(GETTEXT_INCLUDE_DIR)
  174. set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES})
  175. check_function_exists(dgettext LIBC_HAS_DGETTEXT)
  176. if(LIBC_HAS_DGETTEXT)
  177. set(GETTEXT_FOUND TRUE)
  178. else()
  179. find_library(LIBINTL_LIBRARY NAMES intl libintl)
  180. check_library_exists(${LIBINTL_LIBRARY} "dgettext" "" LIBINTL_HAS_DGETTEXT)
  181. if(LIBINTL_HAS_DGETTEXT)
  182. set(GETTEXT_LIBRARIES ${LIBINTL_LIBRARY} ${ICONV_LIBRARIES})
  183. set(GETTEXT_FOUND TRUE)
  184. endif()
  185. endif()
  186. set(CMAKE_REQUIRED_LIBRARIES)
  187. endif()
  188. endif()
  189. if(NOT GETTEXT_FOUND)
  190. message(WARNING "Gettext NOT found. Native Language Support disabled.")
  191. set(ENABLE_NLS 0)
  192. endif()
  193. endif()
  194. # Check for libjpeg
  195. find_package(JPEG REQUIRED)
  196. # Warn if it doesn't seem to be the accelerated libjpeg that's found
  197. set(CMAKE_REQUIRED_LIBRARIES ${JPEG_LIBRARIES})
  198. set(CMAKE_REQUIRED_FLAGS -I${JPEG_INCLUDE_DIR})
  199. if(MSVC)
  200. set(CMAKE_REQUIRED_DEFINITIONS -MT)
  201. endif()
  202. set(JPEG_TEST_SOURCE "\n
  203. #include <stdio.h>\n
  204. #include <jpeglib.h>\n
  205. int main(void) {\n
  206. struct jpeg_compress_struct cinfo;\n
  207. struct jpeg_error_mgr jerr;\n
  208. cinfo.err=jpeg_std_error(&jerr);\n
  209. jpeg_create_compress(&cinfo);\n
  210. cinfo.input_components = 3;\n
  211. jpeg_set_defaults(&cinfo);\n
  212. cinfo.in_color_space = JCS_EXT_RGB;\n
  213. jpeg_default_colorspace(&cinfo);\n
  214. return 0;\n
  215. }")
  216. if(CMAKE_CROSSCOMPILING)
  217. check_c_source_compiles("${JPEG_TEST_SOURCE}" FOUND_LIBJPEG_TURBO)
  218. else()
  219. check_c_source_runs("${JPEG_TEST_SOURCE}" FOUND_LIBJPEG_TURBO)
  220. endif()
  221. set(CMAKE_REQUIRED_LIBRARIES)
  222. set(CMAKE_REQUIRED_FLAGS)
  223. set(CMAKE_REQUIRED_DEFINITIONS)
  224. if(NOT FOUND_LIBJPEG_TURBO)
  225. message(STATUS "WARNING: You are not using libjpeg-turbo. Performance will suffer.")
  226. endif()
  227. # Check for FLTK
  228. if(BUILD_NEW_VNCVIEWER)
  229. set(FLTK_SKIP_FLUID TRUE)
  230. set(FLTK_SKIP_OPENGL TRUE)
  231. set(FLTK_SKIP_IMAGES TRUE)
  232. set(FLTK_SKIP_FORMS TRUE)
  233. find_package(FLTK)
  234. if(NOT APPLE)
  235. # No proper handling for extra X11 libs that FLTK might need...
  236. if(X11_Xft_FOUND)
  237. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xft_LIB})
  238. endif()
  239. if(X11_Xinerama_FOUND)
  240. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xinerama_LIB})
  241. endif()
  242. if(X11_Xfixes_FOUND)
  243. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xfixes_LIB})
  244. endif()
  245. if(X11_Xcursor_FOUND)
  246. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xcursor_LIB})
  247. endif()
  248. endif()
  249. if(FLTK_FOUND)
  250. set(CMAKE_REQUIRED_INCLUDES ${FLTK_INCLUDE_DIR})
  251. set(CMAKE_REQUIRED_LIBRARIES ${FLTK_LIBRARIES})
  252. # FLTK STR #2599
  253. 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)
  254. # FLTK STR #2636
  255. 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)
  256. # FLTK STR #2638
  257. check_cxx_source_compiles("#include <FL/Enumerations.H>\nint main(int c, char** v) { return FL_Volume_Down; }" HAVE_FLTK_MEDIAKEYS)
  258. # FLTK STR #2641
  259. check_cxx_source_compiles("#include <FL/Enumerations.H>\nint main(int c, char** v) { return FL_FULLSCREEN; }" HAVE_FLTK_FULLSCREEN)
  260. # FLTK STR #2660
  261. 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)
  262. set(CMAKE_REQUIRED_INCLUDES)
  263. set(CMAKE_REQUIRED_LIBRARIES)
  264. endif()
  265. option(USE_INCLUDED_FLTK
  266. "Force the use of the FLTK library bundled with the TigerVNC source")
  267. if(NOT FLTK_FOUND OR NOT HAVE_FLTK_DEAD_KEYS OR NOT HAVE_FLTK_CLIPBOARD
  268. OR NOT HAVE_FLTK_MEDIAKEYS OR NOT HAVE_FLTK_FULLSCREEN
  269. OR NOT HAVE_FLTK_CURSOR)
  270. set(USE_INCLUDED_FLTK 1)
  271. endif()
  272. if(USE_INCLUDED_FLTK)
  273. set(FLTK_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/common/fltk)
  274. set(FLTK_LIBRARIES)
  275. if(APPLE)
  276. set(FLTK_LIBRARIES "-framework Carbon -framework Cocoa -framework ApplicationServices")
  277. elseif(NOT WIN32)
  278. set(FLTK_LIBRARIES "-ldl")
  279. endif()
  280. message(STATUS "Using included FLTK library")
  281. endif()
  282. endif()
  283. # Check for GNUTLS library
  284. option(ENABLE_GNUTLS "Enable protocol encryption and advanced authentication" ON)
  285. if(ENABLE_GNUTLS)
  286. find_package(GnuTLS)
  287. if (GNUTLS_FOUND)
  288. include_directories(${GNUTLS_INCLUDE_DIR})
  289. add_definitions("-DHAVE_GNUTLS")
  290. add_definitions(${GNUTLS_DEFINITIONS})
  291. # Detect old version of GnuTLS
  292. set(CMAKE_REQUIRED_FLAGS -I${GNUTLS_INCLUDE_DIR})
  293. set(CMAKE_EXTRA_INCLUDE_FILES gnutls/gnutls.h)
  294. set(CMAKE_REQUIRED_LIBRARIES ${GNUTLS_LIBRARIES})
  295. if(WIN32)
  296. set(CMAKE_EXTRA_INCLUDE_FILES gcrypt.h ${CMAKE_EXTRA_INCLUDE_FILES})
  297. set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ws2_32 user32)
  298. endif()
  299. if(ZLIB_FOUND)
  300. # When we build against the static version of GnuTLS, we also use the
  301. # included version of Zlib, but it isn't built yet, so we have to use the
  302. # system's version (if available) to perform this test.
  303. set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES};-lz)
  304. endif()
  305. check_function_exists(gnutls_transport_set_global_errno HAVE_OLD_GNUTLS)
  306. check_function_exists(gnutls_x509_crt_print HAVE_GNUTLS_X509_CRT_PRINT)
  307. check_type_size(gnutls_x509_crt_t GNUTLS_X509_CRT_T)
  308. check_type_size(gnutls_datum_t GNUTLS_DATUM_T)
  309. check_type_size(gnutls_pk_algorithm_t GNUTLS_PK_ALGORITHM_T)
  310. check_type_size(gnutls_sign_algorithm_t GNUTLS_SIGN_ALGORITHM_T)
  311. set(CMAKE_REQUIRED_FLAGS)
  312. set(CMAKE_EXTRA_INCLUDE_FILES)
  313. set(CMAKE_REQUIRED_LIBRARIES)
  314. endif()
  315. endif()
  316. # Check for PAM library
  317. option(ENABLE_PAM "Enable PAM authentication support" ON)
  318. if(ENABLE_PAM)
  319. check_include_files(security/pam_appl.h HAVE_PAM_H)
  320. set(CMAKE_REQUIRED_LIBRARIES -lpam)
  321. check_function_exists(pam_start HAVE_PAM_START)
  322. set(CMAKE_REQUIRED_LIBRARIES)
  323. if(HAVE_PAM_H AND HAVE_PAM_START)
  324. set(PAM_LIBS pam)
  325. else()
  326. set(ENABLE_PAM 0)
  327. endif()
  328. endif()
  329. set(HAVE_PAM ${ENABLE_PAM})
  330. # Check for socket functions
  331. if(WIN32)
  332. set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h ws2tcpip.h)
  333. set(CMAKE_REQUIRED_LIBRARIES ws2_32)
  334. else()
  335. set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
  336. endif()
  337. check_function_exists(inet_aton HAVE_INET_ATON)
  338. check_function_exists(inet_ntop HAVE_INET_NTOP)
  339. check_type_size(socklen_t SOCKLEN_T)
  340. set(CMAKE_EXTRA_INCLUDE_FILES)
  341. set(CMAKE_REQUIRED_LIBRARIES)
  342. # Check for the newer standard string functions
  343. check_function_exists(snprintf HAVE_SNPRINTF)
  344. check_function_exists(strcasecmp HAVE_STRCASECMP)
  345. check_function_exists(strncasecmp HAVE_STRNCASECMP)
  346. check_function_exists(vsnprintf HAVE_VSNPRINTF)
  347. # Generate config.h and make sure the source finds it
  348. configure_file(config.h.in config.h)
  349. add_definitions(-DHAVE_CONFIG_H)
  350. include_directories(${CMAKE_BINARY_DIR})
  351. add_subdirectory(common)
  352. if(WIN32)
  353. add_subdirectory(win)
  354. else()
  355. # No interest in building x related parts on Apple
  356. if(NOT APPLE)
  357. add_subdirectory(unix)
  358. endif()
  359. endif()
  360. if(BUILD_NEW_VNCVIEWER)
  361. if(ENABLE_NLS)
  362. add_subdirectory(po)
  363. endif()
  364. add_subdirectory(vncviewer)
  365. endif()
  366. include(cmake/BuildPackages.cmake)
  367. # uninstall
  368. configure_file("${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
  369. "cmake_uninstall.cmake" IMMEDIATE @ONLY)
  370. add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P cmake_uninstall.cmake)