DRC | 180c016 | 2010-10-27 07:20:27 +0000 | [diff] [blame] | 1 | # |
| 2 | # Setup |
| 3 | # |
| 4 | |
| 5 | cmake_minimum_required(VERSION 2.6) |
| 6 | |
| 7 | project(TigerVNC) |
| 8 | set(VERSION 1.0.90) |
| 9 | |
| 10 | # The RC version must always be four comma-separated numbers |
| 11 | set(RCVERSION 1,0,90,0) |
| 12 | |
| 13 | if(MINGW OR CYGWIN) |
| 14 | execute_process(COMMAND "date" "+%Y%m%d" OUTPUT_VARIABLE BUILD) |
| 15 | string(REGEX REPLACE "\n" "" BUILD ${BUILD}) |
| 16 | elseif(WIN32) |
| 17 | execute_process(COMMAND "${CMAKE_SOURCE_DIR}/cmakescripts/getdate.bat" |
| 18 | OUTPUT_VARIABLE BUILD) |
| 19 | string(REGEX REPLACE "\n" "" BUILD ${BUILD}) |
| 20 | else() |
| 21 | message(FATAL_ERROR "Platform not supported by this build system. Use autotools instead.") |
| 22 | endif() |
| 23 | |
| 24 | if(NOT CMAKE_BUILD_TYPE) |
| 25 | set(CMAKE_BUILD_TYPE Release) |
| 26 | endif() |
| 27 | |
| 28 | message(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. |
| 32 | if(CMAKE_BUILD_TYPE STREQUAL "Debug") |
| 33 | set(BUILD "${BUILD}d") |
| 34 | endif() |
| 35 | |
| 36 | message(STATUS "VERSION = ${VERSION}, BUILD = ${BUILD}") |
| 37 | |
| 38 | if(NOT DEFINED BUILD_WINVNC) |
| 39 | if(MSVC) |
| 40 | set(BUILD_WINVNC 1) |
| 41 | else() |
| 42 | set(BUILD_WINVNC 0) |
| 43 | endif() |
| 44 | endif() |
| 45 | |
| 46 | if(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) |
| 61 | endif() |
| 62 | |
| 63 | # Detect whether compiler is 64-bit |
| 64 | if((MSVC AND CMAKE_CL_64) OR (CMAKE_SIZEOF_VOID_P MATCHES 8)) |
| 65 | set(64BIT 1) |
| 66 | set(WIN64 1) |
| 67 | endif() |
| 68 | |
| 69 | if(64BIT) |
| 70 | message(STATUS "64-bit build") |
| 71 | else() |
| 72 | message(STATUS "32-bit build") |
| 73 | endif() |
| 74 | |
| 75 | # CMake doesn't properly support resource compilation with MinGW. Boo! |
| 76 | if(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>") |
| 86 | endif() |
| 87 | |
Adam Tkac | 125bd25 | 2011-01-19 14:20:34 +0000 | [diff] [blame] | 88 | # Check for GNUTLS library |
| 89 | find_package(GnuTLS) |
| 90 | if(GNUTLS_FOUND) |
| 91 | include_directories(${GNUTLS_INCLUDE_DIR}) |
| 92 | add_definitions("-DHAVE_GNUTLS") |
| 93 | add_definitions(${GNUTLS_DEFINITIONS}) |
| 94 | endif() |
| 95 | |
DRC | 6375809 | 2010-11-09 19:24:12 +0000 | [diff] [blame] | 96 | # Generate config.h |
| 97 | include(CheckIncludeFiles) |
| 98 | include(CheckFunctionExists) |
| 99 | set(CMAKE_EXTRA_INCLUDE_FILES winsock2.h) |
| 100 | set(CMAKE_REQUIRED_LIBRARIES ws2_32) |
| 101 | check_function_exists(inet_aton HAVE_INET_ATON) |
| 102 | check_function_exists(inet_ntop HAVE_INET_NTOP) |
| 103 | set(CMAKE_EXTRA_INCLUDE_FILES) |
| 104 | set(CMAKE_REQUIRED_LIBRARIES) |
| 105 | check_function_exists(snprintf HAVE_SNPRINTF) |
| 106 | check_function_exists(strcasecmp HAVE_STRCASECMP) |
| 107 | check_function_exists(strncasecmp HAVE_STRNCASECMP) |
| 108 | check_function_exists(vsnprintf HAVE_VSNPRINTF) |
| 109 | configure_file(config.h.cmake.in config.h) |
| 110 | add_definitions(-DHAVE_CONFIG_H) |
| 111 | include_directories(${CMAKE_BINARY_DIR}) |
DRC | 180c016 | 2010-10-27 07:20:27 +0000 | [diff] [blame] | 112 | |
DRC | ed1ef85 | 2011-02-10 10:43:05 +0000 | [diff] [blame] | 113 | add_definitions(-D_WIN32_IE=0x0500 -D_WIN32_WINNT=0x0500) |
| 114 | |
DRC | 180c016 | 2010-10-27 07:20:27 +0000 | [diff] [blame] | 115 | add_subdirectory(common) |
| 116 | add_subdirectory(win) |
| 117 | |
| 118 | |
| 119 | # |
| 120 | # Installer |
| 121 | # |
| 122 | |
| 123 | set(INST_NAME ${CMAKE_PROJECT_NAME}) |
| 124 | |
| 125 | if(64BIT) |
| 126 | set(INST_NAME ${INST_NAME}64) |
| 127 | set(INST_DEFS -DWIN64) |
| 128 | endif() |
| 129 | |
| 130 | if(MSVC_IDE) |
| 131 | set(INSTALLERDIR "$(OutDir)") |
| 132 | set(BUILDDIRDEF "-DBUILD_DIR=${INSTALLERDIR}\\") |
| 133 | else() |
| 134 | set(INSTALLERDIR .) |
| 135 | set(BUILDDIRDEF "-DBUILD_DIR=") |
| 136 | endif() |
| 137 | |
| 138 | set(INST_DEPS vncviewer) |
| 139 | |
| 140 | if(BUILD_WINVNC) |
| 141 | set(INST_DEFS ${INST_DEFS} -DBUILD_WINVNC) |
| 142 | set(INST_DEPS ${INST_DEPS} winvnc4 wm_hooks vncconfig) |
| 143 | endif() |
| 144 | |
| 145 | configure_file(win/tigervnc.iss.in tigervnc.iss) |
| 146 | |
| 147 | add_custom_target(installer |
| 148 | iscc -o${INSTALLERDIR} ${INST_DEFS} ${BUILDDIRDEF} -F${INST_NAME} tigervnc.iss |
| 149 | DEPENDS ${INST_DEPS} |
| 150 | SOURCES tigervnc.iss) |
| 151 | |
| 152 | install(FILES ${CMAKE_SOURCE_DIR}/win/README_BINARY.txt |
| 153 | ${CMAKE_SOURCE_DIR}/LICENCE.txt DESTINATION .) |