blob: 15b1d5ccd121cdfbc1f985398994dd5fe798cf3e [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
Pierre Ossmand027edd2011-03-04 14:31:32 +000054# CMake 64-bit detection leaves a bit to be desired and is sometimes
55# not properly set. Specifically we see this with mingw64. Try to
56# detect this scenario and fix things.
57if(NOT CMAKE_CL_64 AND CMAKE_SIZEOF_VOID_P MATCHES 8)
58 message(STATUS "WARNING: CMake misdetected 64-bit build. Fixing...")
59 set(CMAKE_CL_64 1)
60endif()
61
DRC180c0162010-10-27 07:20:27 +000062if(MSVC)
63 # Use the static C library for all build types
64 foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
65 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
66 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
67 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
68 if(${var} MATCHES "/MD")
69 string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
70 endif()
71 endforeach()
72
73 # NOTE: 4244 and 4267 are 64-bit to 32-bit conversion warnings, so normally
74 # it is not a good idea to disable them, but we do this to duplicate the
75 # behavior of GCC, which is less strict.
76 add_definitions(-wd4244 -wd4267 -wd4800 -wd4996)
77endif()
78
Pierre Ossman0bfc1cd2011-03-03 12:35:04 +000079if(CMAKE_CL_64)
DRC180c0162010-10-27 07:20:27 +000080 message(STATUS "64-bit build")
81else()
82 message(STATUS "32-bit build")
83endif()
84
85# CMake doesn't properly support resource compilation with MinGW. Boo!
86if(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>")
96endif()
97
Pierre Ossmana7769f22011-03-03 09:44:49 +000098# Check for zlib
99find_package(ZLIB)
100option(USE_INCLUDED_ZLIB "Force use of the bundled zlib")
101if(NOT ZLIB_FOUND)
102 message(STATUS "System zlib not found. Using included zlib")
103 set(USE_INCLUDED_ZLIB 1)
104endif()
105
Pierre Ossman4c6bd4c2011-03-03 09:55:21 +0000106# Check for libjpeg
107find_package(JPEG REQUIRED)
108
Pierre Ossman6fa07492011-03-04 11:35:24 +0000109# Warn if it doesn't seem to be the accelerated libjpeg that's found
110include(CheckCSourceCompiles)
111check_c_source_compiles("#include <stdio.h>\n#include <jpeglib.h>\nint main(int c, char** v) { return JCS_EXT_RGBX; }" FOUND_JPEG_TURBO)
112if(NOT FOUND_JPEG_TURBO)
113 message(STATUS "WARNING: You are not using libjpeg-turbo. Performance will suffer.")
114endif()
115
Adam Tkac125bd252011-01-19 14:20:34 +0000116# Check for GNUTLS library
117find_package(GnuTLS)
118if(GNUTLS_FOUND)
119 include_directories(${GNUTLS_INCLUDE_DIR})
120 add_definitions("-DHAVE_GNUTLS")
121 add_definitions(${GNUTLS_DEFINITIONS})
122endif()
123
DRC63758092010-11-09 19:24:12 +0000124# Generate config.h
125include(CheckIncludeFiles)
126include(CheckFunctionExists)
127set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h)
128set(CMAKE_REQUIRED_LIBRARIES ws2_32)
129check_function_exists(inet_aton HAVE_INET_ATON)
130check_function_exists(inet_ntop HAVE_INET_NTOP)
131set(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
DRCed1ef852011-02-10 10:43:05 +0000141add_definitions(-D_WIN32_IE=0x0500 -D_WIN32_WINNT=0x0500)
142
DRC180c0162010-10-27 07:20:27 +0000143add_subdirectory(common)
144add_subdirectory(win)