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