blob: f904b49a93d8d508b097b3049bd5c2aff25781b7 [file] [log] [blame]
DRC180c0162010-10-27 07:20:27 +00001#
2# Setup
3#
4
5cmake_minimum_required(VERSION 2.6)
6
7project(TigerVNC)
8set(VERSION 1.0.90)
9
10# The RC version must always be four comma-separated numbers
11set(RCVERSION 1,0,90,0)
12
Pierre Ossmane8115162011-03-03 12:51:38 +000013# 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.
16set(BUILD "")
17if(MSVC)
DRC180c0162010-10-27 07:20:27 +000018 execute_process(COMMAND "${CMAKE_SOURCE_DIR}/cmakescripts/getdate.bat"
19 OUTPUT_VARIABLE BUILD)
DRC180c0162010-10-27 07:20:27 +000020else()
Pierre Ossmane8115162011-03-03 12:51:38 +000021 execute_process(COMMAND "date" "+%Y%m%d" OUTPUT_VARIABLE BUILD)
22endif()
23
24if(NOT BUILD)
25 set(BUILD "")
26else()
27 string(REGEX REPLACE "\n" "" BUILD ${BUILD})
DRC180c0162010-10-27 07:20:27 +000028endif()
29
Pierre Ossman2c66a632011-03-03 12:52:59 +000030# Default to optimised builds instead of debug ones. Our code has no bugs ;)
31# (CMake makes it fairly easy to toggle this back to Debug if needed)
DRC180c0162010-10-27 07:20:27 +000032if(NOT CMAKE_BUILD_TYPE)
33 set(CMAKE_BUILD_TYPE Release)
34endif()
35
36message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
37
38# This only works if building from the command line. There is currently no way
39# to set a variable's value based on the build type when using the MSVC IDE.
40if(CMAKE_BUILD_TYPE STREQUAL "Debug")
41 set(BUILD "${BUILD}d")
42endif()
43
44message(STATUS "VERSION = ${VERSION}, BUILD = ${BUILD}")
45
46if(NOT DEFINED BUILD_WINVNC)
47 if(MSVC)
48 set(BUILD_WINVNC 1)
49 else()
50 set(BUILD_WINVNC 0)
51 endif()
52endif()
53
54if(MSVC)
55 # Use the static C library for all build types
56 foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
57 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
58 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
59 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
60 if(${var} MATCHES "/MD")
61 string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
62 endif()
63 endforeach()
64
65 # NOTE: 4244 and 4267 are 64-bit to 32-bit conversion warnings, so normally
66 # it is not a good idea to disable them, but we do this to duplicate the
67 # behavior of GCC, which is less strict.
68 add_definitions(-wd4244 -wd4267 -wd4800 -wd4996)
69endif()
70
Pierre Ossman69314c72011-03-08 12:18:13 +000071if(CMAKE_SIZEOF_VOID_P MATCHES 8)
DRC180c0162010-10-27 07:20:27 +000072 message(STATUS "64-bit build")
73else()
74 message(STATUS "32-bit build")
75endif()
76
77# CMake doesn't properly support resource compilation with MinGW. Boo!
78if(MINGW)
79 if(NOT DEFINED RC)
80 set(CMAKE_RC_COMPILER_INIT windres)
81 else()
82 set(CMAKE_RC_COMPILER_INIT ${RC})
83 endif()
84 enable_language(RC)
85 message(STATUS "Resource compiler: ${CMAKE_RC_COMPILER}")
86 set(CMAKE_RC_COMPILE_OBJECT
87 "<CMAKE_RC_COMPILER> <FLAGS> <DEFINES> -o <OBJECT> --output-format=coff <SOURCE>")
88endif()
89
Pierre Ossmana7769f22011-03-03 09:44:49 +000090# Check for zlib
91find_package(ZLIB)
92option(USE_INCLUDED_ZLIB "Force use of the bundled zlib")
93if(NOT ZLIB_FOUND)
94 message(STATUS "System zlib not found. Using included zlib")
95 set(USE_INCLUDED_ZLIB 1)
96endif()
97
Pierre Ossman4c6bd4c2011-03-03 09:55:21 +000098# Check for libjpeg
99find_package(JPEG REQUIRED)
100
Pierre Ossman6fa07492011-03-04 11:35:24 +0000101# Warn if it doesn't seem to be the accelerated libjpeg that's found
102include(CheckCSourceCompiles)
103check_c_source_compiles("#include <stdio.h>\n#include <jpeglib.h>\nint main(int c, char** v) { return JCS_EXT_RGBX; }" FOUND_JPEG_TURBO)
104if(NOT FOUND_JPEG_TURBO)
105 message(STATUS "WARNING: You are not using libjpeg-turbo. Performance will suffer.")
106endif()
107
Adam Tkac125bd252011-01-19 14:20:34 +0000108# Check for GNUTLS library
109find_package(GnuTLS)
110if(GNUTLS_FOUND)
111 include_directories(${GNUTLS_INCLUDE_DIR})
112 add_definitions("-DHAVE_GNUTLS")
113 add_definitions(${GNUTLS_DEFINITIONS})
114endif()
115
DRC63758092010-11-09 19:24:12 +0000116# Generate config.h
117include(CheckIncludeFiles)
118include(CheckFunctionExists)
Henrik Anderssone1fd8e12011-03-08 13:00:12 +0000119include(CheckTypeSize)
120if(WIN32)
121 set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h)
122 set(CMAKE_REQUIRED_LIBRARIES ws2_32)
123endif()
DRC63758092010-11-09 19:24:12 +0000124check_function_exists(inet_aton HAVE_INET_ATON)
125check_function_exists(inet_ntop HAVE_INET_NTOP)
Henrik Anderssone1fd8e12011-03-08 13:00:12 +0000126set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
127check_type_size(socklen_t SOCKLEN_T)
128
DRC63758092010-11-09 19:24:12 +0000129set(CMAKE_EXTRA_INCLUDE_FILES)
130set(CMAKE_REQUIRED_LIBRARIES)
131check_function_exists(snprintf HAVE_SNPRINTF)
132check_function_exists(strcasecmp HAVE_STRCASECMP)
133check_function_exists(strncasecmp HAVE_STRNCASECMP)
134check_function_exists(vsnprintf HAVE_VSNPRINTF)
135configure_file(config.h.cmake.in config.h)
136add_definitions(-DHAVE_CONFIG_H)
137include_directories(${CMAKE_BINARY_DIR})
DRC180c0162010-10-27 07:20:27 +0000138
Pierre Ossman20dea462011-03-04 14:41:14 +0000139# Minimum version is Windows 2000 (5.0)
Pierre Ossman69314c72011-03-08 12:18:13 +0000140if(NOT CMAKE_SIZEOF_VOID_P MATCHES 8)
Pierre Ossman20dea462011-03-04 14:41:14 +0000141 add_definitions(-D_WIN32_IE=0x0500 -D_WIN32_WINNT=0x0500)
142else()
143 # Win64 doesn't like us requesting a Windows version that didn't have
144 # 64-bit support. Request XP (5.1) instead.
145 add_definitions(-D_WIN32_IE=0x0501 -D_WIN32_WINNT=0x0501)
146endif()
DRCed1ef852011-02-10 10:43:05 +0000147
DRC180c0162010-10-27 07:20:27 +0000148add_subdirectory(common)
149add_subdirectory(win)