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 13KB

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