blob: bbe9a27abe6fe472066d9d18abd8b905a22ed2a9 [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
30if(NOT CMAKE_BUILD_TYPE)
31 set(CMAKE_BUILD_TYPE Release)
32endif()
33
34message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
35
36# This only works if building from the command line. There is currently no way
37# to set a variable's value based on the build type when using the MSVC IDE.
38if(CMAKE_BUILD_TYPE STREQUAL "Debug")
39 set(BUILD "${BUILD}d")
40endif()
41
42message(STATUS "VERSION = ${VERSION}, BUILD = ${BUILD}")
43
44if(NOT DEFINED BUILD_WINVNC)
45 if(MSVC)
46 set(BUILD_WINVNC 1)
47 else()
48 set(BUILD_WINVNC 0)
49 endif()
50endif()
51
52if(MSVC)
53 # Use the static C library for all build types
54 foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
55 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
56 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
57 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
58 if(${var} MATCHES "/MD")
59 string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
60 endif()
61 endforeach()
62
63 # NOTE: 4244 and 4267 are 64-bit to 32-bit conversion warnings, so normally
64 # it is not a good idea to disable them, but we do this to duplicate the
65 # behavior of GCC, which is less strict.
66 add_definitions(-wd4244 -wd4267 -wd4800 -wd4996)
67endif()
68
Pierre Ossman0bfc1cd2011-03-03 12:35:04 +000069if(CMAKE_CL_64)
DRC180c0162010-10-27 07:20:27 +000070 message(STATUS "64-bit build")
71else()
72 message(STATUS "32-bit build")
73endif()
74
75# CMake doesn't properly support resource compilation with MinGW. Boo!
76if(MINGW)
77 if(NOT DEFINED RC)
78 set(CMAKE_RC_COMPILER_INIT windres)
79 else()
80 set(CMAKE_RC_COMPILER_INIT ${RC})
81 endif()
82 enable_language(RC)
83 message(STATUS "Resource compiler: ${CMAKE_RC_COMPILER}")
84 set(CMAKE_RC_COMPILE_OBJECT
85 "<CMAKE_RC_COMPILER> <FLAGS> <DEFINES> -o <OBJECT> --output-format=coff <SOURCE>")
86endif()
87
Pierre Ossmana7769f22011-03-03 09:44:49 +000088# Check for zlib
89find_package(ZLIB)
90option(USE_INCLUDED_ZLIB "Force use of the bundled zlib")
91if(NOT ZLIB_FOUND)
92 message(STATUS "System zlib not found. Using included zlib")
93 set(USE_INCLUDED_ZLIB 1)
94endif()
95
Pierre Ossman4c6bd4c2011-03-03 09:55:21 +000096# Check for libjpeg
97find_package(JPEG REQUIRED)
98
Adam Tkac125bd252011-01-19 14:20:34 +000099# Check for GNUTLS library
100find_package(GnuTLS)
101if(GNUTLS_FOUND)
102 include_directories(${GNUTLS_INCLUDE_DIR})
103 add_definitions("-DHAVE_GNUTLS")
104 add_definitions(${GNUTLS_DEFINITIONS})
105endif()
106
DRC63758092010-11-09 19:24:12 +0000107# Generate config.h
108include(CheckIncludeFiles)
109include(CheckFunctionExists)
110set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h)
111set(CMAKE_REQUIRED_LIBRARIES ws2_32)
112check_function_exists(inet_aton HAVE_INET_ATON)
113check_function_exists(inet_ntop HAVE_INET_NTOP)
114set(CMAKE_EXTRA_INCLUDE_FILES)
115set(CMAKE_REQUIRED_LIBRARIES)
116check_function_exists(snprintf HAVE_SNPRINTF)
117check_function_exists(strcasecmp HAVE_STRCASECMP)
118check_function_exists(strncasecmp HAVE_STRNCASECMP)
119check_function_exists(vsnprintf HAVE_VSNPRINTF)
120configure_file(config.h.cmake.in config.h)
121add_definitions(-DHAVE_CONFIG_H)
122include_directories(${CMAKE_BINARY_DIR})
DRC180c0162010-10-27 07:20:27 +0000123
DRCed1ef852011-02-10 10:43:05 +0000124add_definitions(-D_WIN32_IE=0x0500 -D_WIN32_WINNT=0x0500)
125
DRC180c0162010-10-27 07:20:27 +0000126add_subdirectory(common)
127add_subdirectory(win)