From 0d0b10c55264b4fde7255fb113e18e28b2094200 Mon Sep 17 00:00:00 2001
From: dizzy <dizone@gmail.com>
Date: Sun, 19 Aug 2007 11:51:53 +0000
Subject: [PATCH] First version of the cmake build system. Seems to be more
 portable and easy to work with in non-POSIX enviroments than autotools. Still
 need to add installation support for the targets (so you can use "make
 install") and using sed to generate the config files. Usage: -
 autogen/configure become: "cmake /path/to/pvpgnsource"; only tested in the
 current directory so far, so "cmake ."; out of source builds should work too
 in theory - make becomes: make (suprise!) Will update docs with more
 instructions if we will use it after all.

---
 pvpgn/CMakeLists.txt                          |  14 ++
 pvpgn/ConfigureChecks.cmake                   | 142 ++++++++++++++++++
 .../cmake/Modules/CheckIncludeFilesCXX.cmake  |  59 ++++++++
 pvpgn/cmake/Modules/CheckMkdirArgs.cmake      |  58 +++++++
 pvpgn/cmake/Modules/CheckTypeSizeCXX.cmake    |  68 +++++++++
 pvpgn/cmake/Modules/CheckTypeSizeCXX.cxx.in   |  28 ++++
 pvpgn/cmake/Modules/FindMySQL.cmake           |  50 ++++++
 pvpgn/cmake/Modules/FindSQLite3.cmake         |  48 ++++++
 pvpgn/src/CMakeLists.txt                      |  57 +++++++
 pvpgn/src/bnetd/CMakeLists.txt                |  16 ++
 pvpgn/src/bniutils/CMakeLists.txt             |  14 ++
 pvpgn/src/bnpass/CMakeLists.txt               |   5 +
 pvpgn/src/bnpcap/CMakeLists.txt               |   2 +
 pvpgn/src/bntrackd/CMakeLists.txt             |   2 +
 pvpgn/src/client/CMakeLists.txt               |  11 ++
 pvpgn/src/common/CMakeLists.txt               |   7 +
 pvpgn/src/compat/CMakeLists.txt               |   3 +
 pvpgn/src/d2cs/CMakeLists.txt                 |   5 +
 pvpgn/src/d2dbs/CMakeLists.txt                |   3 +
 pvpgn/src/tinycdb/CMakeLists.txt              |   8 +
 pvpgn/src/win32/CMakeLists.txt                |   1 +
 21 files changed, 601 insertions(+)
 create mode 100644 pvpgn/CMakeLists.txt
 create mode 100644 pvpgn/ConfigureChecks.cmake
 create mode 100644 pvpgn/cmake/Modules/CheckIncludeFilesCXX.cmake
 create mode 100644 pvpgn/cmake/Modules/CheckMkdirArgs.cmake
 create mode 100644 pvpgn/cmake/Modules/CheckTypeSizeCXX.cmake
 create mode 100644 pvpgn/cmake/Modules/CheckTypeSizeCXX.cxx.in
 create mode 100644 pvpgn/cmake/Modules/FindMySQL.cmake
 create mode 100644 pvpgn/cmake/Modules/FindSQLite3.cmake
 create mode 100644 pvpgn/src/CMakeLists.txt
 create mode 100644 pvpgn/src/bnetd/CMakeLists.txt
 create mode 100644 pvpgn/src/bniutils/CMakeLists.txt
 create mode 100644 pvpgn/src/bnpass/CMakeLists.txt
 create mode 100644 pvpgn/src/bnpcap/CMakeLists.txt
 create mode 100644 pvpgn/src/bntrackd/CMakeLists.txt
 create mode 100644 pvpgn/src/client/CMakeLists.txt
 create mode 100644 pvpgn/src/common/CMakeLists.txt
 create mode 100644 pvpgn/src/compat/CMakeLists.txt
 create mode 100644 pvpgn/src/d2cs/CMakeLists.txt
 create mode 100644 pvpgn/src/d2dbs/CMakeLists.txt
 create mode 100644 pvpgn/src/tinycdb/CMakeLists.txt
 create mode 100644 pvpgn/src/win32/CMakeLists.txt

diff --git a/pvpgn/CMakeLists.txt b/pvpgn/CMakeLists.txt
new file mode 100644
index 0000000..03e2d3a
--- /dev/null
+++ b/pvpgn/CMakeLists.txt
@@ -0,0 +1,14 @@
+project(pvpgn)
+
+option(WITH_BNETD "compile the bnetd target" ON)
+option(WITH_D2CS "compile the d2cs target" ON)
+option(WITH_D2DBS "compile the d2dbs target" ON)
+option(WITH_ANSI "enforce strict ISO C++ conforming" ON)
+
+#storage backends flags
+option(WITH_MYSQL "include MySQL user accounts support" OFF)
+option(WITH_SQLITE3 "include SQLite3 user accounts support" OFF)
+
+include(ConfigureChecks.cmake)
+
+add_subdirectory(src)
diff --git a/pvpgn/ConfigureChecks.cmake b/pvpgn/ConfigureChecks.cmake
new file mode 100644
index 0000000..875e211
--- /dev/null
+++ b/pvpgn/ConfigureChecks.cmake
@@ -0,0 +1,142 @@
+set(CMAKE_MODULE_PATH
+  ${CMAKE_SOURCE_DIR}/cmake/Modules
+)
+
+include(CheckIncludeFileCXX)
+include(CheckIncludeFilesCXX)
+include(CheckFunctionExists)
+include(CheckLibraryExists)
+include(CheckTypeSizeCXX)
+include(CheckCXXCompilerFlag)
+
+check_include_files_cxx("cassert;cctype;cerrno;cmath;climits;csignal;cstdarg;cstddef;cstdio;cstdlib;cstring;ctime;deque;exception;fstream;iomanip;iostream;limits;list;map;memory;sstream;stdexcept;string;utility;vector" HAVE_STD_HEADERS)
+if(NOT HAVE_STD_HEADERS)
+    MESSAGE(FATAL_ERROR "Standard C90/C++98 header missing, you need a fully standard compliant compiler/enviroment.")
+endif(NOT HAVE_STD_HEADERS)
+
+check_include_file_cxx(fcntl.h HAVE_FCNTL_H)
+check_include_file_cxx(sys/time.h HAVE_SYS_TIME_H)
+check_include_file_cxx(sys/select.h HAVE_SYS_SELECT_H)
+check_include_file_cxx(unistd.h HAVE_UNISTD_H)
+check_include_file_cxx(sys/utsname.h HAVE_SYS_UTSNAME_H)
+check_include_file_cxx(sys/timeb.h HAVE_SYS_TIMEB_H)
+check_include_file_cxx(sys/socket.h HAVE_SYS_SOCKET_H)
+check_include_file_cxx(sys/param.h HAVE_SYS_PARAM_H)
+check_include_file_cxx(netinet/in.h HAVE_NETINET_IN_H)
+check_include_file_cxx(arpa/inet.h HAVE_ARPA_INET_H)
+check_include_file_cxx(netdb.h HAVE_NETDB_H)
+check_include_file_cxx(termios.h HAVE_TERMIOS_H)
+check_include_file_cxx(sys/types.h HAVE_SYS_TYPES_H)
+check_include_file_cxx(sys/wait.h HAVE_SYS_WAIT_H)
+check_include_file_cxx(sys/ioctl.h HAVE_SYS_IOCTL_H)
+check_include_file_cxx(stdint.h HAVE_STDINT_H)
+check_include_file_cxx(sys/file.h HAVE_SYS_FILE_H)
+check_include_file_cxx(poll.h HAVE_POLL_H)
+check_include_file_cxx(sys/poll.h HAVE_SYS_POLL_H)
+check_include_file_cxx(sys/stropts.h HAVE_SYS_STROPTS_H)
+check_include_file_cxx(sys/stat.h HAVE_SYS_STAT_H)
+check_include_file_cxx(pwd.h HAVE_PWD_H)
+check_include_file_cxx(grp.h HAVE_GRP_H)
+check_include_file_cxx(dir.h HAVE_DIR_H)
+check_include_file_cxx(dirent.h HAVE_DIRENT_H)
+check_include_file_cxx(ndir.h HAVE_NDIR_H)
+check_include_file_cxx(sys/ndir.h HAVE_SYS_NDIR_H)
+check_include_file_cxx(sys/dir.h HAVE_SYS_DIR_H)
+check_include_file_cxx(direct.h HAVE_DIRECT_H)
+check_include_file_cxx(sys/mman.h HAVE_SYS_MMAN_H)
+check_include_file_cxx(sys/event.h HAVE_SYS_EVENT_H)
+check_include_file_cxx(sys/epoll.h HAVE_SYS_EPOLL_H)
+check_include_file_cxx(sys/resource.h HAVE_SYS_RESOURCE_H)
+check_include_file_cxx(sqlite3.h HAVE_SQLITE3_H)
+check_include_file_cxx(pcap.h HAVE_PCAP_H)
+
+check_type_size_cxx("unsigned char" SIZEOF_UNSIGNED_CHAR)
+check_type_size_cxx("unsigned short" SIZEOF_UNSIGNED_SHORT)
+check_type_size_cxx("unsigned int" SIZEOF_UNSIGNED_INT)
+check_type_size_cxx("unsigned long" SIZEOF_UNSIGNED_LONG)
+check_type_size_cxx("unsigned long long" SIZEOF_UNSIGNED_LONG_LONG)
+check_type_size_cxx("signed char" SIZEOF_SIGNED_CHAR)
+check_type_size_cxx("signed short" SIZEOF_SIGNED_SHORT)
+check_type_size_cxx("signed int" SIZEOF_SIGNED_INT)
+check_type_size_cxx("signed long" SIZEOF_SIGNED_LONG)
+check_type_size_cxx("signed long long" SIZEOF_SIGNED_LONG_LONG)
+
+check_function_exists(mmap HAVE_MMAP)
+check_function_exists(gethostname HAVE_GETHOSTNAME)
+check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
+check_function_exists(select HAVE_SELECT)
+check_function_exists(socket HAVE_SOCKET)
+check_function_exists(strdup HAVE_STRDUP)
+check_function_exists(strtoul HAVE_STRTOUL)
+check_function_exists(inet_aton HAVE_INET_ATON)
+check_function_exists(inet_ntoa HAVE_INET_NTOA)
+check_function_exists(uname HAVE_UNAME)
+check_function_exists(recv HAVE_RECV)
+check_function_exists(send HAVE_SEND)
+check_function_exists(recvfrom HAVE_RECVFROM)
+check_function_exists(sendto HAVE_SENDTO)
+check_function_exists(uname HAVE_UNAME)
+check_function_exists(fork HAVE_FORK)
+check_function_exists(getpid HAVE_GETPID)
+check_function_exists(sigaction HAVE_SIGACTION)
+check_function_exists(sigprocmask HAVE_SIGPROCMASK)
+check_function_exists(sigaddset HAVE_SIGADDSET)
+check_function_exists(setpgid HAVE_SETPGID)
+check_function_exists(ftime HAVE_FTIME)
+check_function_exists(strcasecmp HAVE_STRCASECMP)
+check_function_exists(strncasecmp HAVE_STRNCASECMP)
+check_function_exists(stricmp HAVE_STRICMP)
+check_function_exists(strnicmp HAVE_STRNICMP)
+check_function_exists(chdir HAVE_CHDIR)
+check_function_exists(difftime HAVE_DIFFTIME)
+check_function_exists(strchr HAVE_STRCHR)
+check_function_exists(strrchr HAVE_STRRCHR)
+check_function_exists(index HAVE_INDEX)
+check_function_exists(rindex HAVE_RINDEX)
+check_function_exists(wait HAVE_WAIT)
+check_function_exists(waitpid HAVE_WAITPID)
+check_function_exists(pipe HAVE_PIPE)
+check_function_exists(getenv HAVE_GETENV)
+check_function_exists(ioctl HAVE_IOCTL)
+check_function_exists(setsid HAVE_SETSID)
+check_function_exists(poll HAVE_POLL)
+check_function_exists(gethostbyname HAVE_GETHOSTBYNAME)
+check_function_exists(getservbyname HAVE_GETSERVBYNAME)
+check_function_exists(getlogin HAVE_GETLOGIN)
+check_function_exists(getpwnam HAVE_GETPWNAME)
+check_function_exists(getgrnam HAVE_GETGRNAM)
+check_function_exists(getuid HAVE_GETUID)
+check_function_exists(getgid HAVE_GETGID)
+check_function_exists(setuid HAVE_SETUID)
+check_function_exists(mkdir HAVE_MKDIR)
+check_function_exists(_mkdir HAVE__MKDIR)
+check_function_exists(strsep HAVE_STRSEP)
+check_function_exists(getopt HAVE_GETOPT)
+check_function_exists(kqueue HAVE_KQUEUE)
+check_function_exists(setitimer HAVE_SETITIMER)
+check_function_exists(epoll_create HAVE_EPOLL_CREATE)
+check_function_exists(getrlimit HAVE_GETRLIMIT)
+check_function_exists(vsnprintf HAVE_VSNPRINTF)
+check_function_exists(_vsnprintf HAVE__VSNPRINTF)
+check_function_exists(snprintf HAVE_SNPRINTF)
+check_function_exists(_snprintf HAVE__SNPRINTF)
+check_function_exists(setpgrp HAVE_SETPGRP)
+
+find_package(ZLIB REQUIRED)
+check_library_exists(pcap pcap_open_offline "" HAVE_LIBPCAP)
+
+#storage module checks
+if(WITH_MYSQL)
+    find_package(MySQL REQUIRED)
+endif(WITH_MYSQL)
+if(WITH_SQLITE3)
+    find_package(SQLite3 REQUIRED)
+endif(WITH_SQLITE3)
+
+configure_file(config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
+
+check_cxx_compiler_flag("-Wall" WITH_FLAG_WALL)
+
+if(WITH_ANSI)
+    check_cxx_compiler_flag("-pedantic -ansi" WITH_FLAG_ANSIPEDANTIC)
+endif(WITH_ANSI)
diff --git a/pvpgn/cmake/Modules/CheckIncludeFilesCXX.cmake b/pvpgn/cmake/Modules/CheckIncludeFilesCXX.cmake
new file mode 100644
index 0000000..68fa117
--- /dev/null
+++ b/pvpgn/cmake/Modules/CheckIncludeFilesCXX.cmake
@@ -0,0 +1,59 @@
+# - Check if the files can be included
+#
+# CHECK_INCLUDE_FILES_CXX(INCLUDE VARIABLE)
+#
+#  INCLUDE  - list of files to include
+#  VARIABLE - variable to return result
+#
+# The following variables may be set before calling this macro to
+# modify the way the check is run:
+#
+#  CMAKE_REQUIRED_FLAGS = string of compile command line flags
+#  CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+#  CMAKE_REQUIRED_INCLUDES = list of include directories
+
+MACRO(CHECK_INCLUDE_FILES_CXX INCLUDE VARIABLE)
+  IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
+    SET(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n")
+    IF(CMAKE_REQUIRED_INCLUDES)
+      SET(CHECK_INCLUDE_FILES_CXX_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
+    ELSE(CMAKE_REQUIRED_INCLUDES)
+      SET(CHECK_INCLUDE_FILES_CXX_INCLUDE_DIRS)
+    ENDIF(CMAKE_REQUIRED_INCLUDES)
+    SET(CHECK_INCLUDE_FILES_CXX_CONTENT "/* */\n")
+    SET(MACRO_CHECK_INCLUDE_FILES_CXX_FLAGS ${CMAKE_REQUIRED_FLAGS})
+    FOREACH(FILE ${INCLUDE})
+      SET(CMAKE_CONFIGURABLE_FILE_CONTENT
+        "${CMAKE_CONFIGURABLE_FILE_CONTENT}#include <${FILE}>\n")
+    ENDFOREACH(FILE)
+    SET(CMAKE_CONFIGURABLE_FILE_CONTENT
+      "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n\nint main(){return 0;}\n")
+    CONFIGURE_FILE("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
+      "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFiles.cxx" @ONLY IMMEDIATE)
+
+    MESSAGE(STATUS "Looking for include files ${VARIABLE}")
+    TRY_COMPILE(${VARIABLE}
+      ${CMAKE_BINARY_DIR}
+      ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFiles.cxx
+      COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+      CMAKE_FLAGS 
+      -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILES_CXX_FLAGS}
+      "${CHECK_INCLUDE_FILES_CXX_INCLUDE_DIRS}"
+      OUTPUT_VARIABLE OUTPUT)
+    IF(${VARIABLE})
+      MESSAGE(STATUS "Looking for include files ${VARIABLE} - found")
+      SET(${VARIABLE} 1 CACHE INTERNAL "Have include ${VARIABLE}")
+      FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log 
+        "Determining if files ${INCLUDE} "
+        "exist passed with the following output:\n"
+        "${OUTPUT}\n\n")
+    ELSE(${VARIABLE})
+      MESSAGE(STATUS "Looking for include files ${VARIABLE} - not found.")
+      SET(${VARIABLE} "" CACHE INTERNAL "Have includes ${VARIABLE}")
+      FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log 
+        "Determining if files ${INCLUDE} "
+        "exist failed with the following output:\n"
+        "${OUTPUT}\nSource:\n${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
+    ENDIF(${VARIABLE})
+  ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
+ENDMACRO(CHECK_INCLUDE_FILES_CXX)
diff --git a/pvpgn/cmake/Modules/CheckMkdirArgs.cmake b/pvpgn/cmake/Modules/CheckMkdirArgs.cmake
new file mode 100644
index 0000000..5866cb6
--- /dev/null
+++ b/pvpgn/cmake/Modules/CheckMkdirArgs.cmake
@@ -0,0 +1,58 @@
+# - Check if the files can be included
+#
+# CHECK_MKDIR_ARGS(VARIABLE)
+#
+#  VARIABLE - variable to return if mkdir/_mkdir need a single argument
+#
+# The following variables may be set before calling this macro to
+# modify the way the check is run:
+#
+#  CMAKE_REQUIRED_FLAGS = string of compile command line flags
+#  CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+#  CMAKE_REQUIRED_INCLUDES = list of include directories
+
+MACRO(CHECK_MKDIR_ARGS INCLUDE VARIABLE)
+  IF("${VARIABLE}" MATCHES "^${VARIABLE}$")
+    SET(CMAKE_CONFIGURABLE_FILE_CONTENT "/* */\n")
+    IF(CMAKE_REQUIRED_INCLUDES)
+      SET(CHECK_INCLUDE_FILES_CXX_INCLUDE_DIRS "-DINCLUDE_DIRECTORIES=${CMAKE_REQUIRED_INCLUDES}")
+    ELSE(CMAKE_REQUIRED_INCLUDES)
+      SET(CHECK_INCLUDE_FILES_CXX_INCLUDE_DIRS)
+    ENDIF(CMAKE_REQUIRED_INCLUDES)
+    SET(CHECK_INCLUDE_FILES_CXX_CONTENT "/* */\n")
+    SET(MACRO_CHECK_INCLUDE_FILES_CXX_FLAGS ${CMAKE_REQUIRED_FLAGS})
+    FOREACH(FILE ${INCLUDE})
+      SET(CMAKE_CONFIGURABLE_FILE_CONTENT
+        "${CMAKE_CONFIGURABLE_FILE_CONTENT}#include <${FILE}>\n")
+    ENDFOREACH(FILE)
+    SET(CMAKE_CONFIGURABLE_FILE_CONTENT
+      "${CMAKE_CONFIGURABLE_FILE_CONTENT}\n\nint main(){return 0;}\n")
+    CONFIGURE_FILE("${CMAKE_ROOT}/Modules/CMakeConfigurableFile.in"
+      "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFiles.cxx" @ONLY IMMEDIATE)
+
+    MESSAGE(STATUS "Looking for include files ${VARIABLE}")
+    TRY_COMPILE(${VARIABLE}
+      ${CMAKE_BINARY_DIR}
+      ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckIncludeFiles.cxx
+      COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+      CMAKE_FLAGS 
+      -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_INCLUDE_FILES_CXX_FLAGS}
+      "${CHECK_INCLUDE_FILES_CXX_INCLUDE_DIRS}"
+      OUTPUT_VARIABLE OUTPUT)
+    IF(${VARIABLE})
+      MESSAGE(STATUS "Looking for include files ${VARIABLE} - found")
+      SET(${VARIABLE} 1 CACHE INTERNAL "Have include ${VARIABLE}")
+      FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log 
+        "Determining if files ${INCLUDE} "
+        "exist passed with the following output:\n"
+        "${OUTPUT}\n\n")
+    ELSE(${VARIABLE})
+      MESSAGE(STATUS "Looking for include files ${VARIABLE} - not found.")
+      SET(${VARIABLE} "" CACHE INTERNAL "Have includes ${VARIABLE}")
+      FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log 
+        "Determining if files ${INCLUDE} "
+        "exist failed with the following output:\n"
+        "${OUTPUT}\nSource:\n${CMAKE_CONFIGURABLE_FILE_CONTENT}\n")
+    ENDIF(${VARIABLE})
+  ENDIF("${VARIABLE}" MATCHES "^${VARIABLE}$")
+ENDMACRO(CHECK_INCLUDE_FILES_CXX)
diff --git a/pvpgn/cmake/Modules/CheckTypeSizeCXX.cmake b/pvpgn/cmake/Modules/CheckTypeSizeCXX.cmake
new file mode 100644
index 0000000..d731ebb
--- /dev/null
+++ b/pvpgn/cmake/Modules/CheckTypeSizeCXX.cmake
@@ -0,0 +1,68 @@
+# - Check sizeof a type
+#  CHECK_TYPE_SIZE_CXX(TYPE VARIABLE)
+# Check if the type exists and determine size of type.  if the type
+# exists, the size will be stored to the variable.
+#  VARIABLE - variable to store size if the type exists.
+#  HAVE_${VARIABLE} - does the variable exists or not
+# The following variables may be set before calling this macro to
+# modify the way the check is run:
+#
+#  CMAKE_REQUIRED_FLAGS = string of compile command line flags
+#  CMAKE_REQUIRED_DEFINITIONS = list of macros to define (-DFOO=bar)
+#  CMAKE_REQUIRED_INCLUDES = list of include directories
+#  CMAKE_REQUIRED_LIBRARIES = list of libraries to link
+
+MACRO(CHECK_TYPE_SIZE_CXX TYPE VARIABLE)
+  SET(CMAKE_ALLOW_UNKNOWN_VARIABLE_READ_ACCESS 1)
+  IF("HAVE_${VARIABLE}" MATCHES "^HAVE_${VARIABLE}$")
+    SET(CHECK_TYPE_SIZE_CXX_TYPE "${TYPE}")
+    SET(MACRO_CHECK_TYPE_CXX_SIZE_FLAGS 
+      "${CMAKE_REQUIRED_FLAGS}")
+    FOREACH(def HAVE_SYS_TYPES_H HAVE_STDINT_H HAVE_STDDEF_H)
+      IF("${def}")
+        SET(MACRO_CHECK_TYPE_SIZE_CXX_FLAGS 
+          "${MACRO_CHECK_TYPE_SIZE_CXX_FLAGS} -D${def}")
+      ENDIF("${def}")
+    ENDFOREACH(def)
+    SET(CHECK_TYPE_SIZE_CXX_PREINCLUDE)
+    SET(CHECK_TYPE_SIZE_CXX_PREMAIN)
+    FOREACH(def ${CMAKE_EXTRA_INCLUDE_FILES})
+      SET(CHECK_TYPE_SIZE_CXX_PREMAIN "${CHECK_TYPE_SIZE_CXX_PREMAIN}#include \"${def}\"\n")
+    ENDFOREACH(def)
+    CONFIGURE_FILE("${CMAKE_MODULE_PATH}/CheckTypeSizeCXX.cxx.in"
+      "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckTypeSizeCXX.cxx" IMMEDIATE @ONLY)
+    FILE(READ "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckTypeSizeCXX.cxx"
+      CHECK_TYPE_SIZE_CXX_FILE_CONTENT)
+    MESSAGE(STATUS "Check size of ${TYPE}")
+    IF(CMAKE_REQUIRED_LIBRARIES)
+      SET(CHECK_TYPE_SIZE_CXX_ADD_LIBRARIES 
+        "-DLINK_LIBRARIES:STRING=${CMAKE_REQUIRED_LIBRARIES}")
+    ELSE(CMAKE_REQUIRED_LIBRARIES)
+      SET(CHECK_TYPE_SIZE_CXX_ADD_LIBRARIES)
+    ENDIF(CMAKE_REQUIRED_LIBRARIES)
+    IF(CMAKE_REQUIRED_INCLUDES)
+      SET(CHECK_TYPE_SIZE_CXX_ADD_INCLUDES
+        "-DINCLUDE_DIRECTORIES:STRING=${CMAKE_REQUIRED_INCLUDES}")
+    ELSE(CMAKE_REQUIRED_INCLUDES)
+      SET(CHECK_TYPE_SIZE_CXX_ADD_INCLUDES)
+    ENDIF(CMAKE_REQUIRED_INCLUDES)
+    TRY_RUN(${VARIABLE} HAVE_${VARIABLE}
+      ${CMAKE_BINARY_DIR}
+      "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/CheckTypeSizeCXX.cxx"
+      COMPILE_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS}
+      CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${MACRO_CHECK_TYPE_SIZE_CXX_FLAGS}
+      "${CHECK_TYPE_SIZE_CXX_ADD_LIBRARIES}"
+      "${CHECK_TYPE_SIZE_CXX_ADD_INCLUDES}"
+      OUTPUT_VARIABLE OUTPUT)
+    IF(HAVE_${VARIABLE})
+      MESSAGE(STATUS "Check size of ${TYPE} - done")
+      FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log 
+        "Determining size of ${TYPE} passed with the following output:\n${OUTPUT}\n\n")
+    ELSE(HAVE_${VARIABLE})
+      MESSAGE(STATUS "Check size of ${TYPE} - failed")
+      FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log 
+        "Determining size of ${TYPE} failed with the following output:\n${OUTPUT}\nCheckTypeSizeCXX.cxx:\n${CHECK_TYPE_SIZE_CXX_FILE_CONTENT}\n\n")
+    ENDIF(HAVE_${VARIABLE})
+  ENDIF("HAVE_${VARIABLE}" MATCHES "^HAVE_${VARIABLE}$")
+  SET(CMAKE_ALLOW_UNKNOWN_VARIABLE_READ_ACCESS )
+ENDMACRO(CHECK_TYPE_SIZE_CXX)
diff --git a/pvpgn/cmake/Modules/CheckTypeSizeCXX.cxx.in b/pvpgn/cmake/Modules/CheckTypeSizeCXX.cxx.in
new file mode 100644
index 0000000..32081a8
--- /dev/null
+++ b/pvpgn/cmake/Modules/CheckTypeSizeCXX.cxx.in
@@ -0,0 +1,28 @@
+#cmakedefine CHECK_TYPE_SIZE_CXX_TYPE @CHECK_TYPE_SIZE_CXX_TYPE@
+#ifdef CHECK_TYPE_SIZE_CXX_TYPE
+
+@CHECK_TYPE_SIZE_CXX_PREINCLUDE@
+#ifdef HAVE_SYS_TYPES_H
+#  include <sys/types.h>
+#endif /* HAVE_SYS_TYPES_H */
+
+#ifdef HAVE_STDINT_H
+#  include <stdint.h>
+#endif /* HAVE_STDINT_H */
+
+#ifdef HAVE_STDDEF_H
+#  include <stddef.h>
+#endif /* HAVE_STDDEF_H */
+
+@CHECK_TYPE_SIZE_CXX_PREMAIN@
+
+int main(int ac, char*av[]){
+  if(ac > 1000){return *av[0];}
+  return sizeof(CHECK_TYPE_SIZE_CXX_TYPE);
+}
+
+#else  /* CHECK_TYPE_SIZE_CXX_TYPE */
+
+#  error "CHECK_TYPE_SIZE_CXX_TYPE has to specify the type"
+
+#endif /* CHECK_TYPE_SIZE_CXX_TYPE */
diff --git a/pvpgn/cmake/Modules/FindMySQL.cmake b/pvpgn/cmake/Modules/FindMySQL.cmake
new file mode 100644
index 0000000..2a14159
--- /dev/null
+++ b/pvpgn/cmake/Modules/FindMySQL.cmake
@@ -0,0 +1,50 @@
+# - Find mysqlclient
+# Find the native MySQL includes and library
+#
+#  MYSQL_INCLUDE_DIR - where to find mysql.h, etc.
+#  MYSQL_LIBRARIES   - List of libraries when using MySQL.
+#  MYSQL_FOUND       - True if MySQL found.
+
+IF (MYSQL_INCLUDE_DIR)
+  # Already in cache, be silent
+  SET(MYSQL_FIND_QUIETLY TRUE)
+ENDIF (MYSQL_INCLUDE_DIR)
+
+FIND_PATH(MYSQL_INCLUDE_DIR mysql.h
+  /usr/local/mysql/include
+  /usr/local/include/mysql
+  /usr/local/include
+  /usr/include/mysql
+  /usr/include
+  /usr/mysql/include
+)
+
+SET(MYSQL_NAMES mysqlclient mysqlclient_r)
+FIND_LIBRARY(MYSQL_LIBRARY
+  NAMES ${MYSQL_NAMES}
+  PATHS /usr/local/mysql/lib /usr/local/lib /usr/lib
+)
+
+IF (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY)
+  SET(MYSQL_FOUND TRUE)
+  SET( MYSQL_LIBRARIES ${MYSQL_LIBRARY} )
+ELSE (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY)
+  SET(MYSQL_FOUND FALSE)
+  SET( MYSQL_LIBRARIES )
+ENDIF (MYSQL_INCLUDE_DIR AND MYSQL_LIBRARY)
+
+IF (MYSQL_FOUND)
+  IF (NOT MYSQL_FIND_QUIETLY)
+    MESSAGE(STATUS "Found MySQL: ${MYSQL_LIBRARY}")
+  ENDIF (NOT MYSQL_FIND_QUIETLY)
+ELSE (MYSQL_FOUND)
+  IF (MYSQL_FIND_REQUIRED)
+    MESSAGE(STATUS "Looked for MySQL libraries named ${MYSQL_NAMES}.")
+    MESSAGE(FATAL_ERROR "Could NOT find MySQL library")
+  ENDIF (MYSQL_FIND_REQUIRED)
+ENDIF (MYSQL_FOUND)
+
+MARK_AS_ADVANCED(
+  MYSQL_LIBRARY
+  MYSQL_INCLUDE_DIR
+  )
diff --git a/pvpgn/cmake/Modules/FindSQLite3.cmake b/pvpgn/cmake/Modules/FindSQLite3.cmake
new file mode 100644
index 0000000..1d772c9
--- /dev/null
+++ b/pvpgn/cmake/Modules/FindSQLite3.cmake
@@ -0,0 +1,48 @@
+# - Find sqlite3
+# Find the native SQLite3 includes and library
+#
+#  SQLITE3_INCLUDE_DIR - where to find sqlite3.h
+#  SQLITE3_LIBRARIES   - List of libraries when using SQLite3.
+#  SQLITE3_FOUND       - True if SQLite3 found.
+
+IF (SQLITE3_INCLUDE_DIR)
+  # Already in cache, be silent
+  SET(SQLITE3_FIND_QUIETLY TRUE)
+ENDIF (SQLITE3_INCLUDE_DIR)
+
+FIND_PATH(SQLITE3_INCLUDE_DIR sqlite3.h
+  /usr/local/include/sqlite3
+  /usr/local/include
+  /usr/include/sqlite3
+  /usr/include
+)
+
+SET(SQLITE3_NAMES sqlite3)
+FIND_LIBRARY(SQLITE3_LIBRARY
+  NAMES ${SQLITE3_NAMES}
+  PATHS /usr/local/lib /usr/lib
+)
+
+IF (SQLITE3_INCLUDE_DIR AND SQLITE3_LIBRARY)
+  SET(SQLITE3_FOUND TRUE)
+  SET( SQLITE3_LIBRARIES ${SQLITE3_LIBRARY} )
+ELSE (SQLITE3_INCLUDE_DIR AND SQLITE3_LIBRARY)
+  SET(SQLITE3_FOUND FALSE)
+  SET( SQLITE3_LIBRARIES )
+ENDIF (SQLITE3_INCLUDE_DIR AND SQLITE3_LIBRARY)
+
+IF (SQLITE3_FOUND)
+  IF (NOT SQLITE3_FIND_QUIETLY)
+    MESSAGE(STATUS "Found SQLite3: ${SQLITE3_LIBRARY}")
+  ENDIF (NOT SQLITE3_FIND_QUIETLY)
+ELSE (SQLITE3_FOUND)
+  IF (SQLITE3_FIND_REQUIRED)
+    MESSAGE(STATUS "Looked for SQLite3 libraries named ${SQLITE3_NAMES}.")
+    MESSAGE(FATAL_ERROR "Could NOT find SQLite3 library")
+  ENDIF (SQLITE3_FIND_REQUIRED)
+ENDIF (SQLITE3_FOUND)
+
+MARK_AS_ADVANCED(
+  SQLITE3_LIBRARY
+  SQLITE3_INCLUDE_DIR
+  )
diff --git a/pvpgn/src/CMakeLists.txt b/pvpgn/src/CMakeLists.txt
new file mode 100644
index 0000000..5f50f20
--- /dev/null
+++ b/pvpgn/src/CMakeLists.txt
@@ -0,0 +1,57 @@
+#first setup the includes and link paths
+include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/src)
+
+if(MYSQL_INCLUDE_DIR)
+    include_directories(${MYSQL_INCLUDE_DIR})
+endif(MYSQL_INCLUDE_DIR)
+if(SQLITE3_INCLUDE_DIR)
+    include_directories(${SQLITE3_INCLUDE_DIR})
+endif(SQLITE3_INCLUDE_DIR)
+
+link_directories(${CMAKE_BINARY_DIR}/src/common 
+${CMAKE_BINARY_DIR}/src/compat
+${CMAKE_BINARY_DIR}/src/tinycdb
+${CMAKE_BINARY_DIR}/src/win32)
+
+#this is needed to be compatible with existent code
+add_definitions("-DHAVE_CONFIG_H")
+
+if(WITH_FLAG_WALL)
+    add_definitions("-Wall")
+endif(WITH_FLAG_WALL)
+
+if(WITH_FLAG_ANSIPEDANTIC)
+    add_definitions("-pedantic -ansi")
+endif(WITH_FLAG_ANSIPEDANTIC)
+
+if(MYSQL_FOUND)
+    add_definitions("-DWITH_SQL_MYSQL")
+endif(MYSQL_FOUND)
+if(SQLITE3_FOUND)
+    add_definitions("-DWITH_SQL_SQLITE3")
+endif(SQLITE3_FOUND)
+
+add_subdirectory(compat)
+add_subdirectory(common)
+add_subdirectory(tinycdb)
+add_subdirectory(win32)
+add_subdirectory(bntrackd)
+add_subdirectory(client)
+add_subdirectory(bniutils)
+add_subdirectory(bnpass)
+
+if(WITH_BNETD)
+    add_subdirectory(bnetd)
+endif(WITH_BNETD)
+
+if(WITH_D2CS)
+    add_subdirectory(d2cs)
+endif(WITH_D2CS)
+
+if(WITH_D2DBS)
+    add_subdirectory(d2dbs)
+endif(WITH_D2DBS)
+
+if(HAVE_PCAP_H AND HAVE_LIBPCAP)
+    add_subdirectory(bnpcap)
+endif(HAVE_PCAP_H AND HAVE_LIBPCAP)
diff --git a/pvpgn/src/bnetd/CMakeLists.txt b/pvpgn/src/bnetd/CMakeLists.txt
new file mode 100644
index 0000000..6fc51c8
--- /dev/null
+++ b/pvpgn/src/bnetd/CMakeLists.txt
@@ -0,0 +1,16 @@
+add_executable(bnetd account.cpp account_wrap.cpp adbanner.cpp alias_command.cpp anongame.cpp 
+anongame_gameresult.cpp anongame_infos.cpp anongame_maplists.cpp attrgroup.cpp 
+attrlayer.cpp autoupdate.cpp channel.cpp channel_conv.cpp character.cpp clan.cpp 
+cmdline.cpp command.cpp command_groups.cpp connection.cpp file.cpp file_cdb.cpp 
+file_plain.cpp friends.cpp game.cpp game_conv.cpp handle_anongame.cpp 
+handle_bnet.cpp handle_bot.cpp handle_d2cs.cpp handle_file.cpp handle_init.cpp 
+handle_irc.cpp handle_telnet.cpp handle_udp.cpp helpfile.cpp ipban.cpp irc.cpp 
+ladder.cpp ladder_calc.cpp mail.cpp main.cpp message.cpp news.cpp 
+output.cpp prefs.cpp realm.cpp runprog.cpp server.cpp sql_dbcreator.cpp 
+sql_mysql.cpp sql_odbc.cpp sql_pgsql.cpp sql_sqlite3.cpp storage.cpp 
+storage_file.cpp storage_sql.cpp support.cpp team.cpp tick.cpp timer.cpp topic.cpp 
+tournament.cpp tracker.cpp udptest_send.cpp versioncheck.cpp watch.cpp 
+storage_sql2.cpp sql_common.cpp handle_wol.cpp handle_irc_common.cpp 
+handle_apireg.cpp)
+target_link_libraries(bnetd compat common tinycdb 
+${ZLIB_LIBRARIES} ${MYSQL_LIBRARIES} ${SQLITE3_LIBRARIES})
diff --git a/pvpgn/src/bniutils/CMakeLists.txt b/pvpgn/src/bniutils/CMakeLists.txt
new file mode 100644
index 0000000..bcce61f
--- /dev/null
+++ b/pvpgn/src/bniutils/CMakeLists.txt
@@ -0,0 +1,14 @@
+add_executable(bnilist bnilist.cpp fileio.cpp tga.cpp)
+target_link_libraries(bnilist common compat)
+
+add_executable(bni2tga bni2tga.cpp fileio.cpp)
+target_link_libraries(bni2tga common)
+
+add_executable(bniextract bniextract.cpp fileio.cpp tga.cpp bni.cpp)
+target_link_libraries(bniextract common compat)
+
+add_executable(bnibuild bnibuild.cpp fileio.cpp bni.cpp tga.cpp)
+target_link_libraries(bnibuild common compat)
+
+add_executable(tgainfo tgainfo.cpp fileio.cpp tga.cpp)
+target_link_libraries(tgainfo common compat)
diff --git a/pvpgn/src/bnpass/CMakeLists.txt b/pvpgn/src/bnpass/CMakeLists.txt
new file mode 100644
index 0000000..d6abb3c
--- /dev/null
+++ b/pvpgn/src/bnpass/CMakeLists.txt
@@ -0,0 +1,5 @@
+add_executable(bnpass bnpass.cpp)
+target_link_libraries(bnpass common compat)
+
+add_executable(sha1hash sha1hash.cpp)
+target_link_libraries(sha1hash common compat)
diff --git a/pvpgn/src/bnpcap/CMakeLists.txt b/pvpgn/src/bnpcap/CMakeLists.txt
new file mode 100644
index 0000000..1a0d996
--- /dev/null
+++ b/pvpgn/src/bnpcap/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_executable(bnpcap bnpcap.cpp)
+target_link_libraries(bnpcap common pcap)
diff --git a/pvpgn/src/bntrackd/CMakeLists.txt b/pvpgn/src/bntrackd/CMakeLists.txt
new file mode 100644
index 0000000..01d65ca
--- /dev/null
+++ b/pvpgn/src/bntrackd/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_executable(bntrackd bntrackd.cpp)
+target_link_libraries(bntrackd common compat)
diff --git a/pvpgn/src/client/CMakeLists.txt b/pvpgn/src/client/CMakeLists.txt
new file mode 100644
index 0000000..ccb7a07
--- /dev/null
+++ b/pvpgn/src/client/CMakeLists.txt
@@ -0,0 +1,11 @@
+add_executable(bnchat bnchat.cpp client.cpp client_connect.cpp udptest.cpp)
+target_link_libraries(bnchat common compat)
+
+add_executable(bnftp bnftp.cpp client.cpp)
+target_link_libraries(bnftp common compat)
+
+add_executable(bnbot bnbot.cpp client.cpp)
+target_link_libraries(bnbot common compat)
+
+add_executable(bnstat bnstat.cpp client.cpp client_connect.cpp udptest.cpp)
+target_link_libraries(bnstat common compat)
diff --git a/pvpgn/src/common/CMakeLists.txt b/pvpgn/src/common/CMakeLists.txt
new file mode 100644
index 0000000..e94bad1
--- /dev/null
+++ b/pvpgn/src/common/CMakeLists.txt
@@ -0,0 +1,7 @@
+add_library(common conf.cpp list.cpp eventlog.cpp hexdump.cpp bn_type.cpp 
+util.cpp addr.cpp d2char_checksum.cpp xalloc.cpp network.cpp packet.cpp 
+xstring.cpp asnprintf.cpp bnethash.cpp bnethashconv.cpp bnettime.cpp 
+fdwatch.cpp fdwatch_epoll.cpp fdwatch_kqueue.cpp fdwatch_poll.cpp 
+fdwatch_select.cpp give_up_root_privileges.cpp hashtable.cpp proginfo.cpp 
+queue.cpp rcm.cpp rlimit.cpp tag.cpp token.cpp trans.cpp fdwbackend.cpp 
+xstr.cpp systemerror.cpp wolhash.cpp)
diff --git a/pvpgn/src/compat/CMakeLists.txt b/pvpgn/src/compat/CMakeLists.txt
new file mode 100644
index 0000000..8d2a92e
--- /dev/null
+++ b/pvpgn/src/compat/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_library(compat psock.cpp strerror.cpp strsep.cpp pgetopt.cpp 
+gettimeofday.cpp inet_aton.cpp inet_ntoa.cpp mmap.cpp pdir.cpp snprintf.cpp 
+strcasecmp.cpp strdup.cpp strncasecmp.cpp strtoul.cpp uname.cpp vsnprintf.cpp)
diff --git a/pvpgn/src/d2cs/CMakeLists.txt b/pvpgn/src/d2cs/CMakeLists.txt
new file mode 100644
index 0000000..aa60407
--- /dev/null
+++ b/pvpgn/src/d2cs/CMakeLists.txt
@@ -0,0 +1,5 @@
+add_executable(d2cs bnetd.cpp cmdline.cpp connection.cpp d2charfile.cpp 
+d2charlist.cpp d2gs.cpp d2ladder.cpp game.cpp gamequeue.cpp handle_bnetd.cpp 
+handle_d2cs.cpp handle_d2gs.cpp handle_init.cpp handle_signal.cpp main.cpp 
+net.cpp prefs.cpp s2s.cpp server.cpp serverqueue.cpp)
+target_link_libraries(d2cs common compat win32)
diff --git a/pvpgn/src/d2dbs/CMakeLists.txt b/pvpgn/src/d2dbs/CMakeLists.txt
new file mode 100644
index 0000000..77d8d0f
--- /dev/null
+++ b/pvpgn/src/d2dbs/CMakeLists.txt
@@ -0,0 +1,3 @@
+add_executable(d2dbs charlock.cpp d2ladder.cpp dbserver.cpp dbspacket.cpp 
+cmdline.cpp prefs.cpp handle_signal.cpp dbsdupecheck.cpp main.cpp)
+target_link_libraries(d2dbs common compat)
diff --git a/pvpgn/src/tinycdb/CMakeLists.txt b/pvpgn/src/tinycdb/CMakeLists.txt
new file mode 100644
index 0000000..7312cbe
--- /dev/null
+++ b/pvpgn/src/tinycdb/CMakeLists.txt
@@ -0,0 +1,8 @@
+add_library(tinycdb cdb_find.cpp cdb_findnext.cpp cdb_hash.cpp cdb_init.cpp 
+cdb_make_add.cpp cdb_make.cpp cdb_make_find.cpp cdb_make_put.cpp cdb_seek.cpp 
+cdb_seq.cpp cdb_unpack.cpp)
+
+add_executable(bncdb cdb.cpp)
+target_link_libraries(bncdb tinycdb 
+${CMAKE_BINARY_DIR}/src/common/libcommon.a
+${CMAKE_BINARY_DIR}/src/compat/libcompat.a )
diff --git a/pvpgn/src/win32/CMakeLists.txt b/pvpgn/src/win32/CMakeLists.txt
new file mode 100644
index 0000000..963516f
--- /dev/null
+++ b/pvpgn/src/win32/CMakeLists.txt
@@ -0,0 +1 @@
+add_library(win32 service.cpp)