2013-09-14 04:23:31 +02:00
cmake_minimum_required ( VERSION 2.8 )
2013-08-29 00:21:27 +02:00
project ( OpenSpades )
set ( OpenSpades_VERSION_MAJOR 0 )
set ( OpenSpades_VERSION_MINOR 0 )
2014-06-14 01:40:26 +09:00
set ( OpenSpades_VERSION_REVISION 12 )
2013-11-01 21:22:54 +01:00
2014-04-23 17:39:54 +11:00
set ( OPENSPADES_FULL_VERSION "${OpenSpades_VERSION_MAJOR}.${OpenSpades_VERSION_MINOR}.${OpenSpades_VERSION_REVISION}" )
2013-11-01 21:22:54 +01:00
set ( OS_BASE_DIR ${ CMAKE_CURRENT_SOURCE_DIR } )
2013-08-29 00:21:27 +02:00
2013-09-14 04:19:56 +02:00
set ( CMAKE_PREFIX_PATH Sources/Externals )
2013-09-03 21:52:32 +09:00
2013-12-09 17:36:05 +09:00
include ( cmake/FindSDL2.cmake )
if ( NOT SDL2_FOUND )
message ( FATAL_ERROR "SDL 2.0 not found, set ENV{SDL2DIR} to point to SDL 2.0, and optionally set the cmake var SDL2_LIBRARY_TEMP to the lib dir" )
2013-08-29 00:21:27 +02:00
endif ( )
2014-02-26 17:20:07 +01:00
include ( cmake/FindSDL2_image.cmake )
if ( NOT SDL2_IMAGE_FOUND )
message ( FATAL_ERROR "SDL_image 2.0 not found, set ENV{SDL2DIR} to point to SDL 2.0, and optionally set the cmake var SDL2_LIBRARY_TEMP to the lib dir" )
endif ( )
2013-08-29 00:21:27 +02:00
include ( FindOpenGL )
if ( NOT OPENGL_FOUND AND NOT OPENGL_XMESA_FOUND AND NOT OPENGL_GLU_FOUND )
message ( FATAL_ERROR "OpenGL not found, please install it" )
endif ( )
2013-08-30 21:25:35 +02:00
include ( cmake/FindGLEW2.cmake )
2013-08-29 00:21:27 +02:00
if ( NOT GLEW_FOUND )
message ( FATAL_ERROR "GLEW not found, please install it and make sure CMake can find it (add it to the PATH)" )
endif ( )
include ( FindZLIB )
if ( NOT ZLIB_FOUND )
message ( FATAL_ERROR "ZLIB not found, manually set ZLIB_ROOT in CMake" )
endif ( )
2013-08-31 19:23:32 +02:00
include ( FindCURL )
if ( NOT CURL_FOUND )
message ( FATAL_ERROR "cURL not found, please install it (and make sure it's in your path)" )
endif ( )
2013-08-29 00:21:27 +02:00
if ( CMAKE_COMPILER_IS_GNUCXX )
2013-09-22 20:38:49 -04:00
# GCC C++11 support
# from http://stackoverflow.com/questions/10984442/how-to-detect-c11-support-of-a-compiler-with-cmake
#
execute_process ( COMMAND ${ CMAKE_C_COMPILER } -dumpversion OUTPUT_VARIABLE GCC_VERSION )
if ( GCC_VERSION VERSION_GREATER 4.7 OR GCC_VERSION VERSION_EQUAL 4.7 )
message ( STATUS "C++11 activated." )
add_definitions ( "-std=gnu++11" )
elseif ( GCC_VERSION VERSION_GREATER 4.3 OR GCC_VERSION VERSION_EQUAL 4.3 )
message ( WARNING "C++0x activated. If you get any errors update to a compiler which fully supports C++11" )
add_definitions ( "-std=gnu++0x" )
else ( )
message ( FATAL_ERROR "C++11 needed. Therefore a gcc compiler with a version higher than 4.3 is needed." )
endif ( )
add_definitions (
- W a l l
- W e x t r a
- W n o - u n k n o w n - p r a g m a s #learn_more: output is spammed like shit by all those #pragma mark items
)
2013-08-29 00:21:27 +02:00
2014-04-27 12:52:28 +11:00
if ( CMAKE_BUILD_TYPE MATCHES "Release" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3" )
set ( CMAKE_EXE_LINKER_FLAGS "-s" )
endif ( )
2014-03-11 16:39:39 +09:00
elseif ( "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" )
# Clang C++11 support
2014-03-11 16:47:59 +09:00
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11" )
2014-04-27 12:52:28 +11:00
2014-07-31 00:46:43 +04:00
add_definitions (
- W a l l
- W e x t r a
- W n o - u n u s e d - p a r a m e t e r
)
2014-04-27 12:52:28 +11:00
if ( CMAKE_BUILD_TYPE MATCHES "Release" )
set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3" )
set ( CMAKE_EXE_LINKER_FLAGS "-s" )
endif ( )
2013-09-22 20:38:49 -04:00
elseif ( MSVC )
add_definitions (
/ D _ C R T _ S E C U R E _ N O _ W A R N I N G S
/ w d 4 0 6 8
/ D N O M I N M A X
/ D _ U S E _ M A T H _ D E F I N E S
)
2013-10-09 00:59:36 +02:00
set ( CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT" ) #static link to msv runtime (MSVCR(P)xxx.dll)
#set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
2013-08-29 00:21:27 +02:00
endif ( )
set_property ( GLOBAL PROPERTY USE_FOLDERS ON ) #msvc / xcode: group files in project
2013-08-31 02:32:51 +02:00
#mainly for ENet...
2013-08-29 00:21:27 +02:00
include ( CheckFunctionExists )
2013-08-31 02:32:51 +02:00
include ( CheckStructHasMember )
include ( CheckTypeSize )
check_function_exists ( "fcntl" HAS_FCNTL )
check_function_exists ( "poll" HAS_POLL )
check_function_exists ( "gethostbyname_r" HAS_GETHOSTBYNAME_R )
check_function_exists ( "gethostbyaddr_r" HAS_GETHOSTBYADDR_R )
check_function_exists ( "inet_pton" HAS_INET_PTON )
check_function_exists ( "inet_ntop" HAS_INET_NTOP )
check_struct_has_member ( "struct msghdr" "msg_flags" "sys/types.h;sys/socket.h" HAS_MSGHDR_FLAGS )
set ( CMAKE_EXTRA_INCLUDE_FILES "sys/types.h" "sys/socket.h" )
check_type_size ( "socklen_t" HAS_SOCKLEN_T BUILTIN_TYPES_ONLY )
unset ( CMAKE_EXTRA_INCLUDE_FILES )
if ( HAS_FCNTL )
add_definitions ( -DHAS_FCNTL=1 )
endif ( )
if ( HAS_POLL )
add_definitions ( -DHAS_POLL=1 )
endif ( )
if ( HAS_GETHOSTBYNAME_R )
add_definitions ( -DHAS_GETHOSTBYNAME_R=1 )
endif ( )
if ( HAS_GETHOSTBYADDR_R )
add_definitions ( -DHAS_GETHOSTBYADDR_R=1 )
endif ( )
if ( HAS_INET_PTON )
add_definitions ( -DHAS_INET_PTON=1 )
endif ( )
if ( HAS_INET_NTOP )
add_definitions ( -DHAS_INET_NTOP=1 )
endif ( )
if ( HAS_MSGHDR_FLAGS )
add_definitions ( -DHAS_MSGHDR_FLAGS=1 )
endif ( )
if ( HAS_SOCKLEN_T )
add_definitions ( -DHAS_SOCKLEN_T=1 )
endif ( )
2014-04-23 21:47:48 +11:00
option ( OPENSPADES_RESOURCES "NO_OPENSPADES_RESOURCES" ON )
2014-04-28 02:21:17 +11:00
# note that all paths are without trailing slash
set ( OPENSPADES_INSTALL_DOC "share/doc/openspades" CACHE STRING "Directory for installing documentation. " )
set ( OPENSPADES_INSTALL_MENU "share/menu" CACHE STRING "Directory for installing menu file. " )
set ( OPENSPADES_INSTALL_MAN "share/man/man6" CACHE STRING "Directory for installing man file. " )
set ( OPENSPADES_INSTALL_RESOURCES "share/games/openspades/Resources" CACHE STRING "Directory for installing Resources. " )
set ( OPENSPADES_INSTALL_ICONS "share/icons/hicolor" CACHE STRING "Directory for installing icons. " )
set ( OPENSPADES_INSTALL_PIXMAP "share/pixmaps" CACHE STRING "Directory for installing .xpm icon. " )
set ( OPENSPADES_INSTALL_BINARY "games" CACHE STRING "Directory for installing result binary executable. " )
set ( OPENSPADES_INSTALL_DESKTOP "share/applications" CACHE STRING "Directory for installing .desktop file. " )
set ( OPENSPADES_INSTALL_LIBS "lib/openspades" CACHE STRING "Directory for installing various non-media stuff. Currently not used" )
2013-08-30 23:58:56 +02:00
set ( OPENSPADES_RESDIR "" CACHE STRING "Resource dir to use while developing" )
2013-10-08 22:12:41 +02:00
set ( OPENSPADES_EXTRATITLE "" CACHE STRING "Extra info to add to the package name" )
2013-08-30 23:58:56 +02:00
if ( OPENSPADES_RESDIR )
set ( RESDIR ${ OPENSPADES_RESDIR } )
2013-08-30 20:06:57 +02:00
set ( RESDIR_DEFINED TRUE )
2013-08-30 23:58:56 +02:00
mark_as_advanced ( RESDIR )
mark_as_advanced ( RESDIR_DEFINED )
2013-08-30 20:06:57 +02:00
endif ( )
2014-04-27 15:13:34 +11:00
if ( UNIX )
EXECUTE_PROCESS ( COMMAND "date" "+%Y" OUTPUT_VARIABLE CMAKE_CURRENT_YEAR )
mark_as_advanced ( CMAKE_CURRENT_YEAR )
endif ( UNIX )
2014-04-27 12:52:28 +11:00
2013-09-14 04:19:56 +02:00
if ( CMAKE_CXX_COMPILER_ID )
if ( CMAKE_CXX_COMPILER_VERSION )
set ( _version " ${CMAKE_CXX_COMPILER_VERSION}" )
else ( )
set ( _version "" )
endif ( )
set ( OPENSPADES_COMPILER ${ CMAKE_CXX_COMPILER_ID } ${ _version } )
endif ( )
2013-08-29 00:21:27 +02:00
configure_file ( "${PROJECT_SOURCE_DIR}/OpenSpades.h.in" "${PROJECT_BINARY_DIR}/OpenSpades.h" )
2013-11-01 21:24:50 +01:00
configure_file ( "${PROJECT_SOURCE_DIR}/OpenSpades.rc.in" "${PROJECT_BINARY_DIR}/OpenSpades.rc" )
2014-07-31 00:41:13 +04:00
include_directories ( BEFORE "${PROJECT_BINARY_DIR}" )
2013-12-09 17:36:05 +09:00
include_directories ( "${SDL2_INCLUDE_DIR}" )
2014-02-26 17:20:07 +01:00
include_directories ( "${SDL2_IMAGE_INCLUDE_DIR}" )
2013-08-29 00:21:27 +02:00
if ( OPENGL_INCLUDE_DIR )
include_directories ( "${OPENGL_INCLUDE_DIR}" )
endif ( )
include_directories ( "${GLEW_INCLUDE_DIR}" )
include_directories ( "${ZLIB_INCLUDE_DIR}" )
2013-08-31 19:23:32 +02:00
include_directories ( "${CURL_INCLUDE_DIRS}" )
2013-08-29 00:21:27 +02:00
add_subdirectory ( Resources )
add_subdirectory ( Sources )
2013-10-06 16:24:43 +02:00
2014-04-27 12:52:28 +11:00
if ( UNIX AND NOT APPLE )
2014-04-06 20:10:13 +11:00
# various texts
2015-02-08 00:18:40 +09:00
INSTALL ( FILES AUTHORS LICENSE README.md DESTINATION ${ OPENSPADES_INSTALL_DOC } / )
2014-04-06 20:10:13 +11:00
2014-04-27 12:52:28 +11:00
# menu file
2014-04-28 02:21:17 +11:00
INSTALL ( FILES Resources/Unix/Menu/openspades DESTINATION ${ OPENSPADES_INSTALL_MENU } / )
2014-04-27 12:52:28 +11:00
# man file
2014-04-28 02:21:17 +11:00
INSTALL ( FILES ${ CMAKE_BINARY_DIR } /Resources/Unix/Man/openspades.6.gz DESTINATION ${ OPENSPADES_INSTALL_MAN } / )
2014-04-27 12:52:28 +11:00
# changelog file
2014-04-28 02:21:17 +11:00
INSTALL ( FILES ${ CMAKE_BINARY_DIR } /Resources/Unix/Debian/changelog.gz DESTINATION ${ OPENSPADES_INSTALL_DOC } / )
2014-04-27 12:52:28 +11:00
# copyright file
2014-04-28 02:21:17 +11:00
INSTALL ( FILES ${ CMAKE_BINARY_DIR } /Resources/Unix/Debian/copyright DESTINATION ${ OPENSPADES_INSTALL_DOC } / )
2014-04-27 12:52:28 +11:00
2014-04-23 17:39:54 +11:00
# install devpak
install (
2014-04-25 22:22:35 +11:00
D I R E C T O R Y $ { C M A K E _ B I N A R Y _ D I R } / R e s o u r c e s / D e v P a k /
2014-04-28 02:21:17 +11:00
D E S T I N A T I O N $ { O P E N S P A D E S _ I N S T A L L _ R E S O U R C E S } )
2014-04-23 17:39:54 +11:00
# install other resources, that not packed to devpak
2014-04-28 02:21:17 +11:00
install ( DIRECTORY Resources/Gfx DESTINATION ${ OPENSPADES_INSTALL_RESOURCES } )
install ( DIRECTORY Resources/Locales DESTINATION ${ OPENSPADES_INSTALL_RESOURCES } )
install ( DIRECTORY Resources/Maps DESTINATION ${ OPENSPADES_INSTALL_RESOURCES } )
install ( DIRECTORY Resources/Scripts DESTINATION ${ OPENSPADES_INSTALL_RESOURCES } )
install ( DIRECTORY Resources/Shaders DESTINATION ${ OPENSPADES_INSTALL_RESOURCES } )
2014-04-06 20:10:13 +11:00
# install icons
2014-04-23 17:39:54 +11:00
INSTALL (
2014-04-25 22:22:35 +11:00
D I R E C T O R Y $ { C M A K E _ B I N A R Y _ D I R } / R e s o u r c e s / I c o n s / h i c o l o r /
2014-04-28 02:21:17 +11:00
D E S T I N A T I O N $ { O P E N S P A D E S _ I N S T A L L _ I C O N S }
2014-04-25 22:22:35 +11:00
F I L E S _ M A T C H I N G P A T T E R N " * . p n g " )
2014-04-06 20:10:13 +11:00
2014-04-28 02:21:17 +11:00
INSTALL ( FILES Resources/Icons/openspades.xpm DESTINATION ${ OPENSPADES_INSTALL_PIXMAP } / )
2013-10-06 16:24:43 +02:00
2014-04-06 20:10:13 +11:00
# binary file
2014-04-28 02:21:17 +11:00
INSTALL ( PROGRAMS ${ CMAKE_BINARY_DIR } /bin/openspades DESTINATION ${ OPENSPADES_INSTALL_BINARY } )
2014-04-06 20:10:13 +11:00
# desktop file
2014-04-28 02:21:17 +11:00
INSTALL ( FILES Resources/Unix/Desktop/openspades.desktop DESTINATION ${ OPENSPADES_INSTALL_DESKTOP } / )
2014-04-06 20:10:13 +11:00
2014-04-25 22:22:35 +11:00
# Currently there is no files in lib/openspades. But if you reading this message in future and want to
# place somewhere libs, binaries or other non-media stuff, place them in lib/openspades. Thank you.
2014-04-27 12:52:28 +11:00
endif ( UNIX AND NOT APPLE )
2014-04-06 20:10:13 +11:00
2014-04-23 17:39:54 +11:00
2014-04-06 20:10:13 +11:00
#see http://www.cmake.org/cmake/help/v2.8.11/cpack.html
set ( CPACK_PACKAGE_NAME "OpenSpades" )
2014-04-23 17:39:54 +11:00
set ( CPACK_PACKAGE_DESCRIPTION_SUMMARY "Open-source clone of Ace of Spades" )
2014-04-25 22:22:35 +11:00
set ( CPACK_PACKAGE_DESCRIPTION "Open-source clone of Ace of Spades - free FPS sandbox game" )
2013-10-06 16:24:43 +02:00
set ( CPACK_PACKAGE_VENDOR "yvt, assorted" )
2014-04-25 22:22:35 +11:00
set ( CPACK_PACKAGE_CONTACT "yvt <i@yvt.jp>" )
2013-10-06 16:24:43 +02:00
set ( CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md" )
2014-04-23 17:39:54 +11:00
SET ( CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md" )
2013-10-06 16:24:43 +02:00
set ( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE" )
2014-04-23 17:39:54 +11:00
set ( CPACK_SOURCE_PACKAGE_FILE_NAME "openspades-${OPENSPADES_FULL_VERSION}" )
2014-04-27 12:52:28 +11:00
SET ( CPACK_PACKAGE_FILE_NAME "openspades-${OPENSPADES_FULL_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}" )
2014-04-23 17:39:54 +11:00
set ( CPACK_PACKAGE_INSTALL_DIRECTORY "OpenSpades ${OPENSPADES_FULL_VERSION}" )
2013-10-06 16:24:43 +02:00
set ( CPACK_PACKAGE_VERSION_MAJOR ${ OpenSpades_VERSION_MAJOR } )
set ( CPACK_PACKAGE_VERSION_MINOR ${ OpenSpades_VERSION_MINOR } )
set ( CPACK_PACKAGE_VERSION_PATCH ${ OpenSpades_VERSION_REVISION } )
2014-04-27 12:52:28 +11:00
SET ( CPACK_SYSTEM_NAME "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}" )
SET ( CPACK_TOPLEVEL_TAG "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}" )
2014-04-23 17:39:54 +11:00
2013-10-06 16:24:43 +02:00
if ( WIN32 AND NOT UNIX )
2014-04-27 12:52:28 +11:00
2014-04-23 17:39:54 +11:00
set ( CPACK_NSIS_DISPLAY_NAME "OpenSpades ${OPENSPADES_FULL_VERSION}" )
2013-10-06 16:24:43 +02:00
# There is a bug in NSIS that does not handle full unix paths properly. Make
# sure there is at least one set of four (4) backlasshes.
2014-04-25 22:22:35 +11:00
set ( CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\openspades.exe" )
2014-04-23 17:39:54 +11:00
# TODO: set(CPACK_PACKAGE_ICON "")
2013-10-06 16:24:43 +02:00
set ( CPACK_NSIS_HELP_LINK "https://sites.google.com/a/yvt.jp/openspades/" )
set ( CPACK_NSIS_URL_INFO_ABOUT "http://buildandshoot.com/viewforum.php?f=57" )
2014-04-25 22:22:35 +11:00
SET ( CPACK_NSIS_CONTACT "i@yvt.jp" )
2014-04-23 17:39:54 +11:00
# TODO: SET(CPACK_NSIS_CREATE_ICONS_EXTRA "")
# TODO: SET(CPACK_NSIS_DELETE_ICONS_EXTRA "")
2014-04-25 22:22:35 +11:00
# TODO: SET(CPACK_NSIS_MUI_FINISHPAGE_RUN "openspades.exe")
2013-10-06 16:24:43 +02:00
set ( CPACK_NSIS_MODIFY_PATH ON )
2014-04-27 12:52:28 +11:00
elseif ( UNIX AND NOT APPLE )
# usage: `cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_BUILD_TYPE=Release .. ; make package`
2014-04-25 22:22:35 +11:00
INCLUDE ( InstallRequiredSystemLibraries )
2014-04-27 12:52:28 +11:00
set ( CPACK_DEBIAN_PACKAGE_DESCRIPTION "Open-source clone of Ace of Spades - free FPS sandbox game\n OpenSpades is a clone of Voxlap Ace of Spades 0.75, which is a free \n multiplayer game created by Ben Aksoy.\n .\n Here are some features:\n .\n - Ability to connect to vanilla/pyspades server\n - Better performance on some modern computers/netbooks\n - Sophisticated graphics\n - Fully open source (GPLv3 compliant)\n - Cross-platform" )
set ( CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA ${ CMAKE_CURRENT_SOURCE_DIR } /Resources/Unix/Control/postinst )
2014-04-25 22:22:35 +11:00
set ( CPACK_PACKAGING_INSTALL_PREFIX "/usr" )
SET ( CPACK_STRIP_FILES "bin/openspades" )
SET ( CPACK_SET_DESTDIR "on" )
SET ( CPACK_GENERATOR "DEB;TGZ" )
2014-04-27 12:52:28 +11:00
SET ( CPACK_DEBIAN_PACKAGE_DEPENDS
" libc6 ( >= 2.19 ) , libgcc1 ( >= 1:4.9 ) , l i b s t d c + + 6 ( >= 4.8.2 ) , zlib1g ( >= 1:1.2.8 ) , libcurl3 ( >= 7.35.0 ) , l i b g l e w 1 . 10 ( >= 1.10.0 ) , l i b s d l 2 - 2 . 0 - 0 ( >= 2.0.2 ) , l i b s d l 2 - i m a g e - 2 . 0 - 0 ( >= 2.0.0 ) " )
2014-04-25 22:22:35 +11:00
SET ( CPACK_DEBIAN_PACKAGE_PRIORITY "optional" )
SET ( CPACK_DEBIAN_PACKAGE_SECTION "games" )
SET ( CPACK_DEBIAN_ARCHITECTURE ${ CMAKE_SYSTEM_PROCESSOR } )
set ( CPACK_DEBIAN_PACKAGE_RECOMMENDS "" )
set ( CPACK_DEBIAN_PACKAGE_SUGGESTS "" )
SET ( CPACK_COMPONENTS_ALL ALL )
2014-04-27 12:52:28 +11:00
2013-10-06 16:24:43 +02:00
endif ( WIN32 AND NOT UNIX )
2014-04-23 17:39:54 +11:00
2014-04-25 22:22:35 +11:00
set ( CPACK_PACKAGE_EXECUTABLES "openspades" "Launch OpenSpades" )
2013-10-06 16:24:43 +02:00
set ( CPACK_INCLUDE_TOPLEVEL_DIRECTORY FALSE ) #everyone hates a dir inside a zip named exactly like the zip
include ( CPack )