tBuild curses client with cmake. - vaccinewars - be a doctor and try to vaccina… | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 2282a4f361d8e3bc9d0d0d1006766fa8c1263e84 | |
parent e26f3cc0f06b0f72cb9cda70eea4cae8ffc23946 | |
Author: Ben Webb <[email protected]> | |
Date: Fri, 27 Mar 2015 14:32:15 -0700 | |
Build curses client with cmake. | |
Diffstat: | |
M CMakeLists.txt | 54 +++++++++++++++++++++++++++--… | |
A cmake_modules/FindGLIB.cmake | 120 +++++++++++++++++++++++++++++… | |
M config-cmake.h.in | 18 +++++++++++++++--- | |
A src/curses_client/CMakeLists.txt | 1 + | |
M src/cursesport/cursesport.h | 8 ++++++-- | |
M src/dopewars.h | 2 +- | |
M src/network.h | 2 +- | |
7 files changed, 192 insertions(+), 13 deletions(-) | |
--- | |
diff --git a/CMakeLists.txt b/CMakeLists.txt | |
t@@ -1,11 +1,19 @@ | |
cmake_minimum_required(VERSION 2.8) | |
project(dopewars) | |
-set(VERSION SVN) | |
+set(VERSION "SVN") | |
include(CheckIncludeFiles) | |
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} | |
+ ${PROJECT_SOURCE_DIR}/cmake_modules) | |
+include(${PROJECT_SOURCE_DIR}/cmake_modules/FindGLIB.cmake) | |
+ | |
+# Find source headers | |
+include_directories("${PROJECT_SOURCE_DIR}/src") | |
+ | |
# Find generated config.h | |
+set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_CONFIG_H") | |
include_directories("${PROJECT_BINARY_DIR}") | |
check_include_files(fcntl.h HAVE_FCNTL_H) | |
t@@ -14,15 +22,49 @@ check_include_files(unistd.h HAVE_UNISTD_H) | |
check_include_files(stdlib.h HAVE_STDLIB_H) | |
# Process client options | |
-option(GUI_CLIENT "include graphical client (GTK+/Win32)" "probe") | |
-option(CURSES_CLIENT "include curses client" "probe") | |
+option(GUI_CLIENT "include graphical client (GTK+/Win32)" ON) | |
+option(CURSES_CLIENT "include curses client" ON) | |
option(GUI_SERVER "use a simple GTK+/Win32 GUI for the server" "probe") | |
-option(WITH_ESD "support ESD sound output" "probe") | |
-option(WITH_SDL "support SDL sound output" "probe") | |
+option(WITH_ESD "support ESD sound output" ON) | |
+option(WITH_SDL "support SDL sound output" ON) | |
+ | |
+find_package(GLIB) | |
+if (!GLIB_FOUND) | |
+ message(FATAL_ERROR "GLib is required") | |
+else() | |
+ set(EXTRA_LIBS ${EXTRA_LIBS} ${GLIB_LIBRARIES}) | |
+ include_directories(${GLIB_INCLUDE_DIRS}) | |
+endif() | |
+ | |
+if (CURSES_CLIENT) | |
+ find_package(Curses) | |
+ if (CURSES_FOUND) | |
+ add_subdirectory(src/curses_client) | |
+ set(EXTRA_LIBS ${EXTRA_LIBS} ${CURSES_LIBRARIES} cursesclient) | |
+ include_directories(${CURSES_INCLUDE_DIRS}) | |
+ else() | |
+ message(WARNING "Cannot find any curses-type library") | |
+ set(CURSES_CLIENT OFF) | |
+ endif() | |
+endif() | |
configure_file("${PROJECT_SOURCE_DIR}/config-cmake.h.in" | |
"${PROJECT_BINARY_DIR}/config.h") | |
-add_executable(dopewars "${PROJECT_SOURCE_DIR}/src/*.c") | |
+add_executable(dopewars | |
+ "${PROJECT_SOURCE_DIR}/src/AIPlayer.c" | |
+ "${PROJECT_SOURCE_DIR}/src/error.c" | |
+ "${PROJECT_SOURCE_DIR}/src/sound.c" | |
+ "${PROJECT_SOURCE_DIR}/src/admin.c" | |
+ "${PROJECT_SOURCE_DIR}/src/log.c" | |
+ "${PROJECT_SOURCE_DIR}/src/tstring.c" | |
+ "${PROJECT_SOURCE_DIR}/src/configfile.c" | |
+ "${PROJECT_SOURCE_DIR}/src/message.c" | |
+ "${PROJECT_SOURCE_DIR}/src/util.c" | |
+ "${PROJECT_SOURCE_DIR}/src/convert.c" | |
+ "${PROJECT_SOURCE_DIR}/src/network.c" | |
+ "${PROJECT_SOURCE_DIR}/src/dopewars.c" | |
+ "${PROJECT_SOURCE_DIR}/src/serverside.c") | |
+ | |
target_link_libraries(dopewars ${EXTRA_LIBS}) | |
diff --git a/cmake_modules/FindGLIB.cmake b/cmake_modules/FindGLIB.cmake | |
t@@ -0,0 +1,120 @@ | |
+# - Try to find Glib and its components (gio, gobject etc) | |
+# Once done, this will define | |
+# | |
+# GLIB_FOUND - system has Glib | |
+# GLIB_INCLUDE_DIRS - the Glib include directories | |
+# GLIB_LIBRARIES - link these to use Glib | |
+# | |
+# Optionally, the COMPONENTS keyword can be passed to find_package() | |
+# and Glib components can be looked for. Currently, the following | |
+# components can be used, and they define the following variables if | |
+# found: | |
+# | |
+# gio: GLIB_GIO_LIBRARIES | |
+# gobject: GLIB_GOBJECT_LIBRARIES | |
+# gmodule: GLIB_GMODULE_LIBRARIES | |
+# gthread: GLIB_GTHREAD_LIBRARIES | |
+# | |
+# Note that the respective _INCLUDE_DIR variables are not set, since | |
+# all headers are in the same directory as GLIB_INCLUDE_DIRS. | |
+# | |
+# Copyright (C) 2012 Raphael Kubo da Costa <[email protected]> | |
+# | |
+# Redistribution and use in source and binary forms, with or without | |
+# modification, are permitted provided that the following conditions | |
+# are met: | |
+# 1. Redistributions of source code must retain the above copyright | |
+# notice, this list of conditions and the following disclaimer. | |
+# 2. Redistributions in binary form must reproduce the above copyright | |
+# notice, this list of conditions and the following disclaimer in the | |
+# documentation and/or other materials provided with the distribution. | |
+# | |
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND ITS CONTRIBUTORS ``AS | |
+# IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | |
+# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR ITS | |
+# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
+# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
+# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; | |
+# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
+# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR | |
+# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
+# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
+ | |
+find_package(PkgConfig) | |
+pkg_check_modules(PC_GLIB QUIET glib-2.0) | |
+ | |
+find_library(GLIB_LIBRARIES | |
+ NAMES glib-2.0 | |
+ HINTS ${PC_GLIB_LIBDIR} | |
+ ${PC_GLIB_LIBRARY_DIRS} | |
+) | |
+ | |
+# Files in glib's main include path may include glibconfig.h, which, | |
+# for some odd reason, is normally in $LIBDIR/glib-2.0/include. | |
+get_filename_component(_GLIB_LIBRARY_DIR ${GLIB_LIBRARIES} PATH) | |
+find_path(GLIBCONFIG_INCLUDE_DIR | |
+ NAMES glibconfig.h | |
+ HINTS ${PC_LIBDIR} ${PC_LIBRARY_DIRS} ${_GLIB_LIBRARY_DIR} | |
+ ${PC_GLIB_INCLUDEDIR} ${PC_GLIB_INCLUDE_DIRS} | |
+ PATH_SUFFIXES glib-2.0/include | |
+) | |
+ | |
+find_path(GLIB_INCLUDE_DIR | |
+ NAMES glib.h | |
+ HINTS ${PC_GLIB_INCLUDEDIR} | |
+ ${PC_GLIB_INCLUDE_DIRS} | |
+ PATH_SUFFIXES glib-2.0 | |
+) | |
+ | |
+set(GLIB_INCLUDE_DIRS ${GLIB_INCLUDE_DIR} ${GLIBCONFIG_INCLUDE_DIR}) | |
+ | |
+# Version detection | |
+file(READ "${GLIBCONFIG_INCLUDE_DIR}/glibconfig.h" GLIBCONFIG_H_CONTENTS) | |
+string(REGEX MATCH "#define GLIB_MAJOR_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_… | |
+set(GLIB_VERSION_MAJOR "${CMAKE_MATCH_1}") | |
+string(REGEX MATCH "#define GLIB_MINOR_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_… | |
+set(GLIB_VERSION_MINOR "${CMAKE_MATCH_1}") | |
+string(REGEX MATCH "#define GLIB_MICRO_VERSION ([0-9]+)" _dummy "${GLIBCONFIG_… | |
+set(GLIB_VERSION_MICRO "${CMAKE_MATCH_1}") | |
+set(GLIB_VERSION "${GLIB_VERSION_MAJOR}.${GLIB_VERSION_MINOR}.${GLIB_VERSION_M… | |
+ | |
+# Additional Glib components. We only look for libraries, as not all of them | |
+# have corresponding headers and all headers are installed alongside the main | |
+# glib ones. | |
+foreach (_component ${GLIB_FIND_COMPONENTS}) | |
+ if (${_component} STREQUAL "gio") | |
+ find_library(GLIB_GIO_LIBRARIES NAMES gio-2.0 HINTS ${_GLIB_LIBRARY_DI… | |
+ set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GIO_LIBR… | |
+ elseif (${_component} STREQUAL "gobject") | |
+ find_library(GLIB_GOBJECT_LIBRARIES NAMES gobject-2.0 HINTS ${_GLIB_LI… | |
+ set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GOBJECT_… | |
+ elseif (${_component} STREQUAL "gmodule") | |
+ find_library(GLIB_GMODULE_LIBRARIES NAMES gmodule-2.0 HINTS ${_GLIB_LI… | |
+ set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GMODULE_… | |
+ elseif (${_component} STREQUAL "gthread") | |
+ find_library(GLIB_GTHREAD_LIBRARIES NAMES gthread-2.0 HINTS ${_GLIB_LI… | |
+ set(ADDITIONAL_REQUIRED_VARS ${ADDITIONAL_REQUIRED_VARS} GLIB_GTHREAD_… | |
+ elseif (${_component} STREQUAL "gio-unix") | |
+ # gio-unix is compiled as part of the gio library, but the include pat… | |
+ # are separate from the shared glib ones. Since this is currently only… | |
+ # by WebKitGTK+ we don't go to extraordinary measures beyond pkg-confi… | |
+ pkg_check_modules(GIO_UNIX QUIET gio-unix-2.0) | |
+ endif () | |
+endforeach () | |
+ | |
+include(FindPackageHandleStandardArgs) | |
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLIB REQUIRED_VARS GLIB_INCLUDE_DIRS GLIB_LI… | |
+ VERSION_VAR GLIB_VERSION) | |
+ | |
+mark_as_advanced( | |
+ GLIBCONFIG_INCLUDE_DIR | |
+ GLIB_GIO_LIBRARIES | |
+ GLIB_GIO_UNIX_LIBRARIES | |
+ GLIB_GMODULE_LIBRARIES | |
+ GLIB_GOBJECT_LIBRARIES | |
+ GLIB_GTHREAD_LIBRARIES | |
+ GLIB_INCLUDE_DIR | |
+ GLIB_INCLUDE_DIRS | |
+ GLIB_LIBRARIES | |
+) | |
diff --git a/config-cmake.h.in b/config-cmake.h.in | |
t@@ -1,6 +1,21 @@ | |
+/* Version number of package */ | |
+#define VERSION "@VERSION@" | |
+ | |
/* Use the (n)curses client? */ | |
#cmakedefine CURSES_CLIENT | |
+/* true if curses.h is available */ | |
+#cmakedefine CURSES_HAVE_CURSES_H | |
+ | |
+/* true if ncurses.h is available */ | |
+#cmakedefine CURSES_HAVE_NCURSES_H | |
+ | |
+/* true if ncurses/ncurses.h is available */ | |
+#cmakedefine CURSES_HAVE_NCURSES_NCURSES_H | |
+ | |
+/* true if ncurses/curses.h is available */ | |
+#cmakedefine CURSES_HAVE_NCURSES_CURSES_H | |
+ | |
/* Define if building under the Cygwin environment */ | |
#undef CYGWIN | |
t@@ -188,9 +203,6 @@ | |
#endif | |
-/* Version number of package */ | |
-#cmakedefine VERSION | |
- | |
/* Define to 1 if on MINIX. */ | |
#undef _MINIX | |
diff --git a/src/curses_client/CMakeLists.txt b/src/curses_client/CMakeLists.txt | |
t@@ -0,0 +1 @@ | |
+add_library(cursesclient curses_client.c) | |
diff --git a/src/cursesport/cursesport.h b/src/cursesport/cursesport.h | |
t@@ -92,10 +92,14 @@ void endwin(void); | |
#include <errno.h> | |
/* Include a suitable curses-type library */ | |
-#if HAVE_LIBNCURSES | |
+#if HAVE_LIBNCURSES || defined(CURSES_HAVE_NCURSES_H) | |
#include <ncurses.h> | |
-#elif HAVE_LIBCURSES | |
+#elif HAVE_LIBCURSES || defined(CURSES_HAVE_CURSES_H) | |
#include <curses.h> | |
+#elif defined(CURSES_HAVE_NCURSES_NCURSES_H) | |
+#include <ncurses/ncurses.h> | |
+#elif defined(CURSES_HAVE_NCURSES_CURSES_H) | |
+#include <ncurses/curses.h> | |
#elif HAVE_LIBCUR_COLR | |
#include <curses_colr/curses.h> | |
#endif | |
diff --git a/src/dopewars.h b/src/dopewars.h | |
t@@ -35,7 +35,7 @@ | |
#include <sys/time.h> | |
#include <time.h> | |
#else | |
-#if HAVE_SYS_TIME_H | |
+#ifdef HAVE_SYS_TIME_H | |
#include <sys/time.h> | |
#else | |
#include <time.h> | |
diff --git a/src/network.h b/src/network.h | |
t@@ -38,7 +38,7 @@ | |
#include <sys/time.h> | |
#include <time.h> | |
#else | |
-#if HAVE_SYS_TIME_H | |
+#ifdef HAVE_SYS_TIME_H | |
#include <sys/time.h> | |
#else | |
#include <time.h> |