1 cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
3 project(NetRadiant C CXX)
5 #-----------------------------------------------------------------------
6 # Builtins: configuration
7 #-----------------------------------------------------------------------
9 set(BUILTINS_INSTALL_DIR "${CMAKE_BINARY_DIR}/builtins")
10 set(BUILTINS_INCLUDE_DIR "${BUILTINS_INSTALL_DIR}/include")
11 set(BUILTINS_LIB_DIR "${BUILTINS_INSTALL_DIR}/lib")
12 set(BUILTINS_PKGCONFIG_DIR "${BUILTINS_INSTALL_DIR}/lib/pkgconfig")
14 option(BUILTIN_GTKGLEXT "Builtin GtkGLExt" OFF)
15 option(BUILTIN_GTKTHEME_MOJAVE "Builtin Mojave GTK theme" OFF)
18 set(BUILTIN_GTKGLEXT ON)
19 set(BUILTIN_GTKTHEME_MOJAVE ON)
22 set(BUILTIN_GTKGLEXT_BUILT OFF CACHE INTERNAL "...")
23 if (EXISTS "${BUILTINS_PKGCONFIG_DIR}/gtkglext-1.0.pc")
24 set(BUILTIN_GTKGLEXT_BUILT ON)
27 if (EXISTS "${BUILTINS_INCLUDE_DIR}")
28 include_directories("${BUILTINS_INCLUDE_DIR}")
31 if (EXISTS "${BUILTINS_LIB_DIR}")
32 set(ENV{LD_LIBRARY_PATH} "$ENV{LD_LIBRARY_PATH}:${BUILTINS_LIB_DIR}")
33 link_directories("${BUILTINS_LIB_DIR}")
36 if (EXISTS "${BUILTINS_PKGCONFIG_DIR}")
37 set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:${BUILTINS_PKGCONFIG_DIR}")
40 #-----------------------------------------------------------------------
42 #-----------------------------------------------------------------------
44 list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
46 #-----------------------------------------------------------------------
48 #-----------------------------------------------------------------------
50 if (EXISTS "${PROJECT_SOURCE_DIR}/libs/crunch/inc/crn_decomp.h")
51 set(DEFAULT_BUILD_CRUNCH ON CACHE INTERNAL "...")
53 set(DEFAULT_BUILD_CRUNCH OFF CACHE INTERNAL "...")
56 if (EXISTS "${PROJECT_SOURCE_DIR}/tools/unvanquished/daemonmap/tools/quake3/q3map2/main.c")
57 set(DEFAULT_BUILD_DAEMONMAP ON CACHE INTERNAL "...")
59 set(DEFAULT_BUILD_DAEMONMAP OFF CACHE INTERNAL "...")
62 #-----------------------------------------------------------------------
64 #-----------------------------------------------------------------------
66 option(BUILD_RADIANT "Build the GUI" ON)
67 option(BUILD_TOOLS "Build the tools" ON)
68 option(BUILD_CRUNCH "Build Crunch image support" ${DEFAULT_BUILD_CRUNCH})
69 option(BUILD_DAEMONMAP "Build daemonmap navigation mesh generator" ${DEFAULT_BUILD_DAEMONMAP})
70 option(DOWNLOAD_GAMEPACKS "Download game packs" ON)
71 option(USE_WERROR "Build with -Werror -pedantic-errors" OFF)
72 option(FHS_INSTALL "Install according to Filesystem Hierarchy Standard" OFF)
73 option(FHS_INSTALL_ABSOLUTE "Install using absolute paths (requires FHS_INSTALL)" OFF)
75 set(BUILD_BINARIES OFF CACHE INTERNAL "...")
76 if (BUILD_RADIANT OR BUILD_TOOLS)
77 set(BUILD_BINARIES ON)
83 OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux"
84 OR "${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD" )
85 set(BUNDLING_SUPPORTED ON)
88 if (BUNDLING_SUPPORTED)
89 if(WIN32 AND NOT CMAKE_CROSSCOMPILING)
90 set(BUNDLE_LIBRARIES_DEFAULT ON)
92 set(BUNDLE_LIBRARIES_DEFAULT OFF)
95 option(BUNDLE_LIBRARIES "Bundle libraries" ${BUNDLE_LIBRARIES_DEFAULT})
98 if (BUNDLE_LIBRARIES AND BUNDLING_SUPPORTED)
99 set(FHS_INSTALL OFF CACHE PATH "Disabled because of BUNDLE_LIBRARIES is enabled" FORCE)
102 if (NOT FHS_INSTALL AND FHS_INSTALL_ABSOLUTE)
103 set(FHS_INSTALL_ABSOLUTE OFF CACHE PATH "Disabled because of FHS_INSTALL is disabled" FORCE)
107 #-----------------------------------------------------------------------
109 #-----------------------------------------------------------------------
111 if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
112 set(CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/install" CACHE PATH "..." FORCE)
116 set(APPLE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}/NetRadiant.app)
117 set(FINAL_INSTALL_PREFIX ${APPLE_INSTALL_PREFIX}/Contents/Prefix)
119 set(FINAL_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
122 set(RADIANT_NAME "NetRadiant" CACHE INTERNAL "...")
123 add_definitions(-DRADIANT_NAME="${RADIANT_NAME}")
124 set(RADIANT_BASENAME "netradiant" CACHE INTERNAL "...")
125 add_definitions(-DRADIANT_BASENAME="${RADIANT_BASENAME}")
127 set(RADIANT_BIN_DIR ${FINAL_INSTALL_PREFIX} CACHE INTERNAL "...")
128 set(RADIANT_LIB_DIR ${FINAL_INSTALL_PREFIX}/lib CACHE INTERNAL "...")
129 set(RADIANT_ADDONS_DIR ${FINAL_INSTALL_PREFIX} CACHE INTERNAL "...")
130 set(RADIANT_SHARE_DIR ${FINAL_INSTALL_PREFIX}/share CACHE INTERNAL "...")
131 set(RADIANT_DATA_DIR ${FINAL_INSTALL_PREFIX} CACHE INTERNAL "...")
134 add_definitions(-DRADIANT_FHS_INSTALL='ON')
136 set(RADIANT_BIN_DIR ${FINAL_INSTALL_PREFIX}/bin)
137 set(RADIANT_LIB_DIR ${FINAL_INSTALL_PREFIX}/lib/${CMAKE_LIBRARY_ARCHITECTURE})
138 set(RADIANT_ADDONS_DIR ${RADIANT_LIB_DIR}/${RADIANT_BASENAME})
139 set(RADIANT_SHARE_DIR ${FINAL_INSTALL_PREFIX}/share)
140 set(RADIANT_DATA_DIR ${RADIANT_SHARE_DIR}/${RADIANT_BASENAME})
141 set(RADIANT_LIB_DIR ${FINAL_INSTALL_PREFIX}/lib/${CMAKE_LIBRARY_ARCHITECTURE})
143 if (FHS_INSTALL_ABSOLUTE)
144 add_definitions(-DRADIANT_ADDONS_DIR="${RADIANT_ADDONS_DIR}")
145 add_definitions(-DRADIANT_DATA_DIR="${RADIANT_DATA_DIR}")
147 add_definitions(-DRADIANT_LIB_ARCH="${CMAKE_LIBRARY_ARCHITECTURE}")
152 set(GAMEPACKS_DOWNLOAD_DIR ${PROJECT_BINARY_DIR}/download CACHE PATH "Where to store downloaded game packs")
154 #-----------------------------------------------------------------------
156 #-----------------------------------------------------------------------
158 # CMake 3.0+ would allow this in project()
159 set(RADIANT_VERSION_MAJOR 1)
160 set(RADIANT_VERSION_MINOR 5)
161 set(RADIANT_VERSION_PATCH 0)
162 set(RADIANT_VERSION "${RADIANT_VERSION_MAJOR}.${RADIANT_VERSION_MINOR}.${RADIANT_VERSION_PATCH}")
164 set(RADIANT_ABOUTMSG "Custom build" CACHE STRING "About message")
166 set(RADIANT_VERSION_STRING "${RADIANT_VERSION}n")
168 if (NOT DEFINED GIT_VERSION)
169 find_package(Git REQUIRED)
172 COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
173 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
174 OUTPUT_VARIABLE GIT_VERSION
175 OUTPUT_STRIP_TRAILING_WHITESPACE
179 set(RADIANT_VERSION_STRING "${RADIANT_VERSION_STRING}-git-${GIT_VERSION}")
183 message(STATUS "Building ${PROJECT_NAME} ${RADIANT_VERSION_STRING} ${RADIANT_ABOUTMSG}")
185 #-----------------------------------------------------------------------
187 #-----------------------------------------------------------------------
190 set(CMAKE_CXX_STANDARD 11)
191 set(CMAKE_CXX_STANDARD_REQUIRED ON)
192 set(CMAKE_CXX_EXTENSIONS OFF)
194 if (CMAKE_VERSION VERSION_LESS "3.1")
195 if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX)
196 include(CheckCXXCompilerFlag)
197 check_cxx_compiler_flag(--std=c++${CMAKE_CXX_STANDARD} STD_CXX)
199 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++${CMAKE_CXX_STANDARD}")
201 message(SEND_ERROR "Requires C++${CMAKE_CXX_STANDARD} or better")
204 message(WARNING "Unrecognized compiler: ${CMAKE_CXX_COMPILER_ID}, make sure it supports C++${CMAKE_CXX_STANDARD}")
209 #-----------------------------------------------------------------------
211 #-----------------------------------------------------------------------
214 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
216 macro (addflags_c args)
217 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${args}")
220 macro (addflags_cxx args)
221 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${args}")
224 macro (addflags args)
225 addflags_c("${args}")
226 addflags_cxx("${args}")
229 addflags("-fno-strict-aliasing")
231 addflags("-fvisibility=hidden")
236 addflags("-pedantic-errors")
241 addflags("-pedantic")
243 addflags_c("-Wno-deprecated-declarations") # vfs.c: g_strdown
245 addflags("-Wno-unused-function")
246 addflags("-Wno-unused-variable")
247 addflags("-Wno-unused-parameter")
250 add_definitions(-DGL_SILENCE_DEPRECATION=1)
253 set(CMAKE_POSITION_INDEPENDENT_CODE 1)
257 set(GTK_TARGET 2 CACHE STRING "GTK target")
258 add_definitions(-DGTK_TARGET=${GTK_TARGET})
261 add_definitions(-DWORKAROUND_WINDOWS_FLOATING_WINDOW=1)
263 if (GTK_TARGET EQUAL 2)
264 add_definitions(-DWORKAROUND_WINDOWS_GTK2_GLWIDGET=1)
269 if (GTK_TARGET EQUAL 2)
270 add_definitions(-DWORKAROUND_MACOS_GTK2_DESTROY=1)
271 add_definitions(-DWORKAROUND_MACOS_GTK2_GLWIDGET=1)
272 add_definitions(-DWORKAROUND_MACOS_GTK2_LAGGYPOINTER=1)
277 #-----------------------------------------------------------------------
279 #-----------------------------------------------------------------------
282 add_definitions(-DRADIANT_VERSION="${RADIANT_VERSION}")
283 add_definitions(-DRADIANT_VERSION_STRING="${RADIANT_VERSION_STRING}")
285 if (NOT CMAKE_BUILD_TYPE MATCHES Release)
286 add_definitions(-D_DEBUG=1)
291 add_definitions(-DRADIANT_ABOUTMSG="${RADIANT_ABOUTMSG}")
293 macro (disable_deprecated name gtk2only)
294 add_definitions(-D${name}_DISABLE_SINGLE_INCLUDES)
295 if ((${gtk2only} EQUAL 0) OR (GTK_TARGET EQUAL 2))
296 add_definitions(-D${name}_DISABLE_DEPRECATED)
300 disable_deprecated(ATK 0)
301 disable_deprecated(G 0)
302 disable_deprecated(GDK 0)
303 disable_deprecated(GDK_PIXBUF 0)
304 disable_deprecated(GTK 1)
305 disable_deprecated(PANGO 0)
309 add_custom_target(binaries ALL)
311 if(APPLE OR ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
329 if (BUILD_RADIANT AND NOT APPLE AND NOT WIN32)
331 find_package(X11 REQUIRED)
332 include_directories(${X11_INCLUDE_DIR})
333 add_definitions(-DXWINDOWS=1)
337 include_directories("${PROJECT_SOURCE_DIR}/include")
338 include_directories("${PROJECT_SOURCE_DIR}/libs")
340 macro (copy_dlls target)
341 if (BUNDLE_LIBRARIES AND BUNDLING_SUPPORTED)
342 add_custom_command(TARGET ${target} POST_BUILD
343 COMMAND "${PROJECT_SOURCE_DIR}/library-bundler"
344 "register" "${PROJECT_BINARY_DIR}" "$<TARGET_FILE:${target}>"
347 add_dependencies(bundle ${target})
352 #-----------------------------------------------------------------------
354 #-----------------------------------------------------------------------
357 if (BUNDLE_LIBRARIES AND BUNDLING_SUPPORTED)
358 add_subdirectory(bundle)
362 #-----------------------------------------------------------------------
364 #-----------------------------------------------------------------------
366 add_custom_target(builtins)
368 if (BUILTIN_GTKGLEXT OR BUILTIN_GTKTHEME_MOJAVE)
369 include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)
372 if (BUILTIN_GTKGLEXT)
373 set(GTKGLEXT_PKGNAMES "gdk-2.0 gtk+-2.0 glib-2.0")
376 set(GTKGLEXT_PKGNAMES "${GTKGLEXT_PKGNAMES} gl")
379 execute_process(COMMAND pkg-config --libs ${GTKGLEXT_PKGNAMES}
380 OUTPUT_VARIABLE GTKGLEXT_LDFLAGS
381 OUTPUT_STRIP_TRAILING_WHITESPACE
384 set(GTKGLEXT_LDFLAGS "$ENV{LDFLAGS} -lm ${GTKGLEXT_LDFLAGS}")
386 execute_process(COMMAND pkg-config --cflags ${GTKGLEXT_PKGNAMES}
387 OUTPUT_VARIABLE GTKGLEXT_CFLAGS
388 OUTPUT_STRIP_TRAILING_WHITESPACE
391 set(GTKGLEXT_CFLAGS "$ENV{CFLAGS} ${GTKGLEXT_CFLAGS}")
394 set(CONFIGURE_OPTIONS --disable-gtk-doc --disable-gtk-doc-html --disable-gtk-doc-pdf --disable-dependency-tracking --without-x)
396 if (CMAKE_BUILD_TYPE MATCHES Release)
397 set(CONFIGURE_OPTIONS ${CONFIGURE_OPTIONS} --disable-debug)
401 set(GTKGLEXT_GIT_TAG macos)
403 set(GTKGLEXT_GIT_TAG fixes)
407 set(GTKGLEXT_CFLAGS "${GTKGLEXT_CFLAGS} -DGL_SILENCE_DEPRECATION=1 -Wno-deprecated-declarations")
410 ExternalProject_Add(gtkglext
411 GIT_REPOSITORY https://gitlab.gnome.org/illwieckz/gtkglext.git
412 GIT_TAG ${GTKGLEXT_GIT_TAG}
414 CONFIGURE_COMMAND export CCFLAGS=${GTKGLEXT_CFLAGS}
415 CONFIGURE_COMMAND && export LDFLAGS=${GTKGLEXT_LDFLAGS}
416 CONFIGURE_COMMAND && export NOCONFIGURE=1
417 CONFIGURE_COMMAND && ./autogen.sh
418 CONFIGURE_COMMAND && ./configure --prefix "${BUILTINS_INSTALL_DIR}" ${CONFIGURE_OPTIONS}
419 BUILD_COMMAND $(MAKE)
420 BUILD_COMMAND CFLAGS=${GTKGLEXT_CFLAGS}
421 BUILD_COMMAND LDFLAGS=${GTKGLEXT_LDFLAGS}
422 INSTALL_COMMAND $(MAKE) install
425 include_directories("${BUILTINS_INCLUDE_DIR}/gtkglext-1.0")
426 include_directories("${BUILTINS_LIB_DIR}/gtkglext-1.0/include")
428 add_dependencies(builtins gtkglext)
429 set_target_properties(gtkglext PROPERTIES EXCLUDE_FROM_ALL ON)
432 if (BUNDLE_LIBRARIES)
433 # It was required to tell cmake to not patch rpath on macos builtins.
434 # It was also required to tell cmake to not patch rpath on freebsd binaries.
435 # Patching rpath is done in library_bundler instead so we can skip this
436 # step entirely when bundling.
437 set(CMAKE_SKIP_RPATH ON)
440 if (BUILTIN_GTKTHEME_MOJAVE)
441 ExternalProject_Add(gtktheme-mojave
442 GIT_REPOSITORY https://github.com/vinceliuice/Mojave-gtk-theme.git
445 CONFIGURE_COMMAND echo
447 INSTALL_COMMAND ./install.sh -o standard -a standard -s standard -i standard -d "${PROJECT_BINARY_DIR}/themes"
449 add_dependencies(builtins gtktheme-mojave)
450 set_target_properties(gtktheme-mojave PROPERTIES EXCLUDE_FROM_ALL ON)
453 #-----------------------------------------------------------------------
455 #-----------------------------------------------------------------------
458 add_subdirectory(libs)
462 add_subdirectory(include)
465 #-----------------------------------------------------------------------
467 #-----------------------------------------------------------------------
470 add_subdirectory(contrib)
473 #-----------------------------------------------------------------------
475 #-----------------------------------------------------------------------
478 add_subdirectory(plugins)
481 #-----------------------------------------------------------------------
483 #-----------------------------------------------------------------------
486 macro (radiant_tool name)
487 add_dependencies(binaries ${name})
490 add_executable(${name} ${ARGN} ${PROJECT_SOURCE_DIR}/include/lib.rc)
492 add_executable(${name} ${ARGN})
499 RUNTIME DESTINATION ${RADIANT_BIN_DIR}
504 add_subdirectory(radiant)
508 #-----------------------------------------------------------------------
510 #-----------------------------------------------------------------------
513 add_subdirectory(tools)
515 file(GLOB DATA_FILES "${PROJECT_SOURCE_DIR}/setup/data/tools/*")
517 if (NOT (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR))
518 # Copy data files from sources to the build directory
519 message(STATUS "Copying data files")
520 file(COPY ${DATA_FILES} DESTINATION "${PROJECT_BINARY_DIR}")
524 #-----------------------------------------------------------------------
526 #-----------------------------------------------------------------------
528 set(GAMEPACKS_LICENSE_LIST free CACHE STRING "Download game packs by license")
529 set(GAMEPACKS_NAME_LIST none CACHE STRING "Download game packs by name")
531 if (DOWNLOAD_GAMEPACKS)
532 add_custom_target(gamepacks ALL
533 COMMAND "${PROJECT_SOURCE_DIR}/gamepack-manager" --license ${GAMEPACKS_LICENSE_LIST} --name ${GAMEPACKS_NAME_LIST} --download-dir "${GAMEPACKS_DOWNLOAD_DIR}" --install-dir "${PROJECT_BINARY_DIR}/gamepacks" --download --install
534 COMMENT "Downloading game packs"
538 #-----------------------------------------------------------------------
540 #-----------------------------------------------------------------------
544 setup/data/tools/base
545 setup/data/tools/bitmaps
547 setup/data/tools/plugins
549 DESTINATION ${RADIANT_DATA_DIR}
553 setup/data/tools/global.xlink
554 DESTINATION ${RADIANT_DATA_DIR}
558 if (DOWNLOAD_GAMEPACKS)
560 ${PROJECT_BINARY_DIR}/gamepacks
561 DESTINATION ${RADIANT_DATA_DIR}
565 if (BUILD_BINARIES AND FHS_INSTALL AND NOT WIN32 AND NOT APPLE)
568 DESTINATION ${RADIANT_SHARE_DIR}/pixmaps
571 icons/netradiant.desktop
572 DESTINATION ${RADIANT_SHARE_DIR}/applications
575 icons/x-netradiant-map.xml
576 DESTINATION ${RADIANT_SHARE_DIR}/mime/application
583 DESTINATION ${APPLE_INSTALL_PREFIX}
586 ${PROJECT_BINARY_DIR}/themes
587 DESTINATION ${APPLE_INSTALL_PREFIX}/Contents/Prefix/share
590 setup/macos/NetRadiant
591 DESTINATION ${APPLE_INSTALL_PREFIX}/Contents/MacOS
595 include(cmake/scripts/package.cmake)