forked from Return-To-The-Roots/s25client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
204 lines (164 loc) · 8.14 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
192
193
194
195
196
197
198
199
200
201
202
203
204
################################################################################
### $Id: CMakeLists.txt 8361 2012-09-30 16:52:07Z FloSoft $
################################################################################
CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0)
CMAKE_POLICY(SET CMP0003 OLD)
IF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 7 AND ${CMAKE_PATCH_VERSION} GREATER 0)
CMAKE_POLICY(SET CMP0015 OLD)
ENDIF(${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} GREATER 7 AND ${CMAKE_PATCH_VERSION} GREATER 0)
SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
SET(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH} ${CMAKE_SOURCE_DIR}/contrib)
SET(BOOST_INCLUDEDIR ${CMAKE_SOURCE_DIR}/contrib/boost)
SET(Boost_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/contrib)
INCLUDE(CMakeMacroSetCCache)
INCLUDE(CMakeMacroAddFlags)
INCLUDE(CMakeMacroForceAddFlags)
INCLUDE(CMakeMacroCorrectLib)
INCLUDE(CMakeMacroEnsureOutOfSourceBuild)
################################################################################
IF(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Windows" OR WIN32)
SET(COMPILEFOR_PLATFORM "windows")
SET(COMPILEFOR "windows")
SET(CROSSCOMPILE "0")
SET(CROSS "")
IF ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
SET(COMPILEARCH "x86_64")
ELSE ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
SET(COMPILEARCH "i386")
ENDIF ("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
ELSE()
INCLUDE(cmake/crosscompile.cmake)
ENDIF()
PROJECT(s25client)
################################################################################
SET(PREFIX ${PREFIX} CACHE STRING "Path prefix")
SET(BINDIR ${BINDIR} CACHE STRING "Directory for the binaries")
SET(DATADIR ${DATADIR} CACHE STRING "Data directory")
SET(LIBDIR ${LIBDIR} CACHE STRING "Directory for shared binaries")
SET(DRIVERDIR ${DRIVERDIR} CACHE STRING "Directory for driver objects")
IF (NOT "${PREFIX}" STREQUAL "" AND "${BINDIR}" STREQUAL "")
SET(BINDIR ${PREFIX}/bin CACHE STRING "Directory for the binaries" FORCE)
MESSAGE(STATUS "Set BINDIR to ${BINDIR}")
ENDIF (NOT "${PREFIX}" STREQUAL "" AND "${BINDIR}" STREQUAL "")
IF (NOT "${PREFIX}" STREQUAL "" AND "${DATADIR}" STREQUAL "")
SET(DATADIR ${PREFIX}/share/s25rttr CACHE STRING "Data directory" FORCE)
MESSAGE(STATUS "Set DATADIR to ${DATADIR}")
ENDIF (NOT "${PREFIX}" STREQUAL "" AND "${DATADIR}" STREQUAL "")
IF (NOT "${DATADIR}" STREQUAL "" AND "${LIBDIR}" STREQUAL "")
SET(LIBDIR ${DATADIR} CACHE STRING "Directory for shared binaries" FORCE)
MESSAGE(STATUS "Set LIBDIR to ${LIBDIR}")
ENDIF (NOT "${DATADIR}" STREQUAL "" AND "${LIBDIR}" STREQUAL "")
IF (NOT "${LIBDIR}" STREQUAL "" AND "${DRIVERDIR}" STREQUAL "")
SET(DRIVERDIR "${LIBDIR}/driver" CACHE STRING "Directory for driver objects" FORCE)
MESSAGE(STATUS "Set DRIVERDIR to ${DRIVERDIR}")
ENDIF (NOT "${LIBDIR}" STREQUAL "" AND "${DRIVERDIR}" STREQUAL "")
# avoid lhs-path bug in windows
IF ("${COMPILEFOR}" STREQUAL "windows")
SET(CMAKE_INSTALL_PREFIX "" CACHE STRING "" FORCE)
ENDIF ("${COMPILEFOR}" STREQUAL "windows")
IF(NOT "$ENV{CMAKE_INSTALL_PREFIX}" STREQUAL "")
SET(ENV{DESTDIR} "$ENV{CMAKE_INSTALL_PREFIX}" CACHE STRING "" FORCE)
MESSAGE(STATUS "Set DESTDIR to $ENV{DESTDIR}")
ENDIF(NOT "$ENV{CMAKE_INSTALL_PREFIX}" STREQUAL "")
IF(NOT "$ENV{DESTDIR}" STREQUAL "")
SET(ENV{DESTDIR} "$ENV{DESTDIR}/" CACHE STRING "" FORCE)
SET(CMAKE_INSTALL_PREFIX "" CACHE STRING "" FORCE)
MESSAGE(STATUS "Corrected DESTDIR to $ENV{DESTDIR}")
ENDIF(NOT "$ENV{DESTDIR}" STREQUAL "")
# ensure out of source build
ENSURE_OUT_OF_SOURCE_BUILD("${PROJECT_NAME} requires an out of source build. Please go to the build directory and run './cmake.sh [options]' there.")
# Build lobby client
SET (LOBBY_C TRUE)
################################################################################
INCLUDE(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-Wall -Werror -pedantic -Wno-long-long -fno-strict-aliasing" WERROR_FLAGS)
IF (WERROR_FLAGS)
IF (NOT "${COMPILEFOR}" STREQUAL "windows" )
ADD_DEFINITIONS(-Wall -pedantic -fno-strict-aliasing)
ELSE (NOT "${COMPILEFOR}" STREQUAL "windows" )
ADD_DEFINITIONS(-Wall -pedantic -Wno-long-long) # win32 cross build with -Werror does not work
ENDIF (NOT "${COMPILEFOR}" STREQUAL "windows" )
ENDIF (WERROR_FLAGS)
# avoid lhs-path bug in windows
IF ("${COMPILEFOR}" STREQUAL "windows")
SET(BINDIR "." CACHE STRING "" FORCE)
SET(DATADIR "." CACHE STRING "" FORCE)
SET(LIBDIR "." CACHE STRING "" FORCE)
SET(DRIVERDIR "./driver" CACHE STRING "" FORCE)
#ADD_DEFINITIONS(-D_WIN32_WINNT=0x0501)
ENDIF ("${COMPILEFOR}" STREQUAL "windows")
# add build directory to compiler search path
FORCE_ADD_FLAGS(CMAKE_C_FLAGS -I${CMAKE_BINARY_DIR})
FORCE_ADD_FLAGS(CMAKE_CXX_FLAGS -I${CMAKE_BINARY_DIR})
IF (MSVC)
# disable MSVC "use secure function" and 4250: 'class1' : inherits 'class2::member' via dominance (virtual inheritance related)
ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS /wd"4250")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Oi /GL") # systemintern functions for faster code; Optimize whole program
# Strip unused symbols and us COMDAT folding
SET(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /OPT:REF /OPT:ICF")
SET(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} /OPT:REF /OPT:ICF")
SET(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /OPT:REF /OPT:ICF")
# Add optimized debugging features
IF (MSVC_VERSION GREATER 1800) #VS13
ADD_DEFINITIONS(/d2Zi+)
ELSEIF (NOT(MSVC_VERSION LESS 1800)) # VS12
ADD_DEFINITIONS(/Zo)
ENDIF()
ENDIF (MSVC)
################################################################################
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/build_paths.h.cmake"
build_paths.h)
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/build_version.h.cmake"
build_version.h)
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/build/preinstall.sh.cmake"
preinstall.sh @ONLY)
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/build/postinstall.sh.cmake"
postinstall.sh @ONLY)
################################################################################
ADD_SUBDIRECTORY(version)
ADD_CUSTOM_TARGET(updateversion ALL
COMMAND "$<TARGET_FILE:version>" "${CMAKE_SOURCE_DIR}"
DEPENDS version
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
)
IF(NOT ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Windows")
ADD_CUSTOM_TARGET(mrproper
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/build/cleanup.sh"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
)
ADD_CUSTOM_TARGET(create_nightly
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/release/create_release.sh" "nightly" "${CMAKE_SOURCE_DIR}"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
)
ADD_CUSTOM_TARGET(create_stable
COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/release/create_release.sh" "stable" "${CMAKE_SOURCE_DIR}"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
)
# preinstall script
INSTALL(SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/cmake/preinstall.cmake")
ENDIF()
################################################################################
ADD_SUBDIRECTORY(driver)
ADD_SUBDIRECTORY(libendian)
ADD_SUBDIRECTORY(mygettext)
ADD_SUBDIRECTORY(libsiedler2)
ADD_SUBDIRECTORY(libutil)
ADD_SUBDIRECTORY(liblobby)
ADD_SUBDIRECTORY(s-c)
ADD_SUBDIRECTORY(s25update)
ADD_SUBDIRECTORY(src)
################################################################################
# postinstall script-bug workaround, including sub-install-scripts manually
INSTALL(CODE "INCLUDE(driver/cmake_install.cmake)")
INSTALL(CODE "INCLUDE(libsiedler2/cmake_install.cmake)")
INSTALL(CODE "INCLUDE(s-c/cmake_install.cmake)")
INSTALL(CODE "INCLUDE(s25update/cmake_install.cmake)")
INSTALL(CODE "INCLUDE(src/cmake_install.cmake)")
# and then dont let him install anything
INSTALL(CODE "SET(CMAKE_INSTALL_LOCAL_ONLY 1)")
IF(NOT ${CMAKE_HOST_SYSTEM_NAME} MATCHES "Windows")
# postinstall script
INSTALL(SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/cmake/postinstall.cmake")
ENDIF()
INSTALL(CODE "MESSAGE(STATUS \"Installation is now complete\")")
################################################################################