-
Notifications
You must be signed in to change notification settings - Fork 99
/
CMakeLists.txt
191 lines (159 loc) · 6.16 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(mineserver)
CMAKE_POLICY(SET CMP0003 NEW)
#
# project version
#
# Justasic: Get the git revision location for the branch we're on
if(EXISTS "${${PROJECT_NAME}_SOURCE_DIR}/.git/HEAD")
file(STRINGS ${${PROJECT_NAME}_SOURCE_DIR}/.git/HEAD GIT_HEAD_LOC REGEX ".*")
#file(GIT_HEAD_LOC ${${PROJECT_NAME}_SOURCE_DIR}/.git/HEAD REGEX ".*")
string(LENGTH ${GIT_HEAD_LOC} HEAD_LEN)
math(EXPR LEN "${HEAD_LEN} - 5")
string(SUBSTRING ${GIT_HEAD_LOC} 5 ${LEN} GIT_HEAD)
endif(EXISTS "${${PROJECT_NAME}_SOURCE_DIR}/.git/HEAD")
# Justasic: Get the git revision we're on for the version string
if(EXISTS "${${PROJECT_NAME}_SOURCE_DIR}/.git/${GIT_HEAD}")
# Justasic: read_from_file(${${PROJECT_NAME}_SOURCE_DIR}/.git/${GIT_HEAD} ".*" VERSION_STR)
file(STRINGS ${${PROJECT_NAME}_SOURCE_DIR}/.git/${GIT_HEAD} VERSION_STR REGEX ".*")
# Justasic: Get the length of the string
string(LENGTH ${VERSION_STR} VERSION_LEN)
# Justasic: Subtract 7 from the string's length
math(EXPR VERSION_NUM_LEN "${VERSION_LEN} - ${VERSION_LEN} + 7")
# Justasic: Extract the value from the string
string(SUBSTRING ${VERSION_STR} 0 ${VERSION_NUM_LEN} VERSION_GIT)
endif(EXISTS "${${PROJECT_NAME}_SOURCE_DIR}/.git/${GIT_HEAD}")
# Set the actual version strings, these are used inside the program later
SET(${PROJECT_NAME}_MAJOR_VERSION 0)
SET(${PROJECT_NAME}_MINOR_VERSION 2)
SET(${PROJECT_NAME}_PATCH_LEVEL 0)
# Justasic: the rest is automatic
SET(${PROJECT_NAME}_VERSION_SIMPLE "${${PROJECT_NAME}_MAJOR_VERSION}.${${PROJECT_NAME}_MINOR_VERSION}.${${PROJECT_NAME}_PATCH_LEVEL}")
# Justasic: Get the git revision as well, really only useful for locating what revision we're on
SET(${PROJECT_NAME}_VERSION_COMPLETE "${${PROJECT_NAME}_VERSION_SIMPLE}-${VERSION_GIT}")
# set default build to Debug
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE Debug
CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE
)
ENDIF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}")
#
# Configure paths
#
SET(CONFIG_DIR_BIN bin/)
SET(CONFIG_DIR_ETC etc/${PROJECT_NAME}/)
SET(CONFIG_DIR_LIB lib/${PROJECT_NAME}/)
SET(CONFIG_DIR_SHARE ./)
IF(WIN32)
MESSAGE(STATUS "CONFIG_LOCAL is set -- assuming local build")
SET(CONFIG_DIR_BIN bin/)
SET(CONFIG_DIR_ETC bin/)
SET(CONFIG_DIR_LIB bin/)
SET(CONFIG_DIR_SHARE ./)
SET(CONFIG_PREFIX ${CMAKE_INSTALL_PREFIX})
ENDIF()
# The DISTSOURCE parameter tells the executable where to find the factory defaults.
# It is used by Mineserver::configDirectoryPrepare() to install the factory defaults.
# In the Release build, this should eventually be overridden by a central location
# like $PREFIX/share/mineserver/files, I suppose.
SET(CONFIG_DIR_DISTSOURCE files)
#
# Include directories
#
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/src)
# CMake crap to include
include(CheckFunctionExists)
include(CheckIncludeFile)
include(CheckTypeSize)
include(CheckLibraryExists)
include(CheckCXXCompilerFlag)
# functions/includes needed during compile
check_function_exists(backtrace HAVE_BACKTRACE)
check_include_file(sys/utsname.h HAVE_SYS_UTSNAME_H)
# Output paths
SET(EXECUTABLE_OUTPUT_PATH bin)
SET(LIBRARY_OUTPUT_PATH bin)
# Set compiler specific build flags
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(CMAKE_CXX_FLAGS "-W -Wall -Wno-unused-variable -Wno-unused-parameter -pedantic -std=c++11")
SET(CMAKE_CXX_FLAGS_DEBUG "-DDEBUG -g -O0")
SET(CMAKE_CXX_FLAGS_PROFILE "-DDEBUG -g -pg")
SET(CMAKE_CXX_FLAGS_RELEASE "-O4 -s -DNDEBUG")
ENDIF()
IF(MSVC_IDE)
SET(CMAKE_CXX_FLAGS "/DWIN32 /D_CONSOLE /DZLIB_WINAPI /fp:fast /EHsc")
SET(CMAKE_CXX_FLAGS_DEBUG "/DDEBUG /D_DEBUG /MTd /Zi")
SET(CMAKE_CXX_FLAGS_RELEASE "/MT /D_SECURE_SCL=0")
ENDIF(MSVC_IDE)
#
# dependencies
#
SET(TARGET ${PROJECT_NAME})
SET(mineserver_depends -lpthread)
# Note that on Ubuntu systems, CMake's FindOpenSSL.cmake file does not define
# all the proper defines, therefore our old and generic library finder does not
# work like it should :< - Justasic
Find_package(OpenSSL REQUIRED)
Find_package(Event REQUIRED)
Find_package(Noise REQUIRED)
Find_package(ZLIB REQUIRED)
include_directories(${ZLIB_INCLUDE_DIR} ${NOISE_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR} ${EVENT_INCLUDE_DIR})
LIST(APPEND mineserver_depends "${ZLIB_LIBRARY};${NOISE_LIBRARY};${OPENSSL_LIBRARIES};${EVENT_LIBRARY}")
# preprocess configuration file
CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/src/configure.h.in ${PROJECT_BINARY_DIR}/src/configure.h)
#
# platform-specific tweaks
#
IF(WIN32)
# this requires WinMain() entry, disabled until console/GUI option is added
#set(exe "WIN32")
# this shouldn't be here, but can cmake find these .lib's?
# do we really need winmm?
FOREACH(lib ws2_32 winmm)
STRING(TOUPPER ${lib} LIB)
LIST(APPEND mineserver_depends "${lib}")
SET(${LIB}_LIBRARY "${lib}")
ENDFOREACH()
ELSE()
IF(NOISE_DIR_IS_LIBNOISE)
ADD_DEFINITIONS(-DLIBNOISE)
ENDIF()
ENDIF()
#
# Create some directories we need
#
FILE(MAKE_DIRECTORY "${CONFIG_DIR_BIN}/plugins")
#
# subdirectories to build
#
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(plugins)
ADD_SUBDIRECTORY(files)
# In the Debug build, we provide a local config file.
#IF(CMAKE_BUILD_TYPE MATCHES Debug)
#CONFIGURE_FILE(files/config.cfg "${EXECUTABLE_OUTPUT_PATH}/config.cfg" COPYONLY)
#CONFIGURE_FILE(files/item_alias.cfg "${EXECUTABLE_OUTPUT_PATH}/item_alias.cfg" COPYONLY)
#ENDIF()
#
# install
#
install(FILES ${mineserver_configs}
DESTINATION ${CONFIG_DIR_ETC}/
)
install(DIRECTORY ${mineserver_dirs}
DESTINATION ${CONFIG_DIR_SHARE}/
)
#
# cpack
#
set(CPACK_PACKAGE_VENDOR "The Mineserver Project")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Mineserver Developers <[email protected]>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Mineserver - C++ Minecraft server software")
set(CPACK_PACKAGE_VERSION ${${PROJECT_NAME}_MAJOR_VERSION}.${${PROJECT_NAME}_MINOR_VERSION}.${${PROJECT_NAME}_PATCH_LEVEL})
set(CPACK_PACKAGE_VERSION_MAJOR ${${PROJECT_NAME}_MAJOR_VERSION})
set(CPACK_PACKAGE_VERSION_MINOR ${${PROJECT_NAME}_MINOR_VERSION})
set(CPACK_PACKAGE_VERSION_PATCH ${${PROJECT_NAME}_PATCH_LEVEL})
set(CPACK_PACKAGE_INSTALL_DIRECTORY "/usr/local/bin")
include(CPack)