Remove -Wno-extra
[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("-Wno-switch")
91 addflags("-Wno-pedantic")
92 addflags("-Wno-parentheses")
93 addflags("-Wno-sign-compare")
94 addflags("-Wno-write-strings")
95 addflags("-Wno-unused-function")
96 addflags("-Wno-unused-variable")
97 addflags("-Wno-unused-parameter")
98 addflags("-Wno-deprecated-declarations")
99 addflags("-Wno-unused-but-set-variable")
100 addflags("-Wno-missing-field-initializers")
101
102 addflags_c("-Wno-int-conversion")
103 addflags_c("-Wno-pointer-to-int-cast")
104 addflags_c("-Wno-incompatible-pointer-types")
105
106 addflags_cxx("-Wno-reorder")
107 addflags_cxx("-Wno-delete-non-virtual-dtor")
108
109 set(CMAKE_POSITION_INDEPENDENT_CODE 1)
110 set(GTK_TARGET 2 CACHE STRING "GTK target")
111 add_definitions(-DGTK_TARGET=${GTK_TARGET})
112
113 #-----------------------------------------------------------------------
114 # Defs
115 #-----------------------------------------------------------------------
116
117 add_definitions(-DRADIANT_VERSION="${NetRadiant_VERSION}")
118 add_definitions(-DRADIANT_MAJOR_VERSION="${NetRadiant_VERSION_MAJOR}")
119 add_definitions(-DRADIANT_MINOR_VERSION="${NetRadiant_VERSION_MINOR}")
120 add_definitions(-DRADIANT_PATCH_VERSION="${NetRadiant_VERSION_PATCH}")
121
122 add_definitions(-DRADIANT_ABOUTMSG="${NetRadiant_ABOUT}")
123
124 if (NOT CMAKE_BUILD_TYPE MATCHES Release)
125     add_definitions(-D_DEBUG=1)
126 endif ()
127
128 macro(disable_deprecated name gtk2only)
129     add_definitions(-D${name}_DISABLE_SINGLE_INCLUDES)
130     if ((${gtk2only} EQUAL 0) OR (GTK_TARGET EQUAL 2))
131         add_definitions(-D${name}_DISABLE_DEPRECATED)
132     endif ()
133 endmacro()
134
135 disable_deprecated(ATK 0)
136 disable_deprecated(G 0)
137 disable_deprecated(GDK 0)
138 disable_deprecated(GDK_PIXBUF 0)
139 disable_deprecated(GTK 1)
140 disable_deprecated(PANGO 0)
141
142 if (APPLE)
143     option(XWINDOWS "Build against X11" ON)
144     add_definitions(
145             -DPOSIX=1
146     )
147 elseif (WIN32)
148     add_definitions(
149             -DWIN32=1
150             -D_WIN32=1
151     )
152 else ()
153     set(XWINDOWS ON)
154     add_definitions(
155             -DPOSIX=1
156     )
157 endif ()
158
159 if (XWINDOWS)
160     find_package(X11 REQUIRED)
161     include_directories(${X11_INCLUDE_DIR})
162     add_definitions(-DXWINDOWS=1)
163 endif ()
164
165 include_directories("${PROJECT_SOURCE_DIR}/include")
166 include_directories("${PROJECT_SOURCE_DIR}/libs")
167
168 if (WIN32 AND NOT CMAKE_CROSSCOMPILING)
169     set(BUNDLE_LIBRARIES_DEFAULT ON)
170 else ()
171     set(BUNDLE_LIBRARIES_DEFAULT OFF)
172 endif ()
173 option(BUNDLE_LIBRARIES "Bundle libraries" ${BUNDLE_LIBRARIES_DEFAULT})
174
175 macro(copy_dlls target)
176     if (BUNDLE_LIBRARIES)
177         add_custom_command(TARGET ${target} POST_BUILD
178                 COMMAND bash
179                 ARGS -c "ldd '$<TARGET_FILE:${target}>' | grep -v /c/Windows | awk '{ print $1 }' | while read dll; do cp \"$(which $dll)\" '${PROJECT_BINARY_DIR}'; done"
180                 VERBATIM
181                 )
182     endif ()
183 endmacro()
184
185 #-----------------------------------------------------------------------
186 # Libraries
187 #-----------------------------------------------------------------------
188
189 add_subdirectory(libs)
190 add_subdirectory(include)
191
192 #-----------------------------------------------------------------------
193 # Plugins
194 #-----------------------------------------------------------------------
195
196 if (BUILD_RADIANT)
197     add_subdirectory(contrib)
198 endif ()
199
200 #-----------------------------------------------------------------------
201 # Modules
202 #-----------------------------------------------------------------------
203
204 if (BUILD_RADIANT)
205     add_subdirectory(plugins)
206 endif ()
207
208 #-----------------------------------------------------------------------
209 # Radiant
210 #-----------------------------------------------------------------------
211
212 if (CMAKE_EXECUTABLE_SUFFIX)
213     string(REGEX REPLACE "^[.]" "" RADIANT_EXECUTABLE ${CMAKE_EXECUTABLE_SUFFIX})
214 else ()
215     execute_process(
216             COMMAND uname -m
217             OUTPUT_VARIABLE RADIANT_EXECUTABLE
218             OUTPUT_STRIP_TRAILING_WHITESPACE
219     )
220 endif ()
221
222 macro(radiant_tool name)
223     add_executable(${name} ${ARGN})
224     install(
225             TARGETS ${name}
226             RUNTIME DESTINATION .
227     )
228     if (NOT (CMAKE_EXECUTABLE_SUFFIX STREQUAL ".${RADIANT_EXECUTABLE}"))
229         add_custom_command(TARGET ${name} POST_BUILD
230                 COMMAND ln -f -s "$<TARGET_FILE_NAME:${name}>" "${PROJECT_BINARY_DIR}/${name}.${RADIANT_EXECUTABLE}"
231                 VERBATIM
232                 )
233         install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
234                 ${name}${CMAKE_EXECUTABLE_SUFFIX} ${CMAKE_INSTALL_PREFIX}/${name}.${RADIANT_EXECUTABLE})
235                 ")
236     endif ()
237 endmacro()
238
239 if (BUILD_RADIANT)
240     add_subdirectory(radiant _radiant)
241     set_target_properties(radiant PROPERTIES
242             COMPILE_DEFINITIONS RADIANT_EXECUTABLE="${RADIANT_EXECUTABLE}"
243             )
244 endif ()
245
246 #-----------------------------------------------------------------------
247 # Tools
248 #-----------------------------------------------------------------------
249
250 add_subdirectory(tools)
251
252 file(GLOB DATA_FILES "${PROJECT_SOURCE_DIR}/setup/data/tools/*")
253
254 if (NOT (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR))
255     # Copy data files from sources to the build directory
256     message(STATUS "Copying data files")
257     file(COPY ${DATA_FILES} DESTINATION "${PROJECT_BINARY_DIR}")
258 endif ()
259
260 #-----------------------------------------------------------------------
261 # Game packs
262 #-----------------------------------------------------------------------
263
264 option(DOWNLOAD_GAMEPACKS "Download game packs" ON)
265 add_custom_target(game_packs
266         COMMAND ${CMAKE_COMMAND} -E make_directory games
267         COMMAND DOWNLOAD_GAMEPACKS=yes SOURCE_DIR="${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/install-gamepacks.sh" "${PROJECT_BINARY_DIR}"
268         COMMENT "Downloading game packs"
269         )
270 if (DOWNLOAD_GAMEPACKS)
271     add_custom_target(game_packs_all ALL DEPENDS game_packs)
272 endif ()
273
274 #-----------------------------------------------------------------------
275 # Install
276 #-----------------------------------------------------------------------
277
278 install(
279         FILES
280         "${PROJECT_BINARY_DIR}/RADIANT_MAJOR"
281         "${PROJECT_BINARY_DIR}/RADIANT_MINOR"
282         "${PROJECT_BINARY_DIR}/RADIANT_PATCH"
283         DESTINATION .
284 )
285
286 install(
287         DIRECTORY
288         setup/data/tools/
289         docs
290         DESTINATION .
291 )
292
293 set(GAME_FILES
294         DarkPlaces
295         Nexuiz
296         OpenArena
297         Osirion
298         Q3
299         Quake2
300         Quake
301         Quetoo
302         Tremulous
303         UFOAI
304         Unvanquished
305         Warsow
306         Xonotic
307         )
308 unset(_tmp)
309 foreach (it ${GAME_FILES})
310     set(dir "${PROJECT_BINARY_DIR}/games/${it}Pack")
311     string(TOLOWER "${it}" it)
312     list(APPEND _tmp "${dir}/games")
313     list(APPEND _tmp "${dir}/${it}.game")
314 endforeach ()
315 set(GAME_FILES ${_tmp})
316
317 install(
318         DIRECTORY
319         ${GAME_FILES}
320         DESTINATION .
321         OPTIONAL
322 )
323
324 include(cmake/scripts/package.cmake)