Remove -Wno-reorder
[xonotic/netradiant.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
2 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
3 project(NetRadiant C CXX)
4
5 option(BUILD_RADIANT "Build the GUI" ON)
6
7 if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
8     set(CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/install" CACHE PATH "..." FORCE)
9 endif ()
10
11 #-----------------------------------------------------------------------
12 # Version
13 #-----------------------------------------------------------------------
14
15 # CMake 3.0+ would allow this in project()
16 set(NetRadiant_VERSION_MAJOR 1)
17 set(NetRadiant_VERSION_MINOR 5)
18 set(NetRadiant_VERSION_PATCH 0)
19 set(NetRadiant_VERSION "${NetRadiant_VERSION_MAJOR}.${NetRadiant_VERSION_MINOR}.${NetRadiant_VERSION_PATCH}")
20
21 file(WRITE "${PROJECT_BINARY_DIR}/RADIANT_MAJOR" ${NetRadiant_VERSION_MAJOR})
22 file(WRITE "${PROJECT_BINARY_DIR}/RADIANT_MINOR" ${NetRadiant_VERSION_MINOR})
23 file(WRITE "${PROJECT_BINARY_DIR}/RADIANT_PATCH" ${NetRadiant_VERSION_PATCH})
24
25 set(RADIANT_ABOUTMSG "Custom build" CACHE STRING "About message")
26
27 find_package(Git REQUIRED)
28 execute_process(
29         COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
30         WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
31         OUTPUT_VARIABLE GIT_VERSION
32         OUTPUT_STRIP_TRAILING_WHITESPACE
33 )
34 set(RADIANT_VERSION_STRING "${NetRadiant_VERSION}n")
35 if (GIT_VERSION)
36     set(RADIANT_VERSION_STRING "${RADIANT_VERSION_STRING}-git-${GIT_VERSION}")
37 endif ()
38
39 message(STATUS "Building ${PROJECT_NAME} ${RADIANT_VERSION_STRING} ${RADIANT_ABOUTMSG}")
40
41 #-----------------------------------------------------------------------
42 # Language standard
43 #-----------------------------------------------------------------------
44
45 set(CMAKE_CXX_STANDARD 11)
46 set(CMAKE_CXX_STANDARD_REQUIRED ON)
47 if (CMAKE_VERSION VERSION_LESS "3.1")
48     if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX)
49         include(CheckCXXCompilerFlag)
50         check_cxx_compiler_flag(--std=c++${CMAKE_CXX_STANDARD} STD_CXX)
51         if (STD_CXX)
52             set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++${CMAKE_CXX_STANDARD}")
53         else ()
54             message(SEND_ERROR "Requires C++${CMAKE_CXX_STANDARD} or better")
55         endif ()
56     else ()
57         message(WARNING "Unrecognized compiler: ${CMAKE_CXX_COMPILER_ID}, make sure it supports C++${CMAKE_CXX_STANDARD}")
58     endif ()
59 endif ()
60
61 #-----------------------------------------------------------------------
62 # Flags
63 #-----------------------------------------------------------------------
64
65 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
66 macro(addflags_c args)
67     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${args}")
68 endmacro()
69 macro(addflags_cxx args)
70     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${args}")
71 endmacro()
72 macro(addflags args)
73     addflags_c("${args}")
74     addflags_cxx("${args}")
75 endmacro()
76 addflags("-fno-strict-aliasing")
77 if (NOT WIN32)
78     addflags("-fvisibility=hidden")
79 endif ()
80
81 if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
82     addflags("-Werror")
83     addflags("-pedantic-errors")
84 endif ()
85
86 addflags("-Wall")
87 addflags("-Wextra")
88 addflags("-pedantic")
89
90 addflags_c("-Wno-deprecated-declarations") # vfs.c: g_strdown
91
92 addflags("-Wno-sign-compare")
93 addflags("-Wno-unused-function")
94 addflags("-Wno-unused-variable")
95 addflags("-Wno-unused-parameter")
96 addflags("-Wno-missing-field-initializers")
97
98 addflags_c("-Wno-int-conversion")
99 addflags_c("-Wno-pointer-to-int-cast")
100 addflags_c("-Wno-incompatible-pointer-types")
101
102 addflags_cxx("-Wno-delete-non-virtual-dtor")
103
104 set(CMAKE_POSITION_INDEPENDENT_CODE 1)
105 set(GTK_TARGET 2 CACHE STRING "GTK target")
106 add_definitions(-DGTK_TARGET=${GTK_TARGET})
107
108 #-----------------------------------------------------------------------
109 # Defs
110 #-----------------------------------------------------------------------
111
112 add_definitions(-DRADIANT_VERSION="${NetRadiant_VERSION}")
113 add_definitions(-DRADIANT_MAJOR_VERSION="${NetRadiant_VERSION_MAJOR}")
114 add_definitions(-DRADIANT_MINOR_VERSION="${NetRadiant_VERSION_MINOR}")
115 add_definitions(-DRADIANT_PATCH_VERSION="${NetRadiant_VERSION_PATCH}")
116
117 add_definitions(-DRADIANT_ABOUTMSG="${NetRadiant_ABOUT}")
118
119 if (NOT CMAKE_BUILD_TYPE MATCHES Release)
120     add_definitions(-D_DEBUG=1)
121 endif ()
122
123 macro(disable_deprecated name gtk2only)
124     add_definitions(-D${name}_DISABLE_SINGLE_INCLUDES)
125     if ((${gtk2only} EQUAL 0) OR (GTK_TARGET EQUAL 2))
126         add_definitions(-D${name}_DISABLE_DEPRECATED)
127     endif ()
128 endmacro()
129
130 disable_deprecated(ATK 0)
131 disable_deprecated(G 0)
132 disable_deprecated(GDK 0)
133 disable_deprecated(GDK_PIXBUF 0)
134 disable_deprecated(GTK 1)
135 disable_deprecated(PANGO 0)
136
137 if (APPLE)
138     option(XWINDOWS "Build against X11" ON)
139     add_definitions(
140             -DPOSIX=1
141     )
142 elseif (WIN32)
143     add_definitions(
144             -DWIN32=1
145             -D_WIN32=1
146     )
147 else ()
148     set(XWINDOWS ON)
149     add_definitions(
150             -DPOSIX=1
151     )
152 endif ()
153
154 if (XWINDOWS)
155     find_package(X11 REQUIRED)
156     include_directories(${X11_INCLUDE_DIR})
157     add_definitions(-DXWINDOWS=1)
158 endif ()
159
160 include_directories("${PROJECT_SOURCE_DIR}/include")
161 include_directories("${PROJECT_SOURCE_DIR}/libs")
162
163 if (WIN32 AND NOT CMAKE_CROSSCOMPILING)
164     set(BUNDLE_LIBRARIES_DEFAULT ON)
165 else ()
166     set(BUNDLE_LIBRARIES_DEFAULT OFF)
167 endif ()
168 option(BUNDLE_LIBRARIES "Bundle libraries" ${BUNDLE_LIBRARIES_DEFAULT})
169
170 macro(copy_dlls target)
171     if (BUNDLE_LIBRARIES)
172         add_custom_command(TARGET ${target} POST_BUILD
173                 COMMAND bash
174                 ARGS -c "ldd '$<TARGET_FILE:${target}>' | grep -v /c/Windows | awk '{ print $1 }' | while read dll; do cp \"$(which $dll)\" '${PROJECT_BINARY_DIR}'; done"
175                 VERBATIM
176                 )
177     endif ()
178 endmacro()
179
180 #-----------------------------------------------------------------------
181 # Libraries
182 #-----------------------------------------------------------------------
183
184 add_subdirectory(libs)
185 add_subdirectory(include)
186
187 #-----------------------------------------------------------------------
188 # Plugins
189 #-----------------------------------------------------------------------
190
191 if (BUILD_RADIANT)
192     add_subdirectory(contrib)
193 endif ()
194
195 #-----------------------------------------------------------------------
196 # Modules
197 #-----------------------------------------------------------------------
198
199 if (BUILD_RADIANT)
200     add_subdirectory(plugins)
201 endif ()
202
203 #-----------------------------------------------------------------------
204 # Radiant
205 #-----------------------------------------------------------------------
206
207 if (CMAKE_EXECUTABLE_SUFFIX)
208     string(REGEX REPLACE "^[.]" "" RADIANT_EXECUTABLE ${CMAKE_EXECUTABLE_SUFFIX})
209 else ()
210     execute_process(
211             COMMAND uname -m
212             OUTPUT_VARIABLE RADIANT_EXECUTABLE
213             OUTPUT_STRIP_TRAILING_WHITESPACE
214     )
215 endif ()
216
217 macro(radiant_tool name)
218     add_executable(${name} ${ARGN})
219     install(
220             TARGETS ${name}
221             RUNTIME DESTINATION .
222     )
223     if (NOT (CMAKE_EXECUTABLE_SUFFIX STREQUAL ".${RADIANT_EXECUTABLE}"))
224         add_custom_command(TARGET ${name} POST_BUILD
225                 COMMAND ln -f -s "$<TARGET_FILE_NAME:${name}>" "${PROJECT_BINARY_DIR}/${name}.${RADIANT_EXECUTABLE}"
226                 VERBATIM
227                 )
228         install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
229                 ${name}${CMAKE_EXECUTABLE_SUFFIX} ${CMAKE_INSTALL_PREFIX}/${name}.${RADIANT_EXECUTABLE})
230                 ")
231     endif ()
232 endmacro()
233
234 if (BUILD_RADIANT)
235     add_subdirectory(radiant _radiant)
236     set_target_properties(radiant PROPERTIES
237             COMPILE_DEFINITIONS RADIANT_EXECUTABLE="${RADIANT_EXECUTABLE}"
238             )
239 endif ()
240
241 #-----------------------------------------------------------------------
242 # Tools
243 #-----------------------------------------------------------------------
244
245 add_subdirectory(tools)
246
247 file(GLOB DATA_FILES "${PROJECT_SOURCE_DIR}/setup/data/tools/*")
248
249 if (NOT (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR))
250     # Copy data files from sources to the build directory
251     message(STATUS "Copying data files")
252     file(COPY ${DATA_FILES} DESTINATION "${PROJECT_BINARY_DIR}")
253 endif ()
254
255 #-----------------------------------------------------------------------
256 # Game packs
257 #-----------------------------------------------------------------------
258
259 option(DOWNLOAD_GAMEPACKS "Download game packs" ON)
260 add_custom_target(game_packs
261         COMMAND ${CMAKE_COMMAND} -E make_directory games
262         COMMAND DOWNLOAD_GAMEPACKS=yes SOURCE_DIR="${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/install-gamepacks.sh" "${PROJECT_BINARY_DIR}"
263         COMMENT "Downloading game packs"
264         )
265 if (DOWNLOAD_GAMEPACKS)
266     add_custom_target(game_packs_all ALL DEPENDS game_packs)
267 endif ()
268
269 #-----------------------------------------------------------------------
270 # Install
271 #-----------------------------------------------------------------------
272
273 install(
274         FILES
275         "${PROJECT_BINARY_DIR}/RADIANT_MAJOR"
276         "${PROJECT_BINARY_DIR}/RADIANT_MINOR"
277         "${PROJECT_BINARY_DIR}/RADIANT_PATCH"
278         DESTINATION .
279 )
280
281 install(
282         DIRECTORY
283         setup/data/tools/
284         docs
285         DESTINATION .
286 )
287
288 set(GAME_FILES
289         DarkPlaces
290         Nexuiz
291         OpenArena
292         Osirion
293         Q3
294         Quake2
295         Quake
296         Quetoo
297         Tremulous
298         UFOAI
299         Unvanquished
300         Warsow
301         Xonotic
302         )
303 unset(_tmp)
304 foreach (it ${GAME_FILES})
305     set(dir "${PROJECT_BINARY_DIR}/games/${it}Pack")
306     string(TOLOWER "${it}" it)
307     list(APPEND _tmp "${dir}/games")
308     list(APPEND _tmp "${dir}/${it}.game")
309 endforeach ()
310 set(GAME_FILES ${_tmp})
311
312 install(
313         DIRECTORY
314         ${GAME_FILES}
315         DESTINATION .
316         OPTIONAL
317 )
318
319 include(cmake/scripts/package.cmake)