Add install, package and package_source targets to CMake

On Linux, `install` installs DDNet into the normal file system (root
rights required).

`package` tries to create an archive similar to today's release archives
and `package_source` tries to create a source archive similar to today's
source archives.
This commit is contained in:
heinrich5991 2017-08-01 21:55:49 +02:00
parent 58d1294b3c
commit 38c26de47b
2 changed files with 175 additions and 6 deletions

1
.gitignore vendored
View file

@ -64,6 +64,7 @@ DDNet-Server_d
DDNet-Server_sql
DDNet-Server_sql_d
/build
CMakeCache.txt
CMakeFiles
Makefile

View file

@ -1,5 +1,27 @@
cmake_minimum_required(VERSION 2.8)
project(DDNet)
file(STRINGS src/game/version.h VERSION_LINE
LIMIT_COUNT 1
REGEX GAME_RELEASE_VERSION
)
if(VERSION_LINE MATCHES "\"([0-9]+)\\.([0-9]+)\\.([0-9]+)\"")
set(VERSION_MAJOR ${CMAKE_MATCH_1})
set(VERSION_MINOR ${CMAKE_MATCH_2})
set(VERSION_PATCH ${CMAKE_MATCH_3})
else()
message(FATAL_ERROR "Couldn't parse version from src/game/version.h")
endif()
if(POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
project(DDNet VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
else()
project(DDNet)
set(PROJECT_VERSION_MAJOR ${VERSION_MAJOR})
set(PROJECT_VERSION_MINOR ${VERSION_MINOR})
set(PROJECT_VERSION_PATCH ${VERSION_PATCH})
endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
@ -304,10 +326,13 @@ endif()
########################################################################
file(COPY data DESTINATION .)
file(COPY ${CURL_COPY_FILES} DESTINATION .)
file(COPY ${FREETYPE_COPY_FILES} DESTINATION .)
file(COPY ${OPUSFILE_COPY_FILES} DESTINATION .)
file(COPY ${SDL2_COPY_FILES} DESTINATION .)
set(COPY_FILES
${CURL_COPY_FILES}
${FREETYPE_COPY_FILES}
${OPUSFILE_COPY_FILES}
${SDL2_COPY_FILES}
)
file(COPY ${COPY_FILES} DESTINATION .)
########################################################################
# CODE GENERATION
@ -834,13 +859,17 @@ foreach(ABS_T ${TOOLS})
if(T MATCHES "\\.cpp$")
string(REGEX REPLACE "\\.cpp$" "" TOOL "${T}")
set(EXTRA_TOOL_SRC)
set(EXCLUDE_FROM_ALL EXCLUDE_FROM_ALL)
if(TOOL MATCHES "^(tileset_|dilate|map_extract|map_replace_image$)")
list(APPEND EXTRA_TOOL_SRC ${DEP_PNG})
endif()
if(TOOL MATCHES "^config_")
list(APPEND EXTRA_TOOL_SRC "src/tools/config_common.h")
endif()
add_executable(${TOOL} EXCLUDE_FROM_ALL
if(TOOL MATCHES "^(config_retrieve|config_store|dilate|map_diff|map_extract)$")
set(EXCLUDE_FROM_ALL)
endif()
add_executable(${TOOL} ${EXCLUDE_FROM_ALL}
${DEPS}
src/tools/${TOOL}.cpp
${EXTRA_TOOL_SRC}
@ -887,6 +916,145 @@ if(GTEST_FOUND)
)
endif()
########################################################################
# INSTALLATION
########################################################################
function(escape_regex VAR STRING)
string(REGEX REPLACE "([][^$.+*?|()\\\\])" "\\\\\\1" ESCAPED "${STRING}")
set(${VAR} ${ESCAPED} PARENT_SCOPE)
endfunction()
function(max_length VAR)
set(MAX_LENGTH 0)
foreach(str ${ARGN})
string(LENGTH ${str} LENGTH)
if(LENGTH GREATER MAX_LENGTH)
set(MAX_LENGTH ${LENGTH})
endif()
endforeach()
set(${VAR} ${MAX_LENGTH} PARENT_SCOPE)
endfunction()
# Tries to generate a list of regex that matches everything except the given
# parameters.
function(regex_inverted VAR)
max_length(MAX_LENGTH ${ARGN})
math(EXPR UPPER_BOUND "${MAX_LENGTH}-1")
set(REMAINING ${ARGN})
set(RESULT)
foreach(i RANGE ${UPPER_BOUND})
set(TEMP ${REMAINING})
set(REMAINING)
foreach(str ${TEMP})
string(LENGTH ${str} LENGTH)
if(i LESS LENGTH)
list(APPEND REMAINING ${str})
endif()
endforeach()
set(ADDITIONAL)
foreach(outer ${REMAINING})
string(SUBSTRING ${outer} 0 ${i} OUTER_PREFIX)
set(CHARS "")
foreach(inner ${REMAINING})
string(SUBSTRING ${inner} 0 ${i} INNER_PREFIX)
if(OUTER_PREFIX STREQUAL INNER_PREFIX)
string(SUBSTRING ${inner} ${i} 1 INNER_NEXT)
set(CHARS "${CHARS}${INNER_NEXT}")
endif()
endforeach()
escape_regex(OUTER_PREFIX_ESCAPED "${OUTER_PREFIX}")
list(APPEND ADDITIONAL "${OUTER_PREFIX_ESCAPED}([^${CHARS}]|$)")
endforeach()
list(REMOVE_DUPLICATES ADDITIONAL)
list(APPEND RESULT ${ADDITIONAL})
endforeach()
set(${VAR} ${RESULT} PARENT_SCOPE)
endfunction()
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_VERBATIM_VARIABLES ON)
set(CPACK_GENERATOR TGZ TXZ)
set(CPACK_ARCHIVE_COMPONENT_INSTALL ON)
set(CPACK_COMPONENTS_ALL portable)
set(CPACK_SOURCE_GENERATOR ZIP TGZ TBZ2 TXZ)
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set(CPACK_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH})
set(CPACK_SYSTEM_NAME ${CMAKE_SYSTEM_NAME})
if(TARGET_OS AND TARGET_BITS)
if(TARGET_OS STREQUAL "windows")
set(CPACK_SYSTEM_NAME "win${TARGET_BITS}")
set(CPACK_GENERATOR ZIP)
elseif(TARGET_OS STREQUAL "linux")
# Assuming Intel here.
if(TARGET_BITS EQUAL 32)
set(CPACK_SYSTEM_NAME "linux_x86")
elseif(TARGET_BITS EQUAL 64)
set(CPACK_SYSTEM_NAME "linux_x86_64")
endif()
elseif(TARGET_OS STREQUAL "mac")
set(CPACK_SYSTEM_NAME "osx")
endif()
endif()
set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME})
set(CPACK_SOURCE_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-src)
set(CPACK_SOURCE_FILES
CMakeLists.txt
README.md
autoexec_server.cfg
bam.lua
cmake/
configure.lua
data/
datasrc/
ddnet-libs/
license.txt
other/
scripts/
src/
storage.cfg
)
set(CPACK_SOURCE_IGNORE_FILES
"\\.pyc$"
"/\\.git"
"/__pycache__/"
)
regex_inverted(CPACK_SOURCE_FILES_INVERTED ${CPACK_SOURCE_FILES})
escape_regex(PROJECT_SOURCE_DIR_ESCAPED ${PROJECT_SOURCE_DIR})
foreach(str ${CPACK_SOURCE_FILES_INVERTED})
list(APPEND CPACK_SOURCE_IGNORE_FILES "${PROJECT_SOURCE_DIR_ESCAPED}/${str}")
endforeach()
# Unset these variables, they might do something in the future of CPack.
unset(CPACK_SOURCE_FILES)
unset(CPACK_SOURCE_FILES_INVERTED)
set(CMAKE_INSTALL_DEFAULT_COMPONENT_NAME ${PROJECT_NAME})
install(TARGETS ${TARGET_CLIENT} ${TARGET_SERVER} DESTINATION bin)
install(DIRECTORY data DESTINATION share/DDNet)
set(EXTRA_ARGS DESTINATION ${CPACK_PACKAGE_FILE_NAME} COMPONENT portable EXCLUDE_FROM_ALL)
install(TARGETS ${TARGET_CLIENT} ${TARGET_SERVER} ${EXTRA_ARGS})
install(TARGETS config_retrieve config_store dilate map_diff map_extract ${EXTRA_ARGS} OPTIONAL)
install(DIRECTORY data ${EXTRA_ARGS})
install(FILES license.txt storage.cfg autoexec_server.cfg ${EXTRA_ARGS})
install(FILES ${COPY_FILES} ${EXTRA_ARGS})
if(TARGET_OS STREQUAL "windows")
install(FILES other/config_directory.bat ${EXTRA_ARGS})
endif()
include(CPack)
########################################################################
# COMPILER-SPECIFICS
########################################################################