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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. #
  2. # Setup
  3. #
  4. cmake_minimum_required(VERSION 2.8.11)
  5. if(POLICY CMP0022)
  6. cmake_policy(SET CMP0022 OLD)
  7. endif()
  8. if(${CMAKE_VERSION} VERSION_LESS "3.4.0")
  9. message(WARNING "CMake 3.4.0 or newer is required to get correct default installation paths")
  10. endif()
  11. # Internal cmake modules
  12. set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
  13. include(CheckIncludeFiles)
  14. include(CheckFunctionExists)
  15. include(CheckLibraryExists)
  16. include(CheckTypeSize)
  17. include(CheckCSourceCompiles)
  18. include(CheckCXXSourceCompiles)
  19. include(CheckCSourceRuns)
  20. include(CMakeMacroLibtoolFile)
  21. project(tigervnc)
  22. set(VERSION 1.11.80)
  23. # The RC version must always be four comma-separated numbers
  24. set(RCVERSION 1,11,80,0)
  25. # Installation paths
  26. include(GNUInstallDirs)
  27. set(CMAKE_INSTALL_UNITDIR "lib/systemd/system" CACHE PATH "systemd unit files (lib/systemd/system)")
  28. if(IS_ABSOLUTE "${CMAKE_INSTALL_UNITDIR}")
  29. set(CMAKE_INSTALL_FULL_UNITDIR "${CMAKE_INSTALL_UNITDIR}")
  30. else()
  31. set(CMAKE_INSTALL_FULL_UNITDIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_UNITDIR}")
  32. endif()
  33. option(INSTALL_SYSTEMD_UNITS "Install TigerVNC systemd units" ON)
  34. if(MSVC)
  35. message(FATAL_ERROR "TigerVNC cannot be built with Visual Studio. Please use MinGW")
  36. endif()
  37. if(NOT BUILD_TIMESTAMP)
  38. STRING(TIMESTAMP BUILD_TIMESTAMP "%Y-%m-%d %H:%M" UTC)
  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. message(STATUS "VERSION = ${VERSION}")
  47. message(STATUS "BUILD_TIMESTAMP = ${BUILD_TIMESTAMP}")
  48. add_definitions(-DBUILD_TIMESTAMP="${BUILD_TIMESTAMP}")
  49. # We want to keep our asserts even in release builds so remove NDEBUG
  50. set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -UNDEBUG")
  51. set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -UNDEBUG")
  52. set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_C_FLAGS_RELWITHDEBINFO} -UNDEBUG")
  53. set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -UNDEBUG")
  54. set(CMAKE_C_FLAGS_MINSIZEREL "${CMAKE_C_FLAGS_MINSIZEREL} -UNDEBUG")
  55. set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -UNDEBUG")
  56. # Make sure we get a sane C version
  57. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
  58. # Tell the compiler to be stringent
  59. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wformat=2")
  60. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wformat=2")
  61. # Make sure we catch these issues whilst developing
  62. IF(CMAKE_BUILD_TYPE MATCHES Debug)
  63. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=vla")
  64. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Werror=vla")
  65. ENDIF()
  66. # clang doesn't support format_arg, which breaks this warning
  67. if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  68. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format-nonliteral -Wno-format-security")
  69. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-format-nonliteral -Wno-format-security")
  70. endif()
  71. option(ENABLE_ASAN "Enable address sanitizer support" OFF)
  72. if(ENABLE_ASAN AND NOT WIN32 AND NOT APPLE)
  73. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address")
  74. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
  75. endif()
  76. option(ENABLE_TSAN "Enable thread sanitizer support" OFF)
  77. if(ENABLE_TSAN AND NOT WIN32 AND NOT APPLE AND CMAKE_SIZEOF_VOID_P MATCHES 8)
  78. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=thread")
  79. set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
  80. endif()
  81. if(NOT DEFINED BUILD_WINVNC)
  82. set(BUILD_WINVNC 1)
  83. endif()
  84. # Minimum version is Windows 7
  85. if(WIN32)
  86. add_definitions(-D_WIN32_WINNT=0x0601)
  87. endif()
  88. if(CMAKE_SIZEOF_VOID_P MATCHES 8)
  89. message(STATUS "64-bit build")
  90. else()
  91. message(STATUS "32-bit build")
  92. endif()
  93. # Versions of CMake before 2.8.7 do not properly support resource compilation
  94. # with MinGW. Boo!
  95. if(MINGW AND "${CMAKE_VERSION}" VERSION_LESS "2.8.7")
  96. if(NOT DEFINED RC)
  97. set(CMAKE_RC_COMPILER_INIT windres)
  98. else()
  99. set(CMAKE_RC_COMPILER_INIT ${RC})
  100. endif()
  101. enable_language(RC)
  102. message(STATUS "Resource compiler: ${CMAKE_RC_COMPILER}")
  103. set(CMAKE_RC_COMPILE_OBJECT
  104. "<CMAKE_RC_COMPILER> <FLAGS> <DEFINES> -o <OBJECT> --output-format=coff <SOURCE>")
  105. endif()
  106. # MinGW64 has header support but no library support for IActiveDesktop, so we
  107. # need to check for both the header and library and use our own implementation
  108. # in common/os if either doesn't exist.
  109. if(WIN32)
  110. check_c_source_compiles("#include <windows.h>\n#include <wininet.h>\n#include <shlobj.h>\nint main(int c, char** v) {IActiveDesktop iad; (void)iad; return 0;}" HAVE_ACTIVE_DESKTOP_H)
  111. 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; (void)i; return 0;}" HAVE_ACTIVE_DESKTOP_L)
  112. endif()
  113. # X11 stuff. It's in a if() so that we can say REQUIRED
  114. if(UNIX AND NOT APPLE)
  115. find_package(X11 REQUIRED)
  116. endif()
  117. # Check for zlib
  118. find_package(ZLIB REQUIRED)
  119. # Check for pixman
  120. find_package(Pixman REQUIRED)
  121. # Check for gettext
  122. option(ENABLE_NLS "Enable translation of program messages" ON)
  123. if(ENABLE_NLS)
  124. # Tools
  125. find_package(Gettext)
  126. # Gettext needs iconv
  127. find_package(Iconv)
  128. if(ICONV_FOUND)
  129. # Headers and libraries (copied from licq)
  130. set(GETTEXT_FOUND FALSE)
  131. find_path(GETTEXT_INCLUDE_DIR libintl.h)
  132. if(GETTEXT_INCLUDE_DIR)
  133. set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES})
  134. set(CMAKE_REQUIRED_FLAGS -fno-builtin-dgettext)
  135. check_function_exists(dgettext LIBC_HAS_DGETTEXT)
  136. if(LIBC_HAS_DGETTEXT)
  137. set(GETTEXT_FOUND TRUE)
  138. else()
  139. find_library(LIBINTL_LIBRARY NAMES intl libintl)
  140. if(LIBINTL_LIBRARY)
  141. check_library_exists(${LIBINTL_LIBRARY} "dgettext" "" LIBINTL_HAS_DGETTEXT)
  142. if(LIBINTL_HAS_DGETTEXT)
  143. set(GETTEXT_LIBRARIES ${LIBINTL_LIBRARY} ${ICONV_LIBRARIES})
  144. set(GETTEXT_FOUND TRUE)
  145. endif()
  146. endif()
  147. endif()
  148. set(CMAKE_REQUIRED_LIBRARIES)
  149. set(CMAKE_REQUIRED_FLAGS)
  150. endif()
  151. endif()
  152. if(NOT GETTEXT_FOUND OR NOT ICONV_FOUND)
  153. message(WARNING "Gettext NOT found. Native Language Support disabled.")
  154. set(ENABLE_NLS 0)
  155. endif()
  156. endif()
  157. # Check for libjpeg
  158. find_package(JPEG REQUIRED)
  159. # Warn if it doesn't seem to be the accelerated libjpeg that's found
  160. set(CMAKE_REQUIRED_LIBRARIES ${JPEG_LIBRARIES})
  161. set(CMAKE_REQUIRED_FLAGS -I${JPEG_INCLUDE_DIR})
  162. set(JPEG_TEST_SOURCE "\n
  163. #include <stdio.h>\n
  164. #include <jpeglib.h>\n
  165. int main(void) {\n
  166. struct jpeg_compress_struct cinfo;\n
  167. struct jpeg_error_mgr jerr;\n
  168. cinfo.err=jpeg_std_error(&jerr);\n
  169. jpeg_create_compress(&cinfo);\n
  170. cinfo.input_components = 3;\n
  171. jpeg_set_defaults(&cinfo);\n
  172. cinfo.in_color_space = JCS_EXT_RGB;\n
  173. jpeg_default_colorspace(&cinfo);\n
  174. return 0;\n
  175. }")
  176. if(CMAKE_CROSSCOMPILING)
  177. check_c_source_compiles("${JPEG_TEST_SOURCE}" FOUND_LIBJPEG_TURBO)
  178. else()
  179. check_c_source_runs("${JPEG_TEST_SOURCE}" FOUND_LIBJPEG_TURBO)
  180. endif()
  181. set(CMAKE_REQUIRED_LIBRARIES)
  182. set(CMAKE_REQUIRED_FLAGS)
  183. set(CMAKE_REQUIRED_DEFINITIONS)
  184. if(NOT FOUND_LIBJPEG_TURBO)
  185. message(STATUS "WARNING: You are not using libjpeg-turbo. Performance will suffer.")
  186. endif()
  187. include_directories(${JPEG_INCLUDE_DIR})
  188. option(BUILD_JAVA "Build Java version of the TigerVNC Viewer" FALSE)
  189. if(BUILD_JAVA)
  190. add_subdirectory(java)
  191. endif()
  192. option(BUILD_VIEWER "Build TigerVNC viewer" ON)
  193. if(BUILD_VIEWER)
  194. # Check for FLTK
  195. set(FLTK_SKIP_FLUID TRUE)
  196. set(FLTK_SKIP_OPENGL TRUE)
  197. set(FLTK_SKIP_FORMS TRUE)
  198. find_package(FLTK REQUIRED)
  199. if(UNIX AND NOT APPLE)
  200. # No proper handling for extra X11 libs that FLTK might need...
  201. if(X11_Xft_FOUND)
  202. # Xft headers include references to fontconfig, so we need
  203. # to link to that as well
  204. find_library(FONTCONFIG_LIB fontconfig)
  205. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xft_LIB} ${FONTCONFIG_LIB})
  206. endif()
  207. if(X11_Xinerama_FOUND)
  208. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xinerama_LIB})
  209. endif()
  210. if(X11_Xfixes_FOUND)
  211. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xfixes_LIB})
  212. endif()
  213. if(X11_Xcursor_FOUND)
  214. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xcursor_LIB})
  215. endif()
  216. if(X11_Xrender_FOUND)
  217. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xrender_LIB})
  218. endif()
  219. endif()
  220. endif()
  221. # Check for GNUTLS library
  222. option(ENABLE_GNUTLS "Enable protocol encryption and advanced authentication" ON)
  223. if(ENABLE_GNUTLS)
  224. find_package(GnuTLS)
  225. if (GNUTLS_FOUND)
  226. include_directories(${GNUTLS_INCLUDE_DIR})
  227. add_definitions("-DHAVE_GNUTLS")
  228. add_definitions(${GNUTLS_DEFINITIONS})
  229. endif()
  230. endif()
  231. # Check for PAM library
  232. if(UNIX AND NOT APPLE)
  233. check_include_files(security/pam_appl.h HAVE_PAM_H)
  234. set(CMAKE_REQUIRED_LIBRARIES -lpam)
  235. check_function_exists(pam_start HAVE_PAM_START)
  236. set(CMAKE_REQUIRED_LIBRARIES)
  237. if(HAVE_PAM_H AND HAVE_PAM_START)
  238. set(PAM_LIBS pam)
  239. else()
  240. message(FATAL_ERROR "Could not find PAM development files")
  241. endif()
  242. endif()
  243. # Generate config.h and make sure the source finds it
  244. configure_file(config.h.in config.h)
  245. add_definitions(-DHAVE_CONFIG_H)
  246. include_directories(${CMAKE_BINARY_DIR})
  247. include(cmake/StaticBuild.cmake)
  248. add_subdirectory(common)
  249. if(WIN32)
  250. add_subdirectory(win)
  251. else()
  252. # No interest in building x related parts on Apple
  253. if(NOT APPLE)
  254. add_subdirectory(unix)
  255. endif()
  256. endif()
  257. if(ENABLE_NLS)
  258. add_subdirectory(po)
  259. endif()
  260. if(BUILD_VIEWER)
  261. add_subdirectory(vncviewer)
  262. add_subdirectory(media)
  263. endif()
  264. add_subdirectory(tests)
  265. if(BUILD_VIEWER)
  266. add_subdirectory(release)
  267. endif()
  268. # uninstall
  269. configure_file("${CMAKE_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
  270. "cmake_uninstall.cmake" IMMEDIATE @ONLY)
  271. add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P cmake_uninstall.cmake)