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