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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. #
  2. # Setup
  3. #
  4. cmake_minimum_required(VERSION 2.6)
  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. project(tigervnc)
  14. set(VERSION 1.0.90)
  15. # The RC version must always be four comma-separated numbers
  16. set(RCVERSION 1,0,90,0)
  17. # Manual toggle until we can deprecate the old viewers
  18. option(BUILD_NEW_VNCVIEWER "Build the new FLTK based vncviewer instead of the old ones")
  19. # Compatibility variables for the migration from autotools
  20. add_definitions(-DPACKAGE_NAME="${CMAKE_PROJECT_NAME}")
  21. add_definitions(-DPACKAGE_VERSION="${VERSION}")
  22. add_definitions(-DLOCALEDIR="${CMAKE_INSTALL_PREFIX}/share/locale")
  23. # Try to encode today's date into the build id. We assume that MSVC
  24. # means we need to use a native Windows method, otherwise we assume
  25. # some kind of Unix system. The id will be empty if things fail.
  26. set(BUILD "")
  27. if(MSVC)
  28. execute_process(COMMAND "${CMAKE_SOURCE_DIR}/cmake/getdate.bat"
  29. OUTPUT_VARIABLE BUILD)
  30. else()
  31. execute_process(COMMAND "date" "+%Y%m%d" OUTPUT_VARIABLE BUILD)
  32. endif()
  33. if(NOT BUILD)
  34. set(BUILD "")
  35. else()
  36. string(REGEX REPLACE "\n" "" BUILD ${BUILD})
  37. endif()
  38. # Default to optimised builds instead of debug ones. Our code has no bugs ;)
  39. # (CMake makes it fairly easy to toggle this back to Debug if needed)
  40. if(NOT CMAKE_BUILD_TYPE)
  41. set(CMAKE_BUILD_TYPE Release)
  42. endif()
  43. message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
  44. # This only works if building from the command line. There is currently no way
  45. # to set a variable's value based on the build type when using the MSVC IDE.
  46. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  47. set(BUILD "${BUILD}d")
  48. endif()
  49. message(STATUS "VERSION = ${VERSION}, BUILD = ${BUILD}")
  50. if(NOT DEFINED BUILD_WINVNC)
  51. if(MSVC)
  52. set(BUILD_WINVNC 1)
  53. else()
  54. set(BUILD_WINVNC 0)
  55. endif()
  56. endif()
  57. if(MSVC)
  58. # Use the static C library for all build types
  59. foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
  60. CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
  61. CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
  62. CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
  63. if(${var} MATCHES "/MD")
  64. string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
  65. endif()
  66. endforeach()
  67. # NOTE: 4244 and 4267 are 64-bit to 32-bit conversion warnings, so normally
  68. # it is not a good idea to disable them, but we do this to duplicate the
  69. # behavior of GCC, which is less strict.
  70. add_definitions(-wd4244 -wd4267 -wd4800 -wd4996)
  71. endif()
  72. # Minimum version is Windows 2000 (5.0)
  73. if(NOT CMAKE_SIZEOF_VOID_P MATCHES 8)
  74. add_definitions(-D_WIN32_IE=0x0500 -D_WIN32_WINNT=0x0500)
  75. else()
  76. # Win64 doesn't like us requesting a Windows version that didn't have
  77. # 64-bit support. Request XP (5.1) instead.
  78. add_definitions(-D_WIN32_IE=0x0501 -D_WIN32_WINNT=0x0501)
  79. endif()
  80. if(CMAKE_SIZEOF_VOID_P MATCHES 8)
  81. message(STATUS "64-bit build")
  82. else()
  83. message(STATUS "32-bit build")
  84. endif()
  85. # CMake doesn't properly support resource compilation with MinGW. Boo!
  86. if(MINGW)
  87. if(NOT DEFINED RC)
  88. set(CMAKE_RC_COMPILER_INIT windres)
  89. else()
  90. set(CMAKE_RC_COMPILER_INIT ${RC})
  91. endif()
  92. enable_language(RC)
  93. message(STATUS "Resource compiler: ${CMAKE_RC_COMPILER}")
  94. set(CMAKE_RC_COMPILE_OBJECT
  95. "<CMAKE_RC_COMPILER> <FLAGS> <DEFINES> -o <OBJECT> --output-format=coff <SOURCE>")
  96. endif()
  97. # X11 stuff. It's in a if() so that we can say REQUIRED
  98. if(UNIX)
  99. find_package(X11 REQUIRED)
  100. endif()
  101. # Check for zlib
  102. find_package(ZLIB)
  103. option(USE_INCLUDED_ZLIB "Force use of the bundled zlib")
  104. if(NOT ZLIB_FOUND)
  105. message(STATUS "System zlib not found. Using included zlib")
  106. set(USE_INCLUDED_ZLIB 1)
  107. endif()
  108. # Check for gettext
  109. option(ENABLE_NLS "Enable translation of program messages" ON)
  110. if(ENABLE_NLS)
  111. # Tools
  112. find_package(Gettext REQUIRED)
  113. set(LOCALE_DIR "${CMAKE_INSTALL_PREFIX}/share/locale")
  114. # Gettext needs iconv
  115. find_package(Iconv REQUIRED)
  116. # Headers and libraries (copied from licq)
  117. set(GETTEXT_FOUND FALSE)
  118. find_path(GETTEXT_INCLUDE_DIR libintl.h)
  119. if(GETTEXT_INCLUDE_DIR)
  120. set(CMAKE_REQUIRED_LIBRARIES ${ICONV_LIBRARIES})
  121. check_function_exists(dgettext LIBC_HAS_DGETTEXT)
  122. if(LIBC_HAS_DGETTEXT)
  123. set(GETTEXT_FOUND TRUE)
  124. else()
  125. find_library(LIBINTL_LIBRARY NAMES intl libintl)
  126. check_library_exists(${LIBINTL_LIBRARY} "dgettext" "" LIBINTL_HAS_DGETTEXT)
  127. if(LIBINTL_HAS_DGETTEXT)
  128. set(GETTEXT_LIBRARIES ${LIBINTL_LIBRARY})
  129. set(GETTEXT_FOUND TRUE)
  130. endif()
  131. endif()
  132. set(CMAKE_REQUIRED_LIBRARIES)
  133. endif()
  134. if(NOT GETTEXT_FOUND)
  135. message(FATAL_ERROR "Gettext NOT found")
  136. endif()
  137. endif()
  138. # Check for libjpeg
  139. find_package(JPEG REQUIRED)
  140. # Warn if it doesn't seem to be the accelerated libjpeg that's found
  141. check_c_source_compiles("#include <stdio.h>\n#include <jpeglib.h>\nint main(int c, char** v) { return JCS_EXT_RGBX; }" FOUND_JPEG_TURBO)
  142. if(NOT FOUND_JPEG_TURBO)
  143. message(STATUS "WARNING: You are not using libjpeg-turbo. Performance will suffer.")
  144. endif()
  145. # Check for FLTK
  146. if(BUILD_NEW_VNCVIEWER)
  147. set(FLTK_SKIP_FLUID TRUE)
  148. set(FLTK_SKIP_OPENGL TRUE)
  149. find_package(FLTK COMPONENTS REQUIRED)
  150. # No proper handling for extra X11 libs that FLTK might need...
  151. if(X11_Xfixes_FOUND)
  152. set(FLTK_LIBRARIES ${FLTK_LIBRARIES} ${X11_Xfixes_LIB})
  153. endif()
  154. set(CMAKE_REQUIRED_INCLUDES ${FLTK_INCLUDE_DIR})
  155. set(CMAKE_REQUIRED_LIBRARIES ${FLTK_LIBRARIES})
  156. # FLTK STR #2599
  157. check_cxx_source_compiles("#include <FL/Fl_Widget.H>\nint main(int c, char** v) { void *foo = (void*)&Fl_Widget::set_simple_keyboard; return 0; }" HAVE_FLTK_DEAD_KEYS)
  158. # FLTK STR #2636
  159. 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)
  160. set(CMAKE_REQUIRED_INCLUDES)
  161. set(CMAKE_REQUIRED_LIBRARIES)
  162. endif()
  163. # Check for GNUTLS library
  164. find_package(GnuTLS)
  165. if(GNUTLS_FOUND)
  166. include_directories(${GNUTLS_INCLUDE_DIR})
  167. add_definitions("-DHAVE_GNUTLS")
  168. add_definitions(${GNUTLS_DEFINITIONS})
  169. # Detect old version of GnuTLS
  170. set(CMAKE_EXTRA_INCLUDE_FILES gnutls/gnutls.h)
  171. set(CMAKE_REQUIRED_LIBRARIES gnutls)
  172. check_function_exists(gnutls_transport_set_global_errno HAVE_OLD_GNUTLS)
  173. check_function_exists(gnutls_x509_crt_print HAVE_GNUTLS_X509_CRT_PRINT)
  174. check_type_size(gnutls_x509_crt_t GNUTLS_X509_CRT_T)
  175. check_type_size(gnutls_datum_t GNUTLS_DATUM_T)
  176. check_type_size(gnutls_pk_algorithm_t GNUTLS_PK_ALGORITHM_T)
  177. check_type_size(gnutls_sign_algorithm_t GNUTLS_SIGN_ALGORITHM_T)
  178. set(CMAKE_EXTRA_INCLUDE_FILES)
  179. set(CMAKE_REQUIRED_LIBRARIES)
  180. endif()
  181. # Check for socket functions
  182. if(WIN32)
  183. set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h ws2tcpip.h)
  184. set(CMAKE_REQUIRED_LIBRARIES ws2_32)
  185. else()
  186. set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
  187. endif()
  188. check_function_exists(inet_aton HAVE_INET_ATON)
  189. check_function_exists(inet_ntop HAVE_INET_NTOP)
  190. check_type_size(socklen_t SOCKLEN_T)
  191. set(CMAKE_EXTRA_INCLUDE_FILES)
  192. set(CMAKE_REQUIRED_LIBRARIES)
  193. # Check for the newer standard string functions
  194. check_function_exists(snprintf HAVE_SNPRINTF)
  195. check_function_exists(strcasecmp HAVE_STRCASECMP)
  196. check_function_exists(strncasecmp HAVE_STRNCASECMP)
  197. check_function_exists(vsnprintf HAVE_VSNPRINTF)
  198. # Generate config.h and make sure the source finds it
  199. configure_file(config.h.cmake.in config.h)
  200. add_definitions(-DHAVE_CONFIG_H)
  201. include_directories(${CMAKE_BINARY_DIR})
  202. add_subdirectory(common)
  203. if(WIN32)
  204. add_subdirectory(win)
  205. else()
  206. add_subdirectory(unix)
  207. endif()
  208. if(BUILD_NEW_VNCVIEWER)
  209. add_subdirectory(po)
  210. add_subdirectory(vncviewer)
  211. endif()