blob: 112aa8d26d86fa8994f645fb5a1478945bf2831f [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
13if(MINGW OR CYGWIN)
14 execute_process(COMMAND "date" "+%Y%m%d" OUTPUT_VARIABLE BUILD)
15 string(REGEX REPLACE "\n" "" BUILD ${BUILD})
16elseif(WIN32)
17 execute_process(COMMAND "${CMAKE_SOURCE_DIR}/cmakescripts/getdate.bat"
18 OUTPUT_VARIABLE BUILD)
19 string(REGEX REPLACE "\n" "" BUILD ${BUILD})
20else()
21 message(FATAL_ERROR "Platform not supported by this build system. Use autotools instead.")
22endif()
23
24if(NOT CMAKE_BUILD_TYPE)
25 set(CMAKE_BUILD_TYPE Release)
26endif()
27
28message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
29
30# This only works if building from the command line. There is currently no way
31# to set a variable's value based on the build type when using the MSVC IDE.
32if(CMAKE_BUILD_TYPE STREQUAL "Debug")
33 set(BUILD "${BUILD}d")
34endif()
35
36message(STATUS "VERSION = ${VERSION}, BUILD = ${BUILD}")
37
38if(NOT DEFINED BUILD_WINVNC)
39 if(MSVC)
40 set(BUILD_WINVNC 1)
41 else()
42 set(BUILD_WINVNC 0)
43 endif()
44endif()
45
46if(MSVC)
47 # Use the static C library for all build types
48 foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
49 CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
50 CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
51 CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
52 if(${var} MATCHES "/MD")
53 string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
54 endif()
55 endforeach()
56
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)
61endif()
62
63# Detect whether compiler is 64-bit
64if((MSVC AND CMAKE_CL_64) OR (CMAKE_SIZEOF_VOID_P MATCHES 8))
65 set(64BIT 1)
66 set(WIN64 1)
67endif()
68
69if(64BIT)
70 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)
128
129
130#
131# Installer
132#
133
DRC180c0162010-10-27 07:20:27 +0000134if(64BIT)
DRCb9b9e4f2011-02-10 22:21:34 +0000135 set(INST_NAME ${CMAKE_PROJECT_NAME}64-${VERSION})
DRC180c0162010-10-27 07:20:27 +0000136 set(INST_DEFS -DWIN64)
DRCb9b9e4f2011-02-10 22:21:34 +0000137else()
138 set(INST_NAME ${CMAKE_PROJECT_NAME}-${VERSION})
DRC180c0162010-10-27 07:20:27 +0000139endif()
140
141if(MSVC_IDE)
142 set(INSTALLERDIR "$(OutDir)")
143 set(BUILDDIRDEF "-DBUILD_DIR=${INSTALLERDIR}\\")
144else()
145 set(INSTALLERDIR .)
146 set(BUILDDIRDEF "-DBUILD_DIR=")
147endif()
148
149set(INST_DEPS vncviewer)
150
151if(BUILD_WINVNC)
152 set(INST_DEFS ${INST_DEFS} -DBUILD_WINVNC)
153 set(INST_DEPS ${INST_DEPS} winvnc4 wm_hooks vncconfig)
154endif()
155
156configure_file(win/tigervnc.iss.in tigervnc.iss)
157
158add_custom_target(installer
159 iscc -o${INSTALLERDIR} ${INST_DEFS} ${BUILDDIRDEF} -F${INST_NAME} tigervnc.iss
160 DEPENDS ${INST_DEPS}
161 SOURCES tigervnc.iss)
162
163install(FILES ${CMAKE_SOURCE_DIR}/win/README_BINARY.txt
164 ${CMAKE_SOURCE_DIR}/LICENCE.txt DESTINATION .)