Propagate ui::Window
[xonotic/netradiant.git] / CMakeLists.txt
1 cmake_minimum_required(VERSION 2.8.11 FATAL_ERROR)
2 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
3
4 project(NetRadiant C CXX)
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 # For some reason the above flags don't really work...
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
60 #-----------------------------------------------------------------------
61 # Flags
62 #-----------------------------------------------------------------------
63
64 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
65 macro(addflags args)
66     set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${args}")
67     set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${args}")
68 endmacro()
69 addflags("-fno-strict-aliasing")
70 if (NOT WIN32)
71     addflags("-fvisibility=hidden")
72 endif ()
73
74 set(CMAKE_POSITION_INDEPENDENT_CODE 1)
75 set(GTK_NS "GTK2" CACHE STRING "GTK variable prefix")
76
77 #-----------------------------------------------------------------------
78 # Defs
79 #-----------------------------------------------------------------------
80
81 add_definitions(-DRADIANT_VERSION="${NetRadiant_VERSION}")
82 add_definitions(-DRADIANT_MAJOR_VERSION="${NetRadiant_VERSION_MAJOR}")
83 add_definitions(-DRADIANT_MINOR_VERSION="${NetRadiant_VERSION_MINOR}")
84 add_definitions(-DRADIANT_PATCH_VERSION="${NetRadiant_VERSION_PATCH}")
85
86 add_definitions(-DRADIANT_ABOUTMSG="${NetRadiant_ABOUT}")
87
88 if (NOT CMAKE_BUILD_TYPE MATCHES Release)
89     add_definitions(-D_DEBUG=1)
90 endif ()
91
92 add_definitions(
93     -DGTK_DISABLE_SINGLE_INCLUDES
94     -DGDK_PIXBUF_DISABLE_SINGLE_INCLUDES
95     -DGSEAL_ENABLE
96     -DGTK_DISABLE_DEPRECATED
97     -DGDK_DISABLE_DEPRECATED
98 )
99
100 if (APPLE)
101     option(XWINDOWS "Build against X11" ON)
102     add_definitions(
103             -DPOSIX=1
104     )
105 elseif (WIN32)
106     add_definitions(
107             -DWIN32=1
108             -D_WIN32=1
109     )
110 else ()
111     set(XWINDOWS ON)
112     add_definitions(
113             -DPOSIX=1
114     )
115 endif ()
116
117 if (XWINDOWS)
118     find_package(X11 REQUIRED)
119     include_directories(${X11_INCLUDE_DIR})
120     add_definitions(-DXWINDOWS=1)
121 endif ()
122
123 include_directories("${PROJECT_SOURCE_DIR}/include")
124 include_directories("${PROJECT_SOURCE_DIR}/libs")
125
126 if (WIN32 AND NOT CMAKE_CROSSCOMPILING)
127     set(BUNDLE_LIBRARIES_DEFAULT ON)
128 else ()
129     set(BUNDLE_LIBRARIES_DEFAULT OFF)
130 endif ()
131 option(BUNDLE_LIBRARIES "Bundle libraries" ${BUNDLE_LIBRARIES_DEFAULT})
132
133 macro(copy_dlls target)
134     if (BUNDLE_LIBRARIES)
135         add_custom_command(TARGET ${target} POST_BUILD
136                 COMMAND bash
137                 ARGS -c "ldd '$<TARGET_FILE:${target}>' | grep -v /c/Windows | awk '{ print $1 }' | while read dll; do cp \"$(which $dll)\" '${PROJECT_BINARY_DIR}'; done"
138                 VERBATIM
139                 )
140     endif ()
141 endmacro()
142
143 #-----------------------------------------------------------------------
144 # Libraries
145 #-----------------------------------------------------------------------
146
147 add_subdirectory(libs)
148 add_subdirectory(include)
149
150 #-----------------------------------------------------------------------
151 # Plugins
152 #-----------------------------------------------------------------------
153
154 if (BUILD_RADIANT)
155     add_subdirectory(contrib)
156 endif ()
157
158 #-----------------------------------------------------------------------
159 # Modules
160 #-----------------------------------------------------------------------
161
162 if (BUILD_RADIANT)
163     add_subdirectory(plugins)
164 endif ()
165
166 #-----------------------------------------------------------------------
167 # Radiant
168 #-----------------------------------------------------------------------
169
170 if (CMAKE_EXECUTABLE_SUFFIX)
171     string(REGEX REPLACE "^[.]" "" RADIANT_EXECUTABLE ${CMAKE_EXECUTABLE_SUFFIX})
172 else ()
173     execute_process(
174             COMMAND uname -m
175             OUTPUT_VARIABLE RADIANT_EXECUTABLE
176             OUTPUT_STRIP_TRAILING_WHITESPACE
177     )
178 endif ()
179
180 macro(radiant_tool name)
181     add_executable(${name} ${ARGN})
182     install(
183             TARGETS ${name}
184             RUNTIME DESTINATION .
185     )
186     if (NOT (CMAKE_EXECUTABLE_SUFFIX STREQUAL ".${RADIANT_EXECUTABLE}"))
187         add_custom_command(TARGET ${name} POST_BUILD
188                 COMMAND ln -f -s "$<TARGET_FILE_NAME:${name}>" "${PROJECT_BINARY_DIR}/${name}.${RADIANT_EXECUTABLE}"
189                 VERBATIM
190                 )
191         install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink \
192             ${name}${CMAKE_EXECUTABLE_SUFFIX} \
193             ${CMAKE_INSTALL_PREFIX}/${name}.${RADIANT_EXECUTABLE} \
194         )")
195     endif ()
196 endmacro()
197
198 if (BUILD_RADIANT)
199     add_subdirectory(radiant build)
200     set_target_properties(radiant PROPERTIES
201             COMPILE_DEFINITIONS RADIANT_EXECUTABLE="${RADIANT_EXECUTABLE}"
202             )
203 endif ()
204
205 #-----------------------------------------------------------------------
206 # Tools
207 #-----------------------------------------------------------------------
208
209 add_subdirectory(tools)
210
211 file(GLOB DATA_FILES "${PROJECT_SOURCE_DIR}/setup/data/tools/*")
212
213 if (NOT (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR))
214     # Copy data files from sources to the build directory
215     message(STATUS "Copying data files")
216     file(COPY ${DATA_FILES} DESTINATION "${PROJECT_BINARY_DIR}")
217 endif ()
218
219 #-----------------------------------------------------------------------
220 # Game packs
221 #-----------------------------------------------------------------------
222
223 option(DOWNLOAD_GAMEPACKS "Download game packs" ON)
224 add_custom_target(game_packs
225         COMMAND ${CMAKE_COMMAND} -E make_directory games
226         COMMAND DOWNLOAD_GAMEPACKS=yes SOURCE_DIR="${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/install-gamepacks.sh" "${PROJECT_BINARY_DIR}"
227         COMMENT "Downloading game packs"
228         )
229 if (DOWNLOAD_GAMEPACKS)
230     add_custom_target(game_packs_all ALL DEPENDS game_packs)
231 endif ()
232
233 #-----------------------------------------------------------------------
234 # Install
235 #-----------------------------------------------------------------------
236
237 install(
238         FILES
239         "${PROJECT_BINARY_DIR}/RADIANT_MAJOR"
240         "${PROJECT_BINARY_DIR}/RADIANT_MINOR"
241         "${PROJECT_BINARY_DIR}/RADIANT_PATCH"
242         DESTINATION ${CMAKE_INSTALL_PREFIX}
243 )
244
245 install(
246         DIRECTORY
247         ${PROJECT_SOURCE_DIR}/setup/data/tools/
248         ${PROJECT_SOURCE_DIR}/docs
249         DESTINATION ${CMAKE_INSTALL_PREFIX}
250 )
251
252 set(GAME_FILES
253         DarkPlaces
254         Nexuiz
255         OpenArena
256         Osirion
257         Q3
258         Quake2
259         Quake
260         Quetoo
261         Tremulous
262         UFOAI
263         Unvanquished
264         Warsow
265         Xonotic
266         )
267 unset(_tmp)
268 foreach (it ${GAME_FILES})
269     set(dir "${PROJECT_BINARY_DIR}/games/${it}Pack")
270     string(TOLOWER "${it}" it)
271     list(APPEND _tmp "${dir}/games")
272     list(APPEND _tmp "${dir}/${it}.game")
273 endforeach ()
274 set(GAME_FILES ${_tmp})
275
276 install(
277         DIRECTORY
278         ${GAME_FILES}
279         DESTINATION ${CMAKE_INSTALL_PREFIX}
280         OPTIONAL
281 )