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)
5 option(BUILD_RADIANT "Build the GUI" ON)
6 option(BUILD_TOOLS "Build the tools" ON)
7 option(BUILD_CRUNCH "Build Crunch image support" OFF)
8 option(DOWNLOAD_GAMEPACKS "Download game packs" ON)
9 option(USE_WERROR "Build with -Werror -pedantic-errors" OFF)
10 option(FHS_INSTALL "Install according to Filesystem Hierarchy Standard" OFF)
12 set(BUILD_BINARIES OFF CACHE INTERNAL "...")
13 if (BUILD_RADIANT OR BUILD_TOOLS)
14 set(BUILD_BINARIES ON)
17 #-----------------------------------------------------------------------
19 #-----------------------------------------------------------------------
21 if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
22 set(CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/install" CACHE PATH "..." FORCE)
25 set(RADIANT_BASENAME netradiant CACHE INTERNAL "...")
26 add_definitions(-DRADIANT_BASENAME="${RADIANT_BASENAME}")
28 set(RADIANT_LIB_DIR ${CMAKE_INSTALL_PREFIX} CACHE INTERNAL "...")
29 set(RADIANT_BIN_DIR ${CMAKE_INSTALL_PREFIX} CACHE INTERNAL "...")
30 set(RADIANT_DATA_DIR ${CMAKE_INSTALL_PREFIX} CACHE INTERNAL "...")
33 set(RADIANT_LIB_DIR lib/${RADIANT_BASENAME})
34 set(RADIANT_BIN_DIR bin)
35 set(RADIANT_DATA_DIR share/${RADIANT_BASENAME})
38 #-----------------------------------------------------------------------
40 #-----------------------------------------------------------------------
42 # CMake 3.0+ would allow this in project()
43 set(NetRadiant_VERSION_MAJOR 1)
44 set(NetRadiant_VERSION_MINOR 5)
45 set(NetRadiant_VERSION_PATCH 0)
46 set(NetRadiant_VERSION "${NetRadiant_VERSION_MAJOR}.${NetRadiant_VERSION_MINOR}.${NetRadiant_VERSION_PATCH}")
48 set(RADIANT_ABOUTMSG "Custom build" CACHE STRING "About message")
50 find_package(Git REQUIRED)
53 COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
54 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
55 OUTPUT_VARIABLE GIT_VERSION
56 OUTPUT_STRIP_TRAILING_WHITESPACE
59 set(RADIANT_VERSION_STRING "${NetRadiant_VERSION}n")
62 set(RADIANT_VERSION_STRING "${RADIANT_VERSION_STRING}-git-${GIT_VERSION}")
65 message(STATUS "Building ${PROJECT_NAME} ${RADIANT_VERSION_STRING} ${RADIANT_ABOUTMSG}")
67 #-----------------------------------------------------------------------
69 #-----------------------------------------------------------------------
72 set(CMAKE_CXX_STANDARD 11)
73 set(CMAKE_CXX_STANDARD_REQUIRED ON)
74 set(CMAKE_CXX_EXTENSIONS OFF)
76 if (CMAKE_VERSION VERSION_LESS "3.1")
77 if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX)
78 include(CheckCXXCompilerFlag)
79 check_cxx_compiler_flag(--std=c++${CMAKE_CXX_STANDARD} STD_CXX)
81 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++${CMAKE_CXX_STANDARD}")
83 message(SEND_ERROR "Requires C++${CMAKE_CXX_STANDARD} or better")
86 message(WARNING "Unrecognized compiler: ${CMAKE_CXX_COMPILER_ID}, make sure it supports C++${CMAKE_CXX_STANDARD}")
91 #-----------------------------------------------------------------------
93 #-----------------------------------------------------------------------
96 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
98 macro(addflags_c args)
99 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${args}")
102 macro(addflags_cxx args)
103 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${args}")
107 addflags_c("${args}")
108 addflags_cxx("${args}")
111 addflags("-fno-strict-aliasing")
113 addflags("-fvisibility=hidden")
118 addflags("-pedantic-errors")
123 addflags("-pedantic")
125 addflags_c("-Wno-deprecated-declarations") # vfs.c: g_strdown
127 addflags("-Wno-unused-function")
128 addflags("-Wno-unused-variable")
129 addflags("-Wno-unused-parameter")
131 set(CMAKE_POSITION_INDEPENDENT_CODE 1)
135 set(GTK_TARGET 2 CACHE STRING "GTK target")
136 add_definitions(-DGTK_TARGET=${GTK_TARGET})
139 #-----------------------------------------------------------------------
141 #-----------------------------------------------------------------------
144 add_definitions(-DRADIANT_VERSION="${NetRadiant_VERSION}")
145 add_definitions(-DRADIANT_MAJOR_VERSION="${NetRadiant_VERSION_MAJOR}")
146 add_definitions(-DRADIANT_MINOR_VERSION="${NetRadiant_VERSION_MINOR}")
147 add_definitions(-DRADIANT_PATCH_VERSION="${NetRadiant_VERSION_PATCH}")
149 add_definitions(-DRADIANT_ABOUTMSG="${NetRadiant_ABOUT}")
151 if (NOT CMAKE_BUILD_TYPE MATCHES Release)
152 add_definitions(-D_DEBUG=1)
157 macro(disable_deprecated name gtk2only)
158 add_definitions(-D${name}_DISABLE_SINGLE_INCLUDES)
159 if ((${gtk2only} EQUAL 0) OR (GTK_TARGET EQUAL 2))
160 add_definitions(-D${name}_DISABLE_DEPRECATED)
164 disable_deprecated(ATK 0)
165 disable_deprecated(G 0)
166 disable_deprecated(GDK 0)
167 disable_deprecated(GDK_PIXBUF 0)
168 disable_deprecated(GTK 1)
169 disable_deprecated(PANGO 0)
175 option(XWINDOWS "Build against X11" ON)
201 if (BUILD_RADIANT AND XWINDOWS)
202 find_package(X11 REQUIRED)
203 include_directories(${X11_INCLUDE_DIR})
204 add_definitions(-DXWINDOWS=1)
208 include_directories("${PROJECT_SOURCE_DIR}/include")
209 include_directories("${PROJECT_SOURCE_DIR}/libs")
211 if (WIN32 AND NOT CMAKE_CROSSCOMPILING)
212 set(BUNDLE_LIBRARIES_DEFAULT ON)
214 set(BUNDLE_LIBRARIES_DEFAULT OFF)
217 option(BUNDLE_LIBRARIES "Bundle libraries" ${BUNDLE_LIBRARIES_DEFAULT})
219 macro(copy_dlls target)
220 if (BUNDLE_LIBRARIES AND WIN32)
221 add_custom_command(TARGET ${target} POST_BUILD
223 ARGS -c "ldd '$<TARGET_FILE:${target}>' | egrep -i '\\.dll ' | grep -iv '/c/Windows' | awk '{ print $1 }' | while read dll; do cp --preserve=timestamps \"$(which $dll)\" '${PROJECT_BINARY_DIR}'; done"
227 file(GLOB DLL_FILES ${PROJECT_BINARY_DIR}/*.dll)
231 DESTINATION ${CMAKE_INSTALL_PREFIX}
236 macro(bundle_gtkdeps target)
237 if (BUNDLE_LIBRARIES AND WIN32)
238 add_custom_command(TARGET ${target} POST_BUILD
240 ARGS -c "mkdir -p '${PROJECT_BINARY_DIR}/share/themes'; mkdir -p '${PROJECT_BINARY_DIR}/lib'; mingw=\"$(echo '${CMAKE_C_COMPILER}' | sed -e 's|/bin/.*||')\"; cp -r --preserve=timestamps \"$mingw/share/themes/MS-Windows\" '${PROJECT_BINARY_DIR}/share/themes/'; cp -r --preserve=timestamps \"$mingw/lib/gdk-pixbuf-2.0\" '${PROJECT_BINARY_DIR}/lib/'; cp -r --preserve=timestamps \"$mingw/lib/gtk-2.0\" '${PROJECT_BINARY_DIR}/lib/'"
245 ${PROJECT_BINARY_DIR}/lib
246 ${PROJECT_BINARY_DIR}/share
247 DESTINATION ${CMAKE_INSTALL_PREFIX}
253 #-----------------------------------------------------------------------
255 #-----------------------------------------------------------------------
258 add_subdirectory(libs)
262 add_subdirectory(include)
265 #-----------------------------------------------------------------------
267 #-----------------------------------------------------------------------
270 add_subdirectory(contrib)
273 #-----------------------------------------------------------------------
275 #-----------------------------------------------------------------------
278 add_subdirectory(plugins)
281 #-----------------------------------------------------------------------
283 #-----------------------------------------------------------------------
286 if (CMAKE_EXECUTABLE_SUFFIX)
287 string(REGEX REPLACE "^[.]" "" RADIANT_EXECUTABLE ${CMAKE_EXECUTABLE_SUFFIX})
290 macro(radiant_tool name)
291 add_executable(${name} ${ARGN})
294 RUNTIME DESTINATION ${RADIANT_BIN_DIR}
299 add_subdirectory(radiant _radiant)
300 set_target_properties(${RADIANT_BASENAME} PROPERTIES
301 COMPILE_DEFINITIONS RADIANT_EXECUTABLE="${RADIANT_EXECUTABLE}"
306 #-----------------------------------------------------------------------
308 #-----------------------------------------------------------------------
311 add_subdirectory(tools)
313 file(GLOB DATA_FILES "${PROJECT_SOURCE_DIR}/setup/data/tools/*")
315 if (NOT (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR))
316 # Copy data files from sources to the build directory
317 message(STATUS "Copying data files")
318 file(COPY ${DATA_FILES} DESTINATION "${PROJECT_BINARY_DIR}")
322 #-----------------------------------------------------------------------
324 #-----------------------------------------------------------------------
326 set(GAMEPACKS_LICENSE_LIST free CACHE STRING "Download game packs by license")
327 set(GAMEPACKS_NAME_LIST none CACHE STRING "Download game packs by name")
329 if (DOWNLOAD_GAMEPACKS)
330 add_custom_target(game_packs ALL
331 COMMAND "${PROJECT_SOURCE_DIR}/gamepack-manager" --license ${GAMEPACKS_LICENSE_LIST} --name ${GAMEPACKS_NAME_LIST} --download-dir "${PROJECT_BINARY_DIR}/download" --install-dir "${PROJECT_BINARY_DIR}" --download --install
332 COMMENT "Downloading ${GAMEPACKS_LICENSE_LIST} game packs"
336 #-----------------------------------------------------------------------
338 #-----------------------------------------------------------------------
344 DESTINATION ${RADIANT_DATA_DIR}
348 if (DOWNLOAD_GAMEPACKS)
350 set(GAME_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/share/netradiant")
352 set(GAME_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
355 file(GLOB GAME_DIRS ${PROJECT_BINARY_DIR}/*.game)
358 ${PROJECT_BINARY_DIR}/games
360 DESTINATION ${RADIANT_DATA_DIR}
364 if(BUILD_BINARIES AND FHS_INSTALL AND NOT WIN32 AND NOT APPLE)
366 ${PROJECT_SOURCE_DIR}/icons/netradiant.png
367 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/pixmaps
370 ${PROJECT_SOURCE_DIR}/icons/netradiant.desktop
371 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications
374 ${PROJECT_SOURCE_DIR}/icons/mime/map.xml
375 DESTINATION ${CMAKE_INSTALL_PREFIX}/share/mime/model
379 include(cmake/scripts/package.cmake)