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_CRUNCH "Build Crunch image support" OFF)
8 if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
9 set(CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/install" CACHE PATH "..." FORCE)
12 #-----------------------------------------------------------------------
14 #-----------------------------------------------------------------------
16 # CMake 3.0+ would allow this in project()
17 set(NetRadiant_VERSION_MAJOR 1)
18 set(NetRadiant_VERSION_MINOR 5)
19 set(NetRadiant_VERSION_PATCH 0)
20 set(NetRadiant_VERSION "${NetRadiant_VERSION_MAJOR}.${NetRadiant_VERSION_MINOR}.${NetRadiant_VERSION_PATCH}")
22 file(WRITE "${PROJECT_BINARY_DIR}/RADIANT_MAJOR" ${NetRadiant_VERSION_MAJOR})
23 file(WRITE "${PROJECT_BINARY_DIR}/RADIANT_MINOR" ${NetRadiant_VERSION_MINOR})
24 file(WRITE "${PROJECT_BINARY_DIR}/RADIANT_PATCH" ${NetRadiant_VERSION_PATCH})
26 set(RADIANT_ABOUTMSG "Custom build" CACHE STRING "About message")
28 find_package(Git REQUIRED)
30 COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
31 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
32 OUTPUT_VARIABLE GIT_VERSION
33 OUTPUT_STRIP_TRAILING_WHITESPACE
35 set(RADIANT_VERSION_STRING "${NetRadiant_VERSION}n")
37 set(RADIANT_VERSION_STRING "${RADIANT_VERSION_STRING}-git-${GIT_VERSION}")
40 message(STATUS "Building ${PROJECT_NAME} ${RADIANT_VERSION_STRING} ${RADIANT_ABOUTMSG}")
42 #-----------------------------------------------------------------------
44 #-----------------------------------------------------------------------
46 set(CMAKE_CXX_STANDARD 11)
47 set(CMAKE_CXX_STANDARD_REQUIRED ON)
48 set(CMAKE_CXX_EXTENSIONS OFF)
49 if (CMAKE_VERSION VERSION_LESS "3.1")
50 if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX)
51 include(CheckCXXCompilerFlag)
52 check_cxx_compiler_flag(--std=c++${CMAKE_CXX_STANDARD} STD_CXX)
54 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++${CMAKE_CXX_STANDARD}")
56 message(SEND_ERROR "Requires C++${CMAKE_CXX_STANDARD} or better")
59 message(WARNING "Unrecognized compiler: ${CMAKE_CXX_COMPILER_ID}, make sure it supports C++${CMAKE_CXX_STANDARD}")
63 #-----------------------------------------------------------------------
65 #-----------------------------------------------------------------------
67 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
68 macro(addflags_c args)
69 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${args}")
71 macro(addflags_cxx args)
72 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${args}")
76 addflags_cxx("${args}")
78 addflags("-fno-strict-aliasing")
80 addflags("-fvisibility=hidden")
83 if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
85 addflags("-pedantic-errors")
92 addflags_c("-Wno-deprecated-declarations") # vfs.c: g_strdown
94 addflags("-Wno-unused-function")
95 addflags("-Wno-unused-variable")
96 addflags("-Wno-unused-parameter")
98 set(CMAKE_POSITION_INDEPENDENT_CODE 1)
99 set(GTK_TARGET 2 CACHE STRING "GTK target")
100 add_definitions(-DGTK_TARGET=${GTK_TARGET})
102 #-----------------------------------------------------------------------
104 #-----------------------------------------------------------------------
106 add_definitions(-DRADIANT_VERSION="${NetRadiant_VERSION}")
107 add_definitions(-DRADIANT_MAJOR_VERSION="${NetRadiant_VERSION_MAJOR}")
108 add_definitions(-DRADIANT_MINOR_VERSION="${NetRadiant_VERSION_MINOR}")
109 add_definitions(-DRADIANT_PATCH_VERSION="${NetRadiant_VERSION_PATCH}")
111 add_definitions(-DRADIANT_ABOUTMSG="${NetRadiant_ABOUT}")
113 if (NOT CMAKE_BUILD_TYPE MATCHES Release)
114 add_definitions(-D_DEBUG=1)
117 macro(disable_deprecated name gtk2only)
118 add_definitions(-D${name}_DISABLE_SINGLE_INCLUDES)
119 if ((${gtk2only} EQUAL 0) OR (GTK_TARGET EQUAL 2))
120 add_definitions(-D${name}_DISABLE_DEPRECATED)
124 disable_deprecated(ATK 0)
125 disable_deprecated(G 0)
126 disable_deprecated(GDK 0)
127 disable_deprecated(GDK_PIXBUF 0)
128 disable_deprecated(GTK 1)
129 disable_deprecated(PANGO 0)
132 option(XWINDOWS "Build against X11" ON)
149 find_package(X11 REQUIRED)
150 include_directories(${X11_INCLUDE_DIR})
151 add_definitions(-DXWINDOWS=1)
154 include_directories("${PROJECT_SOURCE_DIR}/include")
155 include_directories("${PROJECT_SOURCE_DIR}/libs")
157 if (WIN32 AND NOT CMAKE_CROSSCOMPILING)
158 set(BUNDLE_LIBRARIES_DEFAULT ON)
160 set(BUNDLE_LIBRARIES_DEFAULT OFF)
162 option(BUNDLE_LIBRARIES "Bundle libraries" ${BUNDLE_LIBRARIES_DEFAULT})
164 macro(copy_dlls target)
165 if (BUNDLE_LIBRARIES)
166 add_custom_command(TARGET ${target} POST_BUILD
168 ARGS -c "ldd '$<TARGET_FILE:${target}>' | grep -v /c/Windows | awk '{ print $1 }' | while read dll; do cp \"$(which $dll)\" '${PROJECT_BINARY_DIR}'; done"
174 #-----------------------------------------------------------------------
176 #-----------------------------------------------------------------------
178 add_subdirectory(libs)
179 add_subdirectory(include)
181 #-----------------------------------------------------------------------
183 #-----------------------------------------------------------------------
186 add_subdirectory(contrib)
189 #-----------------------------------------------------------------------
191 #-----------------------------------------------------------------------
194 add_subdirectory(plugins)
197 #-----------------------------------------------------------------------
199 #-----------------------------------------------------------------------
201 if (CMAKE_EXECUTABLE_SUFFIX)
202 string(REGEX REPLACE "^[.]" "" RADIANT_EXECUTABLE ${CMAKE_EXECUTABLE_SUFFIX})
206 OUTPUT_VARIABLE RADIANT_EXECUTABLE
207 OUTPUT_STRIP_TRAILING_WHITESPACE
211 macro(radiant_tool name)
212 add_executable(${name} ${ARGN})
215 RUNTIME DESTINATION .
217 if (NOT (CMAKE_EXECUTABLE_SUFFIX STREQUAL ".${RADIANT_EXECUTABLE}"))
218 add_custom_command(TARGET ${name} POST_BUILD
219 COMMAND ln -f -s "$<TARGET_FILE_NAME:${name}>" "${PROJECT_BINARY_DIR}/${name}.${RADIANT_EXECUTABLE}"
222 install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
223 ${name}${CMAKE_EXECUTABLE_SUFFIX} ${CMAKE_INSTALL_PREFIX}/${name}.${RADIANT_EXECUTABLE})
229 add_subdirectory(radiant _radiant)
230 set_target_properties(radiant PROPERTIES
231 COMPILE_DEFINITIONS RADIANT_EXECUTABLE="${RADIANT_EXECUTABLE}"
235 #-----------------------------------------------------------------------
237 #-----------------------------------------------------------------------
239 add_subdirectory(tools)
241 file(GLOB DATA_FILES "${PROJECT_SOURCE_DIR}/setup/data/tools/*")
243 if (NOT (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR))
244 # Copy data files from sources to the build directory
245 message(STATUS "Copying data files")
246 file(COPY ${DATA_FILES} DESTINATION "${PROJECT_BINARY_DIR}")
249 #-----------------------------------------------------------------------
251 #-----------------------------------------------------------------------
253 option(DOWNLOAD_GAMEPACKS "Download game packs" ON)
255 set(GAMEPACKS_LICENSE_LIST free CACHE STRING "Download game packs by license")
256 set(GAMEPACKS_NAME_LIST none CACHE STRING "Download game packs by name")
258 if (DOWNLOAD_GAMEPACKS)
259 add_custom_target(game_packs ALL
260 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
261 COMMENT "Downloading ${GAMEPACKS_LICENSE_LIST} game packs"
265 #-----------------------------------------------------------------------
267 #-----------------------------------------------------------------------
271 "${PROJECT_BINARY_DIR}/RADIANT_MAJOR"
272 "${PROJECT_BINARY_DIR}/RADIANT_MINOR"
273 "${PROJECT_BINARY_DIR}/RADIANT_PATCH"
284 install(CODE "execute_process(COMMAND \"${PROJECT_SOURCE_DIR}/gamepack-manager\" --license ${GAMEPACKS_LICENSE_LIST} --name ${GAMEPACKS_NAME_LIST} --download-dir \"${PROJECT_BINARY_DIR}/download\" --install-dir \"${CMAKE_INSTALL_PREFIX}\" --install)"
287 include(cmake/scripts/package.cmake)