blob: 9d5bff7aca1b8f5a53408e5a78884cf01d35aa44 [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
Adam Tkac125bd252011-01-19 14:20:34 +000088# Check for GNUTLS library
89find_package(GnuTLS)
90if(GNUTLS_FOUND)
91 include_directories(${GNUTLS_INCLUDE_DIR})
92 add_definitions("-DHAVE_GNUTLS")
93 add_definitions(${GNUTLS_DEFINITIONS})
94endif()
95
DRC63758092010-11-09 19:24:12 +000096# Generate config.h
97include(CheckIncludeFiles)
98include(CheckFunctionExists)
99set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h)
100set(CMAKE_REQUIRED_LIBRARIES ws2_32)
101check_function_exists(inet_aton HAVE_INET_ATON)
102check_function_exists(inet_ntop HAVE_INET_NTOP)
103set(CMAKE_EXTRA_INCLUDE_FILES)
104set(CMAKE_REQUIRED_LIBRARIES)
105check_function_exists(snprintf HAVE_SNPRINTF)
106check_function_exists(strcasecmp HAVE_STRCASECMP)
107check_function_exists(strncasecmp HAVE_STRNCASECMP)
108check_function_exists(vsnprintf HAVE_VSNPRINTF)
109configure_file(config.h.cmake.in config.h)
110add_definitions(-DHAVE_CONFIG_H)
111include_directories(${CMAKE_BINARY_DIR})
DRC180c0162010-10-27 07:20:27 +0000112
113add_subdirectory(common)
114add_subdirectory(win)
115
116
117#
118# Installer
119#
120
121set(INST_NAME ${CMAKE_PROJECT_NAME})
122
123if(64BIT)
124 set(INST_NAME ${INST_NAME}64)
125 set(INST_DEFS -DWIN64)
126endif()
127
128if(MSVC_IDE)
129 set(INSTALLERDIR "$(OutDir)")
130 set(BUILDDIRDEF "-DBUILD_DIR=${INSTALLERDIR}\\")
131else()
132 set(INSTALLERDIR .)
133 set(BUILDDIRDEF "-DBUILD_DIR=")
134endif()
135
136set(INST_DEPS vncviewer)
137
138if(BUILD_WINVNC)
139 set(INST_DEFS ${INST_DEFS} -DBUILD_WINVNC)
140 set(INST_DEPS ${INST_DEPS} winvnc4 wm_hooks vncconfig)
141endif()
142
143configure_file(win/tigervnc.iss.in tigervnc.iss)
144
145add_custom_target(installer
146 iscc -o${INSTALLERDIR} ${INST_DEFS} ${BUILDDIRDEF} -F${INST_NAME} tigervnc.iss
147 DEPENDS ${INST_DEPS}
148 SOURCES tigervnc.iss)
149
150install(FILES ${CMAKE_SOURCE_DIR}/win/README_BINARY.txt
151 ${CMAKE_SOURCE_DIR}/LICENCE.txt DESTINATION .)