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