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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. #
  2. # Setup
  3. #
  4. cmake_minimum_required(VERSION 2.6)
  5. include(CheckIncludeFiles)
  6. include(CheckFunctionExists)
  7. include(CheckTypeSize)
  8. include(CheckCSourceCompiles)
  9. project(TigerVNC)
  10. set(VERSION 1.0.90)
  11. # The RC version must always be four comma-separated numbers
  12. set(RCVERSION 1,0,90,0)
  13. # Try to encode today's date into the build id. We assume that MSVC
  14. # means we need to use a native Windows method, otherwise we assume
  15. # some kind of Unix system. The id will be empty if things fail.
  16. set(BUILD "")
  17. if(MSVC)
  18. execute_process(COMMAND "${CMAKE_SOURCE_DIR}/cmakescripts/getdate.bat"
  19. OUTPUT_VARIABLE BUILD)
  20. else()
  21. execute_process(COMMAND "date" "+%Y%m%d" OUTPUT_VARIABLE BUILD)
  22. endif()
  23. if(NOT BUILD)
  24. set(BUILD "")
  25. else()
  26. string(REGEX REPLACE "\n" "" BUILD ${BUILD})
  27. endif()
  28. # Default to optimised builds instead of debug ones. Our code has no bugs ;)
  29. # (CMake makes it fairly easy to toggle this back to Debug if needed)
  30. if(NOT CMAKE_BUILD_TYPE)
  31. set(CMAKE_BUILD_TYPE Release)
  32. endif()
  33. message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
  34. # This only works if building from the command line. There is currently no way
  35. # to set a variable's value based on the build type when using the MSVC IDE.
  36. if(CMAKE_BUILD_TYPE STREQUAL "Debug")
  37. set(BUILD "${BUILD}d")
  38. endif()
  39. message(STATUS "VERSION = ${VERSION}, BUILD = ${BUILD}")
  40. if(NOT DEFINED BUILD_WINVNC)
  41. if(MSVC)
  42. set(BUILD_WINVNC 1)
  43. else()
  44. set(BUILD_WINVNC 0)
  45. endif()
  46. endif()
  47. if(MSVC)
  48. # Use the static C library for all build types
  49. foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
  50. CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
  51. CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
  52. CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
  53. if(${var} MATCHES "/MD")
  54. string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
  55. endif()
  56. endforeach()
  57. # NOTE: 4244 and 4267 are 64-bit to 32-bit conversion warnings, so normally
  58. # it is not a good idea to disable them, but we do this to duplicate the
  59. # behavior of GCC, which is less strict.
  60. add_definitions(-wd4244 -wd4267 -wd4800 -wd4996)
  61. endif()
  62. if(CMAKE_SIZEOF_VOID_P MATCHES 8)
  63. message(STATUS "64-bit build")
  64. else()
  65. message(STATUS "32-bit build")
  66. endif()
  67. # CMake doesn't properly support resource compilation with MinGW. Boo!
  68. if(MINGW)
  69. if(NOT DEFINED RC)
  70. set(CMAKE_RC_COMPILER_INIT windres)
  71. else()
  72. set(CMAKE_RC_COMPILER_INIT ${RC})
  73. endif()
  74. enable_language(RC)
  75. message(STATUS "Resource compiler: ${CMAKE_RC_COMPILER}")
  76. set(CMAKE_RC_COMPILE_OBJECT
  77. "<CMAKE_RC_COMPILER> <FLAGS> <DEFINES> -o <OBJECT> --output-format=coff <SOURCE>")
  78. endif()
  79. # Check for zlib
  80. find_package(ZLIB)
  81. option(USE_INCLUDED_ZLIB "Force use of the bundled zlib")
  82. if(NOT ZLIB_FOUND)
  83. message(STATUS "System zlib not found. Using included zlib")
  84. set(USE_INCLUDED_ZLIB 1)
  85. endif()
  86. # Check for libjpeg
  87. find_package(JPEG REQUIRED)
  88. # Warn if it doesn't seem to be the accelerated libjpeg that's found
  89. check_c_source_compiles("#include <stdio.h>\n#include <jpeglib.h>\nint main(int c, char** v) { return JCS_EXT_RGBX; }" FOUND_JPEG_TURBO)
  90. if(NOT FOUND_JPEG_TURBO)
  91. message(STATUS "WARNING: You are not using libjpeg-turbo. Performance will suffer.")
  92. endif()
  93. # Check for GNUTLS library
  94. find_package(GnuTLS)
  95. if(GNUTLS_FOUND)
  96. include_directories(${GNUTLS_INCLUDE_DIR})
  97. add_definitions("-DHAVE_GNUTLS")
  98. add_definitions(${GNUTLS_DEFINITIONS})
  99. endif()
  100. # Check for socket functions
  101. if(WIN32)
  102. set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h ws2tcpip.h)
  103. set(CMAKE_REQUIRED_LIBRARIES ws2_32)
  104. else()
  105. set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
  106. endif()
  107. check_function_exists(inet_aton HAVE_INET_ATON)
  108. check_function_exists(inet_ntop HAVE_INET_NTOP)
  109. check_type_size(socklen_t SOCKLEN_T)
  110. set(CMAKE_EXTRA_INCLUDE_FILES)
  111. set(CMAKE_REQUIRED_LIBRARIES)
  112. # Check for the newer standard string functions
  113. check_function_exists(snprintf HAVE_SNPRINTF)
  114. check_function_exists(strcasecmp HAVE_STRCASECMP)
  115. check_function_exists(strncasecmp HAVE_STRNCASECMP)
  116. check_function_exists(vsnprintf HAVE_VSNPRINTF)
  117. # Generate config.h and make sure the source finds it
  118. configure_file(config.h.cmake.in config.h)
  119. add_definitions(-DHAVE_CONFIG_H)
  120. include_directories(${CMAKE_BINARY_DIR})
  121. # Minimum version is Windows 2000 (5.0)
  122. if(NOT CMAKE_SIZEOF_VOID_P MATCHES 8)
  123. add_definitions(-D_WIN32_IE=0x0500 -D_WIN32_WINNT=0x0500)
  124. else()
  125. # Win64 doesn't like us requesting a Windows version that didn't have
  126. # 64-bit support. Request XP (5.1) instead.
  127. add_definitions(-D_WIN32_IE=0x0501 -D_WIN32_WINNT=0x0501)
  128. endif()
  129. add_subdirectory(common)
  130. add_subdirectory(win)