CMake build system for Windows


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4171 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..f390767
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,127 @@
+#
+# Setup
+#
+
+cmake_minimum_required(VERSION 2.6)
+
+project(TigerVNC)
+set(VERSION 1.0.90)
+
+# The RC version must always be four comma-separated numbers
+set(RCVERSION 1,0,90,0)
+
+if(MINGW OR CYGWIN)
+  execute_process(COMMAND "date" "+%Y%m%d" OUTPUT_VARIABLE BUILD)
+  string(REGEX REPLACE "\n" "" BUILD ${BUILD})
+elseif(WIN32)
+  execute_process(COMMAND "${CMAKE_SOURCE_DIR}/cmakescripts/getdate.bat"
+    OUTPUT_VARIABLE BUILD)
+  string(REGEX REPLACE "\n" "" BUILD ${BUILD})
+else()
+  message(FATAL_ERROR "Platform not supported by this build system.  Use autotools instead.")
+endif()
+
+if(NOT CMAKE_BUILD_TYPE)
+  set(CMAKE_BUILD_TYPE Release)
+endif()
+
+message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
+
+# This only works if building from the command line.  There is currently no way
+# to set a variable's value based on the build type when using the MSVC IDE.
+if(CMAKE_BUILD_TYPE STREQUAL "Debug")
+  set(BUILD "${BUILD}d")
+endif()
+
+message(STATUS "VERSION = ${VERSION}, BUILD = ${BUILD}")
+
+if(NOT DEFINED BUILD_WINVNC)
+  if(MSVC)
+    set(BUILD_WINVNC 1)
+  else()
+    set(BUILD_WINVNC 0)
+  endif()
+endif()
+
+if(MSVC)
+  # Use the static C library for all build types
+  foreach(var CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
+    CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO
+    CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
+    CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
+    if(${var} MATCHES "/MD")
+      string(REGEX REPLACE "/MD" "/MT" ${var} "${${var}}")
+    endif()
+  endforeach()
+
+  # NOTE: 4244 and 4267 are 64-bit to 32-bit conversion warnings, so normally
+  # it is not a good idea to disable them, but we do this to duplicate the
+  # behavior of GCC, which is less strict.
+  add_definitions(-wd4244 -wd4267 -wd4800 -wd4996)
+endif()
+
+# Detect whether compiler is 64-bit
+if((MSVC AND CMAKE_CL_64) OR (CMAKE_SIZEOF_VOID_P MATCHES 8))
+  set(64BIT 1)
+  set(WIN64 1)
+endif()
+
+if(64BIT)
+  message(STATUS "64-bit build")
+else()
+  message(STATUS "32-bit build")
+endif()
+
+# CMake doesn't properly support resource compilation with MinGW.  Boo!
+if(MINGW)
+  if(NOT DEFINED RC)
+    set(CMAKE_RC_COMPILER_INIT windres)
+  else()
+    set(CMAKE_RC_COMPILER_INIT ${RC})
+  endif()
+  enable_language(RC)
+  message(STATUS "Resource compiler: ${CMAKE_RC_COMPILER}")
+  set(CMAKE_RC_COMPILE_OBJECT
+    "<CMAKE_RC_COMPILER> <FLAGS> <DEFINES> -o <OBJECT> --output-format=coff <SOURCE>")
+endif()
+
+
+add_subdirectory(common)
+add_subdirectory(win)
+
+
+#
+# Installer
+#
+
+set(INST_NAME ${CMAKE_PROJECT_NAME})
+
+if(64BIT)
+  set(INST_NAME ${INST_NAME}64)
+  set(INST_DEFS -DWIN64)
+endif()
+
+if(MSVC_IDE)
+  set(INSTALLERDIR "$(OutDir)")
+  set(BUILDDIRDEF "-DBUILD_DIR=${INSTALLERDIR}\\")
+else()
+  set(INSTALLERDIR .)
+  set(BUILDDIRDEF "-DBUILD_DIR=")
+endif()
+
+set(INST_DEPS vncviewer)
+
+if(BUILD_WINVNC)
+  set(INST_DEFS ${INST_DEFS} -DBUILD_WINVNC)
+  set(INST_DEPS ${INST_DEPS} winvnc4 wm_hooks vncconfig)
+endif()
+
+configure_file(win/tigervnc.iss.in tigervnc.iss)
+
+add_custom_target(installer
+  iscc -o${INSTALLERDIR} ${INST_DEFS} ${BUILDDIRDEF} -F${INST_NAME} tigervnc.iss
+  DEPENDS ${INST_DEPS}
+  SOURCES tigervnc.iss)
+
+install(FILES ${CMAKE_SOURCE_DIR}/win/README_BINARY.txt
+  ${CMAKE_SOURCE_DIR}/LICENCE.txt DESTINATION .)
diff --git a/Makefile.am b/Makefile.am
index 9b7120e..b7de812 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -18,3 +18,5 @@
 
 dmg: all
 	sh $(srcdir)/release/makemacpkg ${PACKAGE_NAME} ${VERSION} ${BUILD} ${srcdir}
+
+EXTRA_DIST = CMakeLists.txt cmakescripts/getdate.bat
diff --git a/cmakescripts/getdate.bat b/cmakescripts/getdate.bat
new file mode 100644
index 0000000..b4251bb
--- /dev/null
+++ b/cmakescripts/getdate.bat
@@ -0,0 +1,3 @@
+@echo off
+for /f "tokens=1-4 eol=/ DELIMS=/ " %%i in ('date /t') do set BUILD=%%l%%j%%k
+echo %BUILD%
diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt
new file mode 100644
index 0000000..aaede05
--- /dev/null
+++ b/common/CMakeLists.txt
@@ -0,0 +1,7 @@
+add_subdirectory(os)
+add_subdirectory(zlib)
+add_subdirectory(jpeg)
+add_subdirectory(rdr)
+add_subdirectory(network)
+add_subdirectory(Xregion)
+add_subdirectory(rfb)
diff --git a/common/Makefile.am b/common/Makefile.am
index d805809..15400c2 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -8,3 +8,5 @@
 endif
 
 SUBDIRS += rdr network Xregion rfb
+
+EXTRA_DIST = CMakeLists.txt
diff --git a/common/Xregion/CMakeLists.txt b/common/Xregion/CMakeLists.txt
new file mode 100644
index 0000000..d12554c
--- /dev/null
+++ b/common/Xregion/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_library(Xregion STATIC
+  Region.c)
diff --git a/common/Xregion/Makefile.am b/common/Xregion/Makefile.am
index fb6a1c7..7ea4c80 100644
--- a/common/Xregion/Makefile.am
+++ b/common/Xregion/Makefile.am
@@ -3,3 +3,5 @@
 HDRS = region.h Xregion.h
 
 libXregion_la_SOURCES = $(HDRS) Region.c
+
+EXTRA_DIST = CMakeLists.txt
diff --git a/common/jpeg/CMakeLists.txt b/common/jpeg/CMakeLists.txt
new file mode 100644
index 0000000..cd867e7
--- /dev/null
+++ b/common/jpeg/CMakeLists.txt
@@ -0,0 +1,117 @@
+#
+# Setup
+#
+
+cmake_minimum_required(VERSION 2.6)
+
+project(libjpeg-turbo)
+set(VERSION 1.0.90)
+
+if(NOT DEFINED WITH_SIMD)
+  set(WITH_SIMD 1)
+endif()
+
+# Detect whether compiler is 64-bit
+if(MSVC AND CMAKE_CL_64)
+  set(SIMD_X86_64 1)
+  set(64BIT 1)
+elseif(CMAKE_SIZEOF_VOID_P MATCHES 8)
+  set(SIMD_X86_64 1)
+  set(64BIT 1)
+endif()
+
+if(64BIT)
+  message(STATUS "64-bit build")
+else()
+  message(STATUS "32-bit build")
+endif()
+
+include_directories(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/win)
+
+
+#
+# Targets
+#
+
+set(JPEG_SOURCES jcapimin.c jcapistd.c jccoefct.c jccolor.c jcdctmgr.c jchuff.c
+  jcinit.c jcmainct.c jcmarker.c jcmaster.c jcomapi.c jcparam.c jcphuff.c
+  jcprepct.c jcsample.c jctrans.c jdapimin.c jdapistd.c jdatadst.c jdatasrc.c
+  jdcoefct.c jdcolor.c jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c
+  jdmaster.c jdmerge.c jdphuff.c jdpostct.c jdsample.c jdtrans.c jerror.c
+  jfdctflt.c jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c jidctred.c
+  jquant1.c jquant2.c jutils.c jmemmgr.c jmemnobs.c)
+
+if(WITH_SIMD)
+  add_definitions(-DWITH_SIMD)
+  add_subdirectory(simd)
+  if(SIMD_X86_64)
+    set(JPEG_SOURCES ${JPEG_SOURCES} simd/jsimd_x86_64.c)
+  else()
+    set(JPEG_SOURCES ${JPEG_SOURCES} simd/jsimd_i386.c)
+  endif()
+  # This tells CMake that the "source" files haven't been generated yet
+  set_source_files_properties(${SIMD_OBJS} PROPERTIES GENERATED 1)
+else()
+  set(JPEG_SOURCES ${JPEG_SOURCES} jsimd_none.c)
+  message(STATUS "Not using SIMD acceleration")
+endif()
+
+add_library(jpeg STATIC ${JPEG_SOURCES} ${SIMD_OBJS})
+if(WITH_SIMD)
+  add_dependencies(jpeg simd)
+endif()
+
+add_executable(jpegut jpegut.c turbojpegl.c)
+target_link_libraries(jpegut jpeg)
+
+add_executable(jpgtest jpgtest.cxx bmp.c turbojpegl.c)
+target_link_libraries(jpgtest jpeg)
+
+add_executable(cjpeg cjpeg.c cdjpeg.c rdbmp.c rdgif.c rdppm.c rdswitch.c
+  rdtarga.c)
+set_property(TARGET cjpeg PROPERTY COMPILE_FLAGS
+  "-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED")
+target_link_libraries(cjpeg jpeg)
+
+add_executable(djpeg djpeg.c cdjpeg.c rdcolmap.c rdswitch.c wrbmp.c wrgif.c
+  wrppm.c wrtarga.c)
+set_property(TARGET djpeg PROPERTY COMPILE_FLAGS
+  "-DBMP_SUPPORTED -DGIF_SUPPORTED -DPPM_SUPPORTED -DTARGA_SUPPORTED")
+target_link_libraries(djpeg jpeg)
+
+add_executable(jpegtran jpegtran.c cdjpeg.c rdswitch.c transupp.c)
+target_link_libraries(jpegtran jpeg)
+
+
+#
+# Tests
+#
+
+enable_testing()
+add_test(jpegut jpegut)
+add_test(cjpeg-int cjpeg -dct int -outfile testoutint.jpg ${CMAKE_CURRENT_SOURCE_DIR}/testorig.ppm)
+add_test(cjpeg-int-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_CURRENT_SOURCE_DIR}/testimgint.jpg testoutint.jpg)
+add_test(cjpeg-fast cjpeg -dct fast -opt -outfile testoutfst.jpg ${CMAKE_CURRENT_SOURCE_DIR}/testorig.ppm)
+add_test(cjpeg-fast-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_CURRENT_SOURCE_DIR}/testimgfst.jpg testoutfst.jpg)
+add_test(cjpeg-float cjpeg -dct float -outfile testoutflt.jpg ${CMAKE_CURRENT_SOURCE_DIR}/testorig.ppm)
+if(WITH_SIMD)
+add_test(cjpeg-float-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_CURRENT_SOURCE_DIR}/testimgflt.jpg testoutflt.jpg)
+else()
+add_test(cjpeg-float-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_CURRENT_SOURCE_DIR}/testimgflt-nosimd.jpg testoutflt.jpg)
+endif()
+add_test(djpeg-int djpeg -dct int -fast -ppm -outfile testoutint.ppm ${CMAKE_CURRENT_SOURCE_DIR}/testorig.jpg)
+add_test(djpeg-int-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_CURRENT_SOURCE_DIR}/testimgint.ppm testoutint.ppm)
+add_test(djpeg-fast djpeg -dct fast -ppm -outfile testoutfst.ppm ${CMAKE_CURRENT_SOURCE_DIR}/testorig.jpg)
+add_test(djpeg-fast-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_CURRENT_SOURCE_DIR}/testimgfst.ppm testoutfst.ppm)
+add_test(djpeg-float djpeg -dct float -ppm -outfile testoutflt.ppm ${CMAKE_CURRENT_SOURCE_DIR}/testorig.jpg)
+if(WITH_SIMD)
+add_test(djpeg-float-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_CURRENT_SOURCE_DIR}/testimgflt.ppm testoutflt.ppm)
+else()
+add_test(djpeg-float-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_CURRENT_SOURCE_DIR}/testorig.ppm testoutflt.ppm)
+endif()
+add_test(djpeg-256 djpeg -dct int -bmp -colors 256 -outfile testout.bmp  ${CMAKE_CURRENT_SOURCE_DIR}/testorig.jpg)
+add_test(djpeg-256-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_CURRENT_SOURCE_DIR}/testimg.bmp testout.bmp)
+add_test(cjpeg-prog cjpeg -dct int -progressive -outfile testoutp.jpg ${CMAKE_CURRENT_SOURCE_DIR}/testorig.ppm)
+add_test(cjpeg-prog-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_CURRENT_SOURCE_DIR}/testimgp.jpg testoutp.jpg)
+add_test(jpegtran-prog jpegtran -outfile testoutt.jpg testoutp.jpg)
+add_test(jpegtran-prog-cmp ${CMAKE_COMMAND} -E compare_files ${CMAKE_CURRENT_SOURCE_DIR}/testimgint.jpg testoutt.jpg)
diff --git a/common/jpeg/Makefile.am b/common/jpeg/Makefile.am
index bae191a..cd1c221 100644
--- a/common/jpeg/Makefile.am
+++ b/common/jpeg/Makefile.am
@@ -57,6 +57,18 @@
 jpegtran_LDADD = libjpeg.la
 
 
+DOCS= README README-turbo.txt LICENSE.txt LGPL.txt
+
+TESTFILES= testorig.jpg testorig.ppm testimg.bmp testimgflt.jpg \
+	testimgfst.jpg testimgint.jpg testimgp.jpg testimgflt.ppm testimgfst.ppm \
+	testimgint.ppm testimgflt-nosimd.jpg
+
+EXTRA_DIST = win $(DOCS) $(TESTFILES) CMakeLists.txt
+
+dist-hook:
+	rm -rf `find $(distdir) -name .svn`
+
+
 if WITH_SIMD
 
 test: testclean all
diff --git a/common/jpeg/simd/CMakeLists.txt b/common/jpeg/simd/CMakeLists.txt
new file mode 100644
index 0000000..5be325e
--- /dev/null
+++ b/common/jpeg/simd/CMakeLists.txt
@@ -0,0 +1,62 @@
+if(NOT DEFINED NASM)
+  set(NASM nasm)
+endif()
+
+if(SIMD_X86_64)
+  set(NAFLAGS -fwin64 -DWIN64 -D__x86_64__ -I${CMAKE_SOURCE_DIR}/win/
+    -I${CMAKE_CURRENT_SOURCE_DIR}/)
+else()
+  set(NAFLAGS -fwin32 -DWIN32 -I${CMAKE_SOURCE_DIR}/win/
+    -I${CMAKE_CURRENT_SOURCE_DIR}/)
+endif()
+
+if(MSVC)
+  set(NAFLAGS ${NAFLAGS} -DMSVC)
+endif()
+
+# This only works if building from the command line.  There is currently no way
+# to set a variable's value based on the build type when using the MSVC IDE.
+if(CMAKE_BUILD_TYPE STREQUAL "Debug"
+  OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
+  set(NAFLAGS ${NAFLAGS} -g)
+endif()
+
+if(SIMD_X86_64)
+  set(SIMD_BASENAMES jfsseflt-64 jccolss2-64 jdcolss2-64 jcsamss2-64
+    jdsamss2-64 jdmerss2-64 jcqnts2i-64 jfss2fst-64 jfss2int-64 jiss2red-64
+    jiss2int-64 jiss2fst-64 jcqnts2f-64 jiss2flt-64)
+  message(STATUS "Building x86_64 SIMD extensions")
+else()
+  set(SIMD_BASENAMES jsimdcpu jccolmmx jdcolmmx jcsammmx jdsammmx jdmermmx
+    jcqntmmx jfmmxfst jfmmxint jimmxred jimmxint jimmxfst jcqnt3dn jf3dnflt
+    ji3dnflt jcqntsse jfsseflt jisseflt jccolss2 jdcolss2 jcsamss2 jdsamss2
+    jdmerss2 jcqnts2i jfss2fst jfss2int jiss2red jiss2int jiss2fst jcqnts2f
+    jiss2flt)
+  message(STATUS "Building i386 SIMD extensions")
+endif()
+
+if(MSVC_IDE)
+  set(OBJDIR "${CMAKE_CURRENT_BINARY_DIR}/$(OutDir)")
+else()
+  set(OBJDIR ${CMAKE_CURRENT_BINARY_DIR})
+endif()
+
+foreach(file ${SIMD_BASENAMES})
+  set(DEPFILE "")
+  set(SIMD_SRC ${CMAKE_CURRENT_SOURCE_DIR}/${file}.asm)
+  if(${file} MATCHES col)
+    set(DEPFILE ${SIMD_SRC})
+    string(REGEX REPLACE "col" "clr" DEPFILE ${DEPFILE})
+  endif()
+  if(${file} MATCHES mer)
+    set(DEPFILE ${SIMD_SRC})
+    string(REGEX REPLACE "mer" "mrg" DEPFILE ${DEPFILE})
+  endif()
+  set(SIMD_OBJ ${OBJDIR}/${file}.obj)
+  add_custom_command(OUTPUT ${SIMD_OBJ} DEPENDS ${SIMD_SRC} ${DEPFILE} *.inc
+    COMMAND ${NASM} ${NAFLAGS} ${SIMD_SRC} -o${SIMD_OBJ})
+  set(SIMD_OBJS ${SIMD_OBJS} ${SIMD_OBJ})
+endforeach()
+
+set(SIMD_OBJS ${SIMD_OBJS} PARENT_SCOPE)
+add_custom_target(simd DEPENDS ${SIMD_OBJS})
diff --git a/common/jpeg/simd/Makefile.am b/common/jpeg/simd/Makefile.am
index a114c37..81c23af 100644
--- a/common/jpeg/simd/Makefile.am
+++ b/common/jpeg/simd/Makefile.am
@@ -4,7 +4,7 @@
 
 EXTRA_DIST = nasm_lt.sh jcclrmmx.asm jcclrss2.asm jdclrmmx.asm jdclrss2.asm \
 	jdmrgmmx.asm jdmrgss2.asm jcclrss2-64.asm jdclrss2-64.asm \
-	jdmrgss2-64.asm
+	jdmrgss2-64.asm CMakeLists.txt
 
 if SIMD_X86_64
 
diff --git a/common/network/CMakeLists.txt b/common/network/CMakeLists.txt
new file mode 100644
index 0000000..2afba7c
--- /dev/null
+++ b/common/network/CMakeLists.txt
@@ -0,0 +1,4 @@
+include_directories(${CMAKE_SOURCE_DIR}/common)
+
+add_library(network STATIC
+  TcpSocket.cxx)
diff --git a/common/network/Makefile.am b/common/network/Makefile.am
index 3db5536..ab8d5ae 100644
--- a/common/network/Makefile.am
+++ b/common/network/Makefile.am
@@ -6,3 +6,4 @@
 
 libnetwork_la_CPPFLAGS = -I$(top_srcdir)/common
 
+EXTRA_DIST = CMakeLists.txt
diff --git a/common/os/CMakeLists.txt b/common/os/CMakeLists.txt
new file mode 100644
index 0000000..bbeec50
--- /dev/null
+++ b/common/os/CMakeLists.txt
@@ -0,0 +1,5 @@
+include_directories(${CMAKE_SOURCE_DIR}/common)
+
+add_library(os STATIC
+  print.c
+  net.c)
diff --git a/common/os/Makefile.am b/common/os/Makefile.am
index 5e37290..ed98579 100644
--- a/common/os/Makefile.am
+++ b/common/os/Makefile.am
@@ -6,3 +6,4 @@
 
 libos_la_CPPFLAGS = -I$(top_srcdir)/common
 
+EXTRA_DIST = CMakeLists.txt
diff --git a/common/rdr/CMakeLists.txt b/common/rdr/CMakeLists.txt
new file mode 100644
index 0000000..2872fd7
--- /dev/null
+++ b/common/rdr/CMakeLists.txt
@@ -0,0 +1,17 @@
+include_directories(${CMAKE_SOURCE_DIR}/common ${CMAKE_SOURCE_DIR}/common/zlib)
+
+add_library(rdr STATIC
+  Exception.cxx
+  FdInStream.cxx
+  FdOutStream.cxx
+  HexInStream.cxx
+  HexOutStream.cxx
+  InStream.cxx
+  RandomStream.cxx
+  TLSException.cxx
+  TLSInStream.cxx
+  TLSOutStream.cxx
+  ZlibInStream.cxx
+  ZlibOutStream.cxx)
+
+target_link_libraries(rdr zlib os)
diff --git a/common/rdr/Makefile.am b/common/rdr/Makefile.am
index ff741c8..ef911c2 100644
--- a/common/rdr/Makefile.am
+++ b/common/rdr/Makefile.am
@@ -18,3 +18,5 @@
 librdr_la_CPPFLAGS += -I$(top_srcdir)/common/zlib
 librdr_la_LIBADD += $(top_builddir)/common/zlib/libz.la
 endif
+
+EXTRA_DIST = CMakeLists.txt
diff --git a/common/rfb/CMakeLists.txt b/common/rfb/CMakeLists.txt
new file mode 100644
index 0000000..6bfb5fe
--- /dev/null
+++ b/common/rfb/CMakeLists.txt
@@ -0,0 +1,70 @@
+include_directories(${CMAKE_SOURCE_DIR}/common ${CMAKE_SOURCE_DIR}/win
+  ${CMAKE_SOURCE_DIR}/common/jpeg ${CMAKE_SOURCE_DIR}/common/jpeg/win)
+
+add_library(rfb STATIC
+  Blacklist.cxx
+  CConnection.cxx
+  CMsgHandler.cxx
+  CMsgReader.cxx
+  CMsgReaderV3.cxx
+  CMsgWriter.cxx
+  CMsgWriterV3.cxx
+  CSecurityPlain.cxx
+  CSecurityStack.cxx
+  CSecurityVeNCrypt.cxx
+  CSecurityVncAuth.cxx
+  CapsContainer.cxx
+  CapsList.cxx
+  ComparingUpdateTracker.cxx
+  Configuration.cxx
+  ConnParams.cxx
+  Cursor.cxx
+  Decoder.cxx
+  d3des.c
+  Encoder.cxx
+  HTTPServer.cxx
+  HextileDecoder.cxx
+  HextileEncoder.cxx
+  KeyRemapper.cxx
+  LogWriter.cxx
+  Logger.cxx
+  Logger_file.cxx
+  Logger_stdio.cxx
+  Password.cxx
+  PixelBuffer.cxx
+  PixelFormat.cxx
+  RREEncoder.cxx
+  RREDecoder.cxx
+  RawDecoder.cxx
+  RawEncoder.cxx
+  Region.cxx
+  SConnection.cxx
+  SMsgHandler.cxx
+  SMsgReader.cxx
+  SMsgReaderV3.cxx
+  SMsgWriter.cxx
+  SMsgWriterV3.cxx
+  ServerCore.cxx
+  Security.cxx
+  SecurityServer.cxx
+  SecurityClient.cxx
+  SSecurityPlain.cxx
+  SSecurityStack.cxx
+  SSecurityVncAuth.cxx
+  SSecurityVeNCrypt.cxx
+  ScaledPixelBuffer.cxx
+  ScaleFilters.cxx
+  Timer.cxx
+  TightDecoder.cxx
+  TightEncoder.cxx
+  TightPalette.cxx
+  TransImageGetter.cxx
+  UpdateTracker.cxx
+  VNCSConnectionST.cxx
+  VNCServerST.cxx
+  ZRLEEncoder.cxx
+  ZRLEDecoder.cxx
+  encodings.cxx
+  util.cxx)
+
+target_link_libraries(rfb jpeg os)
diff --git a/common/rfb/Makefile.am b/common/rfb/Makefile.am
index ce196c6..796c10b 100644
--- a/common/rfb/Makefile.am
+++ b/common/rfb/Makefile.am
@@ -66,3 +66,5 @@
 librfb_la_CPPFLAGS += -I$(top_srcdir)/common/jpeg -I$(top_builddir)/common/jpeg
 librfb_la_LIBADD += $(top_builddir)/common/jpeg/libjpeg.la
 endif
+
+EXTRA_DIST = CMakeLists.txt
diff --git a/common/zlib/CMakeLists.txt b/common/zlib/CMakeLists.txt
new file mode 100644
index 0000000..3f1db1b
--- /dev/null
+++ b/common/zlib/CMakeLists.txt
@@ -0,0 +1,18 @@
+add_definitions(-DNO_VIZ -DWINDOWS)
+
+add_library(zlib STATIC 
+  adler32.c
+  compress.c
+  crc32.c
+  deflate.c
+  gzclose.c
+  gzlib.c
+  gzread.c
+  gzwrite.c
+  inflate.c
+  infback.c
+  inftrees.c
+  inffast.c
+  trees.c
+  uncompr.c
+  zutil.c)
diff --git a/common/zlib/Makefile.am b/common/zlib/Makefile.am
index a8c7318..743ac5c 100644
--- a/common/zlib/Makefile.am
+++ b/common/zlib/Makefile.am
@@ -3,6 +3,8 @@
 HDRS = deflate.h infblock.h infcodes.h inffast.h inffixed.h inftrees.h \
 	infutil.h trees.h zconf.h zlib.h zutil.h
 
-libz_la_SOURCES = $(HDRS) adler32.c compress.c crc32.c deflate.c gzclose.c \

-	gzlib.c gzread.c gzwrite.c inflate.c infback.c inftrees.c inffast.c \

-	trees.c uncompr.c zutil.c

+libz_la_SOURCES = $(HDRS) adler32.c compress.c crc32.c deflate.c gzclose.c \
+	gzlib.c gzread.c gzwrite.c inflate.c infback.c inftrees.c inffast.c \
+	trees.c uncompr.c zutil.c
+
+EXTRA_DIST = CMakeLists.txt
diff --git a/release/BUILDING.txt b/release/BUILDING.txt
index 4dc8441..6c08bc3 100644
--- a/release/BUILDING.txt
+++ b/release/BUILDING.txt
@@ -1,5 +1,5 @@
 *******************************************************************************
-**     Building TigerVNC
+**     Building on Unix Platforms (including Cygwin)
 *******************************************************************************
 
 
@@ -8,9 +8,7 @@
 ==================
 
 -- autoconf 2.57 or later
-
 -- automake 1.7 or later
-
 -- libtool 1.4 or later
 
 -- NASM
@@ -19,9 +17,9 @@
    * NASM 2.07 or later is required for a 64-bit build on OS X.  This can be
      obtained from MacPorts (http://www.macports.org/).
 
-   The NASM 2.05 RPMs do not work on older Linux systems, such as Enterprise
-   Linux 4.  On such systems, you can easily build and install NASM 2.05
-   from the source RPM by executing the following as root:
+   The NASM 2.05 RPMs do not work on older Linux systems, such as Red Hat
+   Enterprise Linux 4.  On such systems, you can easily build and install NASM
+   2.05 from the source RPM by executing the following as root:
 
      ARCH=`uname -m`
      wget http://www.nasm.us/pub/nasm/releasebuilds/2.05.01/nasm-2.05.01-1.src.rpm
@@ -40,6 +38,20 @@
    * OpenSSL v0.9.7 or later
 
 
+==================
+Out-of-Tree Builds
+==================
+
+Binary objects, libraries, and executables are generated in the same directory
+from which configure was executed (the "binary directory"), and this directory
+need not necessarily be the same as the TigerVNC source directory.  You can
+create multiple independent binary directories, in which different versions of
+TigerVNC can be built from the same source tree using different compilers or
+settings.  In the sections below, {build_directory} refers to the binary
+directory, whereas {source_directory} refers to the TigerVNC source directory.
+For in-tree builds, these directories are the same.
+
+
 =================
 Building TigerVNC
 =================
@@ -49,13 +61,14 @@
 depending on the default compiler configuration for your system.  See below for
 specific build instructions for 64-bit systems.
 
-  cd tigervnc
+  cd {source_directory}
   autoreconf -fiv
-  sh ./configure [additional configure flags]
+  cd {build_directory}
+  sh {source_directory}/configure [additional configure flags]
   make
 
-NOTE: Running autoreconf is only necessary if building TigerVNC from the SVN
-repository.
+NOTE: Running autoreconf in the source directory is only necessary if building
+TigerVNC from the SVN repository.
 
 Building the TigerVNC server (Xvnc) is a bit trickier.  On newer systems, such
 as Fedora, Xvnc is typically built to use the X11 shared libraries provided
@@ -70,15 +83,15 @@
 The following procedure will build both the TigerVNC viewer and a
 "legacy-friendly" version of the TigerVNC server:
 
-  cd tigervnc
-  unix/build-xorg init -version 7.4
-  unix/build-xorg build -version 7.4 [-static] [additional configure flags]
+  cd {build_directory}
+  sh {source_directory}/unix/build-xorg init -version 7.4
+  sh {source_directory}/unix/build-xorg build -version 7.4 [-static] [additional configure flags]
 
 Passing an argument of "-static" to the build command line will generate a
 version of Xvnc that has no external dependencies on the X11 shared libraries
 or any other distribution-specific shared libraries.  This version of Xvnc
 should be transportable across multiple O/S distributions.  The legacy-friendly
-build should work on RedHat Enterprise 4, its contemporaries, and later
+build should work on Red Hat Enterprise 4, its contemporaries, and later
 systems.  It probably will not work on older systems.  It has not been tested
 on non-Linux systems (yet).
 
@@ -87,11 +100,11 @@
 This is convenient for testing changes that just apply to the TigerVNC source
 code.  To accomplish this, run:
 
-  unix/build-xorg rebuild [additional make flags]
+  sh {source_directory}/unix/build-xorg rebuild [additional make flags]
 
 For instance,
 
-  unix/build-xorg rebuild clean
+  sh {source_directory}/unix/build-xorg rebuild clean
 
 will clean both the Xvnc and vncviewer builds without destroying any of the
 build configuration or module dependencies.
@@ -109,7 +122,7 @@
 
   --host i686-pc-linux-gnu CFLAGS='-O3 -m32' CXXFLAGS='-O3 -m32' LDFLAGS=-m32
 
-to the configure and build command lines.
+to the configure or build command lines.
 
 
 64-bit Build on 64-bit OS X
@@ -189,11 +202,219 @@
 
 
 *******************************************************************************
+**     Building on Windows (Visual C++ or MinGW)
+*******************************************************************************
+
+
+==================
+Build Requirements
+==================
+
+-- CMake (http://www.cmake.org) v2.6 or later
+
+-- Microsoft Visual C++ 2005 or later
+
+   If you don't already have Visual C++, then the easiest way to get it is by
+   installing the Windows SDK:
+
+   http://msdn.microsoft.com/en-us/windows/bb980924.aspx
+
+   The Windows SDK includes both 32-bit and 64-bit Visual C++ compilers and
+   everything necessary to build TigerVNC.
+
+   * For 32-bit builds, you can also use Microsoft Visual C++ Express
+     Edition.  Visual C++ Express Edition is a free download.
+   * If you intend to build TigerVNC from the command line, then add the
+     appropriate compiler and SDK directories to the INCLUDE, LIB, and PATH
+     environment variables.  This is generally accomplished by executing
+     vcvars32.bat or vcvars64.bat and SetEnv.cmd.  vcvars32.bat and
+     vcvars64.bat are part of Visual C++ and are located in the same directory
+     as the compiler.  SetEnv.cmd is part of the Windows SDK.  You can pass
+     optional arguments to SetEnv.cmd to specify a 32-bit or 64-bit build
+     environment.
+
+... OR ...
+
+-- MinGW
+
+   GCC v4.1 or later recommended for best performance
+
+-- NASM (http://www.nasm.us/) 0.98 or later (NASM 2.05 or later is required for
+   a 64-bit build)
+
+-- Inno Setup (needed to build the TigerVNC installer)
+   Inno Setup can be downloaded from http://www.jrsoftware.org/isinfo.php.
+   You also need the Inno Setup Preprocessor, which is available in the
+   Inno Setup QuickStart Pack.
+
+   Add the directory containing iscc.exe (for instance, 
+   C:\Program Files\Inno Setup 5) to the system or user PATH environment
+   variable prior to building TigerVNC.
+
+
+==================
+Out-of-Tree Builds
+==================
+
+Binary objects, libraries, and executables are generated in the same directory
+from which cmake was executed (the "binary directory"), and this directory need
+not necessarily be the same as the TigerVNC source directory.  You can create
+multiple independent binary directories, in which different versions of
+TigerVNC can be built from the same source tree using different compilers or
+settings.  In the sections below, {build_directory} refers to the binary
+directory, whereas {source_directory} refers to the TigerVNC source directory.
+For in-tree builds, these directories are the same.
+
+
+=================
+Building TigerVNC
+=================
+
+
+Visual C++ (Command Line)
+-------------------------
+
+  cd {build_directory}
+  cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release {source_directory}
+  nmake
+
+This will build either a 32-bit or a 64-bit version of TigerVNC, depending
+on which version of cl.exe is in the PATH.
+
+
+Visual C++ (IDE)
+----------------
+
+Choose the appropriate CMake generator option for your version of Visual Studio
+(run "cmake" with no arguments for a list of available generators.)  For
+instance:
+
+  cd {build_directory}
+  cmake -G "Visual Studio 9 2008" {source_directory}
+
+You can then open ALL_BUILD.vcproj in Visual Studio and build one of the
+configurations in that project ("Debug", "Release", etc.) to generate a full
+build of TigerVNC.
+
+
+MinGW
+-----
+
+  cd {build_directory}
+  cmake -G "MSYS Makefiles" {source_directory}
+  make
+
+This will generate only vncviewer.  Currently, Visual C++ must be used to build
+WinVNC.
+
+
+Debug Build
+-----------
+
+Add "-DCMAKE_BUILD_TYPE=Debug" to the cmake command line.  Or, if building with
+NMake, remove "-DCMAKE_BUILD_TYPE=Release" (Debug builds are the default with
+NMake.)
+
+
+===================
+Installing TigerVNC
+===================
+
+You can use the build system to install TigerVNC into a directory of your
+choosing (as opposed to creating an installer.)  To do this, add:
+
+  -DCMAKE_INSTALL_PREFIX={install_directory}
+
+to the cmake command line.
+
+For example,
+
+  cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release \
+    -DCMAKE_INSTALL_PREFIX=c:\TigerVNC {source_directory}
+  nmake install
+
+If you don't specify CMAKE_INSTALL_PREFIX, then the default is
+c:\Program Files\TigerVNC.
+
+
+=============
+Build Recipes
+=============
+
+
+64-bit MinGW Build on Cygwin
+----------------------------
+
+  cd {build_directory}
+  CC=/usr/bin/x86_64-w64-mingw32-gcc CXX=/usr/bin/x86_64-w64-mingw32-g++ \
+    RC=/usr/bin/x86_64-w64-mingw32-windres \
+    cmake -G "Unix Makefiles" -DCMAKE_SYSTEM_NAME=Windows \
+    -DCMAKE_AR=/usr/bin/x86_64-w64-mingw32-ar \
+    -DCMAKE_RANLIB=/usr/bin/x86_64-w64-mingw32-ranlib {source_directory}
+  make
+
+This produces a 64-bit build of TigerVNC that does not depend on cygwin1.dll or
+other Cygwin DLL's.  The mingw64-x86_64-gcc-core and mingw64-x86_64-gcc-g++
+packages (and their dependencies) must be installed.
+
+
+32-bit MinGW Build on Cygwin
+----------------------------
+
+  cd {build_directory}
+  CC=/usr/bin/i686-w64-mingw32-gcc CXX=/usr/bin/i686-w64-mingw32-g++ \
+    RC=/usr/bin/i686-w64-mingw32-windres \
+    cmake -G "Unix Makefiles" -DCMAKE_SYSTEM_NAME=Windows \
+    -DDCMAKE_AR=/usr/bin/i686-w64-mingw32-ar \
+    -DCMAKE_RANLIB=/usr/bin/i686-w64-mingw32-ranlib {source_directory}
+  make
+
+This produces a 32-bit build of TigerVNC that does not depend on cygwin1.dll or
+other Cygwin DLL's.  The mingw64-i686-gcc-core and mingw64-i686-gcc-g++
+packages (and their dependencies) must be installed.
+
+
+MinGW-w64 Build on Windows
+--------------------------
+
+This produces a 64-bit build of TigerVNC using the "native" MinGW-w64 toolchain
+(which is faster than the Cygwin version):
+
+  cd {build_directory}
+  CC={mingw-w64_binary_path}/x86_64-w64-mingw32-gcc \
+    CXX={mingw-w64_binary_path}/x86_64-w64-mingw32-g++ \
+    RC={mingw-w64_binary_path}/x86_64-w64-mingw32-windres \
+    cmake -G "MSYS Makefiles" \
+    -DCMAKE_AR={mingw-w64_binary_path}/x86_64-w64-mingw32-ar \
+    -DCMAKE_RANLIB={mingw-w64_binary_path}/x86_64-w64-mingw32-ranlib \
+    {source_directory}
+  make
+
+
+MinGW Build on Linux
+--------------------
+
+  cd {build_directory}
+  CC={mingw_binary_path}/i386-mingw32-gcc \
+    CXX={mingw_binary_path}/i386-mingw32-g++ \
+    RC={mingw_binary_path}/i386-mingw32-windres \
+    cmake -G "Unix Makefiles" -DCMAKE_SYSTEM_NAME=Windows \
+    -DCMAKE_AR={mingw_binary_path}/i386-mingw32-ar \
+    -DCMAKE_RANLIB={mingw_binary_path}/i386-mingw32-ranlib \
+    {source_directory}
+  make
+
+
+*******************************************************************************
 **     Creating Release Packages
 *******************************************************************************
 
 The following commands can be used to create various types of release packages:
 
+
+Unix
+----
+
 make dmg
 
   Create Macintosh package/disk image.  This requires the PackageMaker
@@ -207,3 +428,25 @@
   later (OS X 10.4 compatibility SDK required.)  If building on OS X 10.6
   ("Snow Leopard") or later, the 64-bit fork can be made backward compatible
   with 10.5 by using the instructions in the "Build Recipes" section.
+
+
+Windows
+-------
+
+If using NMake:
+
+  cd {build_directory}
+  nmake installer
+
+If using MinGW:
+
+  cd {build_directory}
+  make installer
+
+If using the Visual Studio IDE, build the "installer" project.
+
+The installer package (TigerVNC[64].exe) will be located under
+{build_directory}.  If building using the Visual Studio IDE, then the installer
+package will be located in a subdirectory with the same name as the
+configuration you built (such as {build_directory}\Debug\ or
+{build_directory}\Release\).
diff --git a/win/CMakeLists.txt b/win/CMakeLists.txt
new file mode 100644
index 0000000..ee0a5c0
--- /dev/null
+++ b/win/CMakeLists.txt
@@ -0,0 +1,12 @@
+add_definitions(-D_WIN32_IE=0x0500 -D_WIN32_WINNT=0x0500)
+
+include_directories(${CMAKE_SOURCE_DIR}/common ${CMAKE_SOURCE_DIR}/win)
+
+configure_file(resdefs.h.in resdefs.h)
+
+add_subdirectory(rfb_win32)
+add_subdirectory(vncviewer)
+if(BUILD_WINVNC)
+add_subdirectory(vncconfig)
+add_subdirectory(winvnc)
+endif()
diff --git a/win/Makefile.am b/win/Makefile.am
index 7f2d96c..372b699 100644
--- a/win/Makefile.am
+++ b/win/Makefile.am
@@ -4,4 +4,4 @@
 SUBDIRS += vncconfig winvnc
 endif
 
-EXTRA_DIST = logmessages/messages.h
+EXTRA_DIST = logmessages/messages.h CMakeLists.txt
diff --git a/win/README_BINARY.txt b/win/README_BINARY.txt
index 36dff10..fbef352 100644
--- a/win/README_BINARY.txt
+++ b/win/README_BINARY.txt
@@ -5,6 +5,7 @@
 Copyright (C) 2002-2004 RealVNC Ltd.  All Rights Reserved.
 Copyright (C) 2000-2004 Constantin Kaplinsky.
 Copyright (C) 2004-2009 Peter Astrand for Cendio AB
+Copyright (C) 2009-2010 D. R. Commander
 
 This software is distributed under the GNU General Public Licence as
 published by the Free Software Foundation.  See the file LICENCE.TXT
diff --git a/win/resdefs.h.in b/win/resdefs.h.in
new file mode 100644
index 0000000..b61db53
--- /dev/null
+++ b/win/resdefs.h.in
@@ -0,0 +1,4 @@
+#define __VERSIONSTR "@VERSION@\0"
+#define __RCVERSION @RCVERSION@
+#define __RCVERSIONSTR "@RCVERSION@\0"
+#cmakedefine WIN64
diff --git a/win/rfb_win32/CMakeLists.txt b/win/rfb_win32/CMakeLists.txt
new file mode 100644
index 0000000..60af6db
--- /dev/null
+++ b/win/rfb_win32/CMakeLists.txt
@@ -0,0 +1,48 @@
+set(RFB_WIN32_SOURCES
+  AboutDialog.cxx
+  CKeyboard.cxx
+  Clipboard.cxx
+  CPointer.cxx
+  CurrentUser.cxx
+  DeviceContext.cxx
+  DeviceFrameBuffer.cxx
+  Dialog.cxx
+  DIBSectionBuffer.cxx
+  DynamicFn.cxx
+  EventManager.cxx
+  LaunchProcess.cxx
+  ListViewControl.cxx
+  LowLevelKeyEvents.cxx
+  MonitorInfo.cxx
+  MsgWindow.cxx
+  OSVersion.cxx
+  ProgressControl.cxx
+  RegConfig.cxx
+  Registry.cxx
+  ScaledDIBSectionBuffer.cxx
+  SDisplayCorePolling.cxx
+  SDisplayCoreWMHooks.cxx
+  SDisplay.cxx
+  Security.cxx
+  Service.cxx
+  SInput.cxx
+  SocketManager.cxx
+  TCharArray.cxx
+  Threading.cxx
+  ToolBar.cxx
+  TsSessions.cxx
+  Win32Util.cxx
+  WMCursor.cxx
+  WMHooks.cxx
+  WMNotifier.cxx
+  WMPoller.cxx
+  WMShatter.cxx
+  WMWindowCopyRect.cxx)
+
+if(BUILD_WINVNC)
+  set(RFB_WIN32_SOURCES ${RFB_WIN32_SOURCES} CleanDesktop.cxx)
+endif()
+
+add_library(rfb_win32 STATIC ${RFB_WIN32_SOURCES})
+
+target_link_libraries(rfb_win32 user32.lib comctl32.lib version.lib)
diff --git a/win/rfb_win32/Makefile.am b/win/rfb_win32/Makefile.am
index 74f74e8..80d9286 100644
--- a/win/rfb_win32/Makefile.am
+++ b/win/rfb_win32/Makefile.am
@@ -104,3 +104,5 @@
 
 librfb_win32_la_CPPFLAGS = -I$(top_srcdir)/common -I$(top_srcdir)/win
 librfb_win32_la_LIBADD =
+
+EXTRA_DIST = CMakeLists.txt
diff --git a/win/tigervnc.iss b/win/tigervnc.iss
deleted file mode 100644
index ae7697a..0000000
--- a/win/tigervnc.iss
+++ /dev/null
@@ -1,42 +0,0 @@
-

-[Setup]

-OutputDir=.

-AppName=TigerVNC

-AppVerName=TigerVNC 1.0.90

-AppVersion=1.0.90

-AppPublisher=TigerVNC project

-AppPublisherURL=http://tigervnc.org

-DefaultDirName={pf}\TigerVNC

-DefaultGroupName=TigerVNC

-LicenseFile=LICENCE.txt

-

-[Files]

-Source: "Release\winvnc4.exe"; DestDir: "{app}"; Flags: ignoreversion restartreplace; 

-Source: "Release\wm_hooks.dll"; DestDir: "{app}"; Flags: ignoreversion restartreplace; 

-Source: "Release\vncviewer.exe"; DestDir: "{app}"; Flags: ignoreversion restartreplace; 

-Source: "Release\vncconfig.exe"; DestDir: "{app}"; Flags: ignoreversion restartreplace; 

-Source: "README_BINARY.txt"; DestDir: "{app}"; Flags: ignoreversion

-Source: "LICENCE.txt"; DestDir: "{app}"; Flags: ignoreversion

-

-

-[Icons]

-Name: "{group}\TigerVNC Viewer"; FileName: "{app}\vncviewer.exe";

-Name: "{group}\Listening TigerVNC Viewer"; FileName: "{app}\vncviewer.exe"; Parameters: "-listen";

-

-Name: "{group}\VNC Server (User-Mode)\Run VNC Server"; FileName: "{app}\winvnc4.exe"; Parameters: "-noconsole";

-Name: "{group}\VNC Server (User-Mode)\Configure VNC Server"; FileName: "{app}\vncconfig.exe"; Parameters: "-user";

-

-Name: "{group}\VNC Server (Service-Mode)\Configure VNC Service"; FileName: "{app}\vncconfig.exe"; Parameters: "-noconsole -service";

-Name: "{group}\VNC Server (Service-Mode)\Register VNC Service"; FileName: "{app}\winvnc4.exe"; Parameters: "-register";

-Name: "{group}\VNC Server (Service-Mode)\Unregister VNC Service"; FileName: "{app}\winvnc4.exe"; Parameters: "-unregister";

-Name: "{group}\VNC Server (Service-Mode)\Start VNC Service"; FileName: "{app}\winvnc4.exe"; Parameters: "-noconsole -start";

-Name: "{group}\VNC Server (Service-Mode)\Stop VNC Service"; FileName: "{app}\winvnc4.exe"; Parameters: "-noconsole -stop";

-Name: "{group}\License"; FileName: "{app}\LICENCE.txt";

-

-[Tasks]

-Name: installservice; Description: "&Register new TigerVNC Server as a system service"; GroupDescription: "Server configuration:"; 

-Name: startservice; Description: "&Start or restart TigerVNC service"; GroupDescription: "Server configuration:";

-

-[Run]

-Filename: "{app}\winvnc4.exe"; Parameters: "-register"; Tasks: installservice

-Filename: "net"; Parameters: "start winvnc4"; Tasks: startservice

diff --git a/win/tigervnc.iss.in b/win/tigervnc.iss.in
new file mode 100644
index 0000000..2d967a4
--- /dev/null
+++ b/win/tigervnc.iss.in
@@ -0,0 +1,57 @@
+[Setup]
+#ifdef WIN64
+ArchitecturesInstallIn64BitMode=x64
+AppName=TigerVNC 64-bit
+AppVerName=TigerVNC 64-bit @VERSION@ (@BUILD@)
+#else
+AppName=TigerVNC
+AppVerName=TigerVNC v@VERSION@ (@BUILD@)
+#endif
+AppVersion=@VERSION@
+AppPublisher=TigerVNC project
+AppPublisherURL=http://tigervnc.org
+DefaultDirName={pf}\TigerVNC
+#ifdef WIN64
+DefaultGroupName=TigerVNC 64-bit
+#else
+DefaultGroupName=TigerVNC
+#endif
+LicenseFile=@CMAKE_SOURCE_DIR@\LICENCE.txt
+
+[Files]
+#ifdef BUILD_WINVNC
+Source: "@CMAKE_CURRENT_BINARY_DIR@\win\winvnc\{#BUILD_DIR}winvnc4.exe"; DestDir: "{app}"; Flags: ignoreversion restartreplace; 
+Source: "@CMAKE_CURRENT_BINARY_DIR@\win\winvnc\{#BUILD_DIR}wm_hooks.dll"; DestDir: "{app}"; Flags: ignoreversion restartreplace; 
+Source: "@CMAKE_CURRENT_BINARY_DIR@\win\vncconfig\{#BUILD_DIR}vncconfig.exe"; DestDir: "{app}"; Flags: ignoreversion restartreplace; 
+#endif
+Source: "@CMAKE_CURRENT_BINARY_DIR@\win\vncviewer\{#BUILD_DIR}vncviewer.exe"; DestDir: "{app}"; Flags: ignoreversion restartreplace; 
+Source: "@CMAKE_SOURCE_DIR@\win\README_BINARY.txt"; DestDir: "{app}"; Flags: ignoreversion
+Source: "@CMAKE_SOURCE_DIR@\LICENCE.txt"; DestDir: "{app}"; Flags: ignoreversion
+
+
+[Icons]
+Name: "{group}\TigerVNC Viewer"; FileName: "{app}\vncviewer.exe";
+Name: "{group}\Listening TigerVNC Viewer"; FileName: "{app}\vncviewer.exe"; Parameters: "-listen";
+
+#ifdef BUILD_WINVNC
+Name: "{group}\VNC Server (User-Mode)\Run VNC Server"; FileName: "{app}\winvnc4.exe"; Parameters: "-noconsole";
+Name: "{group}\VNC Server (User-Mode)\Configure VNC Server"; FileName: "{app}\vncconfig.exe"; Parameters: "-user";
+
+Name: "{group}\VNC Server (Service-Mode)\Configure VNC Service"; FileName: "{app}\vncconfig.exe"; Parameters: "-noconsole -service";
+Name: "{group}\VNC Server (Service-Mode)\Register VNC Service"; FileName: "{app}\winvnc4.exe"; Parameters: "-register";
+Name: "{group}\VNC Server (Service-Mode)\Unregister VNC Service"; FileName: "{app}\winvnc4.exe"; Parameters: "-unregister";
+Name: "{group}\VNC Server (Service-Mode)\Start VNC Service"; FileName: "{app}\winvnc4.exe"; Parameters: "-noconsole -start";
+Name: "{group}\VNC Server (Service-Mode)\Stop VNC Service"; FileName: "{app}\winvnc4.exe"; Parameters: "-noconsole -stop";
+#endif
+Name: "{group}\License"; FileName: "{app}\LICENCE.txt";
+Name: "{group}\Uninstall TigerVNC"; FileName: "{uninstallexe}"; WorkingDir: "{app}";
+
+#ifdef BUILD_WINVNC
+[Tasks]
+Name: installservice; Description: "&Register new TigerVNC Server as a system service"; GroupDescription: "Server configuration:"; 
+Name: startservice; Description: "&Start or restart TigerVNC service"; GroupDescription: "Server configuration:";
+
+[Run]
+Filename: "{app}\winvnc4.exe"; Parameters: "-register"; Tasks: installservice
+Filename: "net"; Parameters: "start winvnc4"; Tasks: startservice
+#endif
diff --git a/win/vncconfig/CMakeLists.txt b/win/vncconfig/CMakeLists.txt
new file mode 100644
index 0000000..9883dbd
--- /dev/null
+++ b/win/vncconfig/CMakeLists.txt
@@ -0,0 +1,18 @@
+include_directories(${CMAKE_BINARY_DIR}/win)
+
+# Disable auto-generated manifests, since we have our own
+if(MSVC)
+  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
+endif()
+
+add_executable(vncconfig WIN32
+  Legacy.cxx
+  PasswordDialog.cxx
+  vncconfig.cxx
+  vncconfig.rc)
+
+target_link_libraries(vncconfig rfb_win32 rfb Xregion network rdr ws2_32.lib)
+
+install(TARGETS vncconfig
+  RUNTIME DESTINATION .
+)
diff --git a/win/vncconfig/Makefile.am b/win/vncconfig/Makefile.am
index 84d1b0f..b22b28c 100644
--- a/win/vncconfig/Makefile.am
+++ b/win/vncconfig/Makefile.am
@@ -14,7 +14,7 @@
 	$(top_builddir)/common/rdr/librdr.la -lws2_32 -lgdi32 -lversion -lole32 \

 	-lcomctl32 resources.o

 

-EXTRA_DIST = vncconfig.ico vncconfig.rc vncconfig.exe.manifest

+EXTRA_DIST = vncconfig.ico vncconfig.rc vncconfig.exe.manifest CMakeLists.txt

 

 resources.o: vncconfig.rc

 	$(WINDRES) $^ -o $@

diff --git a/win/vncconfig/vncconfig.exe.manifest64 b/win/vncconfig/vncconfig.exe.manifest64
new file mode 100644
index 0000000..10eefa3
--- /dev/null
+++ b/win/vncconfig/vncconfig.exe.manifest64
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+<assemblyIdentity
+   version="4.0.0.26"
+   processorArchitecture="AMD64"
+   name="TigerVNC.vncconfig.exe"
+   type="win32"
+/>
+<description>.NET control deployment tool</description>
+<dependency>
+   <dependentAssembly>
+     <assemblyIdentity
+       type="win32"
+       name="Microsoft.Windows.Common-Controls"
+       version="6.0.0.0"
+       processorArchitecture="AMD64"
+       publicKeyToken="6595b64144ccf1df"
+       language="*"
+     />
+   </dependentAssembly>
+</dependency>
+</assembly>
diff --git a/win/vncconfig/vncconfig.rc b/win/vncconfig/vncconfig.rc
index 7292f1a..df6cfdd 100644
--- a/win/vncconfig/vncconfig.rc
+++ b/win/vncconfig/vncconfig.rc
@@ -1,6 +1,7 @@
 //Microsoft Developer Studio generated resource script.
 //
 #include "resource.h"
+#include "resdefs.h"
 
 #define APSTUDIO_READONLY_SYMBOLS
 /////////////////////////////////////////////////////////////////////////////
@@ -438,8 +439,8 @@
 //
 
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION 1,0,90,0
- PRODUCTVERSION 1,0,90,0
+ FILEVERSION __RCVERSION
+ PRODUCTVERSION __RCVERSION
  FILEFLAGSMASK 0x3fL
 #ifdef _DEBUG
  FILEFLAGS 0x1L
@@ -456,15 +457,20 @@
         BEGIN
             VALUE "Comments", "\0"
             VALUE "CompanyName", "TigerVNC Project\0"
+            #ifdef WIN64
+            VALUE "FileDescription", "TigerVNC Server Configuration Applet for Win64\0"
+            VALUE "ProductName", "TigerVNC Server Configuration Applet for Win64\0"
+            #else
             VALUE "FileDescription", "TigerVNC Server Configuration Applet for Win32\0"
-            VALUE "FileVersion", "1.0.90\0"
+            VALUE "ProductName", "TigerVNC Server Configuration Applet for Win32\0"
+            #endif
+            VALUE "FileVersion", __RCVERSIONSTR
             VALUE "InternalName", "vncconfig\0"
-            VALUE "LegalCopyright", "Copyright (C) 1998-2009 [many holders]\0"
+            VALUE "LegalCopyright", "Copyright (C) 1998-2010 [many holders]\0"
             VALUE "LegalTrademarks", "TigerVNC\0"
             VALUE "OriginalFilename", "vncconfig.exe\0"
             VALUE "PrivateBuild", "\0"
-            VALUE "ProductName", "TigerVNC Configurator\0"
-            VALUE "ProductVersion", "1.0.90\0"
+            VALUE "ProductVersion", __VERSIONSTR
             VALUE "SpecialBuild", "\0"
         END
     END
@@ -482,7 +488,11 @@
 // 24
 //
 
+#ifdef WIN64
+IDR_MANIFEST            24      DISCARDABLE     "vncconfig.exe.manifest64"
+#else
 IDR_MANIFEST            24      DISCARDABLE     "vncconfig.exe.manifest"
+#endif
 #endif    // English (U.K.) resources
 /////////////////////////////////////////////////////////////////////////////
 
diff --git a/win/vncviewer/CMakeLists.txt b/win/vncviewer/CMakeLists.txt
new file mode 100644
index 0000000..863e2d0
--- /dev/null
+++ b/win/vncviewer/CMakeLists.txt
@@ -0,0 +1,28 @@
+include_directories(${CMAKE_BINARY_DIR}/win)
+
+# Disable auto-generated manifests, since we have our own
+if(MSVC)
+  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
+endif()
+
+add_executable(vncviewer WIN32
+  buildTime.cxx
+  CConn.cxx
+  CConnOptions.cxx
+  CConnThread.cxx
+  ConnectingDialog.cxx
+  ConnectionDialog.cxx
+  DesktopWindow.cxx
+  InfoDialog.cxx
+  OptionsDialog.cxx
+  UserPasswdDialog.cxx
+  ViewerToolBar.cxx
+  vncviewer.cxx
+  vncviewer.rc)
+
+target_link_libraries(vncviewer rfb rfb_win32 Xregion network rdr
+  ws2_32.lib)
+
+install(TARGETS vncviewer
+  RUNTIME DESTINATION .
+)
diff --git a/win/vncviewer/Makefile.am b/win/vncviewer/Makefile.am
index db398ae..1a48625 100644
--- a/win/vncviewer/Makefile.am
+++ b/win/vncviewer/Makefile.am
@@ -42,7 +42,7 @@
 vncviewer_LDFLAGS = -I$(top_srcdir)/win -mwindows
 
 EXTRA_DIST = vncviewer.rc vncviewer.ico cursor1.cur vncviewer.exe.manifest \
-	vncviewer.bmp toolbar.bmp
+	vncviewer.bmp toolbar.bmp CMakeLists.txt
 
 resources.o: vncviewer.rc
 	$(WINDRES) $^ -o $@
diff --git a/win/vncviewer/vncviewer.rc b/win/vncviewer/vncviewer.rc
index 076d5b8..60aa636 100644
--- a/win/vncviewer/vncviewer.rc
+++ b/win/vncviewer/vncviewer.rc
@@ -1,6 +1,7 @@
 //Microsoft Developer Studio generated resource script.
 //
 #include "resource.h"
+#include "resdefs.h"
 
 #define APSTUDIO_READONLY_SYMBOLS
 /////////////////////////////////////////////////////////////////////////////
@@ -67,8 +68,8 @@
 //
 
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION 1,0,90,0
- PRODUCTVERSION 1,0,90,0
+ FILEVERSION __RCVERSION
+ PRODUCTVERSION __RCVERSION
  FILEFLAGSMASK 0x3fL
 #ifdef _DEBUG
  FILEFLAGS 0x1L
@@ -85,15 +86,20 @@
         BEGIN
             VALUE "Comments", "\0"
             VALUE "CompanyName", "TigerVNC Project\0"
+            #ifdef WIN64
+            VALUE "FileDescription", "TigerVNC Viewer for Win64\0"
+            VALUE "ProductName", "TigerVNC Viewer for Win64\0"
+            #else
             VALUE "FileDescription", "TigerVNC Viewer for Win32\0"
-            VALUE "FileVersion", "1.0.90\0"
+            VALUE "ProductName", "TigerVNC Viewer for Win32\0"
+            #endif
+            VALUE "FileVersion", __RCVERSIONSTR
             VALUE "InternalName", "free4/vncviewer/win\0"
-            VALUE "LegalCopyright", "Copyright (C) 1998-2009 [many holders]\0"
+            VALUE "LegalCopyright", "Copyright (C) 1998-2010 [many holders]\0"
             VALUE "LegalTrademarks", "TigerVNC\0"
             VALUE "OriginalFilename", "vncviewer.exe\0"
             VALUE "PrivateBuild", "\0"
-            VALUE "ProductName", "TigerVNC Viewer\0"
-            VALUE "ProductVersion", "1.0.90\0"
+            VALUE "ProductVersion", __VERSIONSTR
             VALUE "SpecialBuild", "\0"
         END
     END
@@ -534,7 +540,7 @@
 // 24
 //
 
-#ifdef _WIN64
+#ifdef WIN64
 IDR_MANIFEST            24      DISCARDABLE     "vncviewer.exe.manifest64"
 #else
 IDR_MANIFEST            24      DISCARDABLE     "vncviewer.exe.manifest"
diff --git a/win/winvnc/CMakeLists.txt b/win/winvnc/CMakeLists.txt
new file mode 100644
index 0000000..811492c
--- /dev/null
+++ b/win/winvnc/CMakeLists.txt
@@ -0,0 +1,33 @@
+include_directories(${CMAKE_BINARY_DIR}/win)
+
+# Disable auto-generated manifests, since we have our own
+if(MSVC)
+  set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO")
+endif()
+
+add_library(wm_hooks SHARED
+  ../wm_hooks/wm_hooks.cxx
+	../wm_hooks/wm_hooks.def
+	../wm_hooks/wm_hooks.rc)
+
+add_executable(winvnc4 WIN32
+  buildTime.cxx
+  ControlPanel.cxx
+  JavaViewer.cxx
+  ManagedListener.cxx
+  QueryConnectDialog.cxx
+  STrayIcon.cxx
+  VNCServerService.cxx
+  VNCServerWin32.cxx
+  winvnc.cxx
+  winvnc.rc)
+
+target_link_libraries(winvnc4 rfb rfb_win32 Xregion network rdr ws2_32.lib)
+
+install(TARGETS winvnc4
+  RUNTIME DESTINATION .
+)
+
+install(TARGETS wm_hooks
+  RUNTIME DESTINATION .
+)
diff --git a/win/winvnc/Makefile.am b/win/winvnc/Makefile.am
index 19f3ada..0ede921 100644
--- a/win/winvnc/Makefile.am
+++ b/win/winvnc/Makefile.am
@@ -20,7 +20,7 @@
 winvnc4_LDFLAGS = -mwindows

 

 EXTRA_DIST = winvnc.rc winvnc.ico connected.ico icon_dis.ico connecte.ico \

-	winvnc4.exe.manifest winvnc.bmp

+	winvnc4.exe.manifest winvnc.bmp CMakeLists.txt

 

 resources.o: winvnc.rc

 	$(WINDRES) $^ -o $@

diff --git a/win/winvnc/winvnc.rc b/win/winvnc/winvnc.rc
index 3cbc0a4..d514c4a 100644
--- a/win/winvnc/winvnc.rc
+++ b/win/winvnc/winvnc.rc
@@ -1,6 +1,7 @@
 //Microsoft Developer Studio generated resource script.
 //
 #include "resource.h"
+#include "resdefs.h"
 
 #define APSTUDIO_READONLY_SYMBOLS
 /////////////////////////////////////////////////////////////////////////////
@@ -58,8 +59,8 @@
 //
 
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION 1,0,90,0
- PRODUCTVERSION 1,0,90,0
+ FILEVERSION __RCVERSION
+ PRODUCTVERSION __RCVERSION
  FILEFLAGSMASK 0x3fL
 #ifdef _DEBUG
  FILEFLAGS 0x1L
@@ -76,15 +77,20 @@
         BEGIN
             VALUE "Comments", "\0"
             VALUE "CompanyName", "TigerVNC Project\0"
+            #ifdef WIN64
+            VALUE "FileDescription", "TigerVNC Server for Win64\0"
+            VALUE "ProductName", "TigerVNC Server for Win64\0"
+            #else
             VALUE "FileDescription", "TigerVNC Server for Win32\0"
-            VALUE "FileVersion", "1.0.90\0"
+            VALUE "ProductName" "TigerVNC Server for Win32\0"
+            #endif
+            VALUE "FileVersion", __RCVERSIONSTR
             VALUE "InternalName", "winvnc\0"
-            VALUE "LegalCopyright", "Copyright (C) 1998-2009 [many holders]\0"
+            VALUE "LegalCopyright", "Copyright (C) 1998-2010 [many holders]\0"
             VALUE "LegalTrademarks", "TigerVNC\0"
             VALUE "OriginalFilename", "winvnc4.exe\0"
             VALUE "PrivateBuild", "\0"
-            VALUE "ProductName", "TigerVNC Server\0"
-            VALUE "ProductVersion", "1.0.90\0"
+            VALUE "ProductVersion", __VERSIONSTR
             VALUE "SpecialBuild", "\0"
         END
     END
@@ -222,7 +228,11 @@
 // 24
 //
 
+#ifdef WIN64
+IDR_MANIFEST            24      DISCARDABLE     "winvnc4.exe.manifest64"
+#else
 IDR_MANIFEST            24      DISCARDABLE     "winvnc4.exe.manifest"
+#endif
 
 /////////////////////////////////////////////////////////////////////////////
 //
diff --git a/win/winvnc/winvnc4.exe.manifest64 b/win/winvnc/winvnc4.exe.manifest64
new file mode 100644
index 0000000..be02243
--- /dev/null
+++ b/win/winvnc/winvnc4.exe.manifest64
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+<assemblyIdentity
+   version="4.0.0.26"
+   processorArchitecture="AMD64"
+   name="TigerVNC.winvnc4.exe"
+   type="win32"
+/>
+<description>.NET control deployment tool</description>
+<dependency>
+   <dependentAssembly>
+     <assemblyIdentity
+       type="win32"
+       name="Microsoft.Windows.Common-Controls"
+       version="6.0.0.0"
+       processorArchitecture="AMD64"
+       publicKeyToken="6595b64144ccf1df"
+       language="*"
+     />
+   </dependentAssembly>
+</dependency>
+</assembly>
diff --git a/win/wm_hooks/wm_hooks.def b/win/wm_hooks/wm_hooks.def
index b9198ab..a70908a 100644
--- a/win/wm_hooks/wm_hooks.def
+++ b/win/wm_hooks/wm_hooks.def
@@ -1,5 +1,5 @@
 LIBRARY      "wm_hooks"
-DESCRIPTION  'Window Message Hooks Dynamic Link Library'
+; DESCRIPTION  'Window Message Hooks Dynamic Link Library'
 
 SECTIONS
 	.WM_Hooks_Shared read write shared
diff --git a/win/wm_hooks/wm_hooks.rc b/win/wm_hooks/wm_hooks.rc
index 5a11fd2..d80c983 100644
--- a/win/wm_hooks/wm_hooks.rc
+++ b/win/wm_hooks/wm_hooks.rc
@@ -1,6 +1,7 @@
 //Microsoft Developer Studio generated resource script.
 //
 #include "resource.h"
+#include "resdefs.h"
 
 #define APSTUDIO_READONLY_SYMBOLS
 /////////////////////////////////////////////////////////////////////////////
@@ -54,8 +55,8 @@
 //
 
 VS_VERSION_INFO VERSIONINFO
- FILEVERSION 4,1,0,0
- PRODUCTVERSION 4,1,0,0
+ FILEVERSION __RCVERSION
+ PRODUCTVERSION __RCVERSION
  FILEFLAGSMASK 0x3fL
 #ifdef _DEBUG
  FILEFLAGS 0x1L
@@ -72,15 +73,20 @@
         BEGIN
             VALUE "Comments", "\0"
             VALUE "CompanyName", "Constantin Kaplinsky\0"
+            #ifdef WIN64
+            VALUE "FileDescription", "TigerVNC Server Hooking DLL for Win64\0"
+            VALUE "ProductName", "TigerVNC Server Hooking DLL for Win64\0"
+            #else
             VALUE "FileDescription", "TigerVNC Server Hooking DLL for Win32\0"
-            VALUE "FileVersion", "4.1\0"
+            VALUE "ProductName", "TigerVNC Server Hooking DLL for Win32\0"
+            #endif
+            VALUE "FileVersion", __RCVERSIONSTR
             VALUE "InternalName", "\0"
             VALUE "LegalCopyright", "Copyright (C) 1998-2005 [many holders]\0"
             VALUE "LegalTrademarks", "TigerVNC\0"
             VALUE "OriginalFilename", "wm_hooks.dll\0"
             VALUE "PrivateBuild", "\0"
-            VALUE "ProductName", "TigerVNC Server\0"
-            VALUE "ProductVersion", "4.1\0"
+            VALUE "ProductVersion", __VERSIONSTR
             VALUE "SpecialBuild", "\0"
         END
     END