Merge remote-tracking branch 'illwieckz/pakpath'
[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 # Enable Debug by default, can be changed with -DCMAKE_BUILD_TYPE=Release
4 if (NOT CMAKE_BUILD_TYPE)
5     set(CMAKE_BUILD_TYPE Debug)
6 endif ()
7
8 project(NetRadiant C CXX)
9 option(BUILD_RADIANT "Build the gui" ON)
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
24 set(RADIANT_ABOUTMSG "Custom build" CACHE STRING "About message")
25
26 find_package(Git REQUIRED)
27 execute_process(
28         COMMAND ${GIT_EXECUTABLE} rev-parse --short HEAD
29         WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
30         OUTPUT_VARIABLE GIT_VERSION
31         OUTPUT_STRIP_TRAILING_WHITESPACE
32 )
33 set(RADIANT_VERSION_STRING "${NetRadiant_VERSION}n")
34 if (GIT_VERSION)
35     set(RADIANT_VERSION_STRING "${RADIANT_VERSION_STRING}-git-${GIT_VERSION}")
36 endif ()
37
38 message(STATUS "Building ${PROJECT_NAME} ${RADIANT_VERSION_STRING} ${RADIANT_ABOUTMSG}")
39
40 #-----------------------------------------------------------------------
41 # Language standard
42 #-----------------------------------------------------------------------
43
44 set(CMAKE_CXX_STANDARD 11)
45 set(CMAKE_CXX_STANDARD_REQUIRED ON)
46 # For some reason the above flags don't really work...
47 if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX)
48     include(CheckCXXCompilerFlag)
49     check_cxx_compiler_flag(--std=c++${CMAKE_CXX_STANDARD} STD_CXX)
50     if (STD_CXX)
51         list(APPEND CMAKE_CXX_FLAGS --std=c++${CMAKE_CXX_STANDARD})
52     else ()
53         message(SEND_ERROR "Requires C++${CMAKE_CXX_STANDARD} or better")
54     endif ()
55 else ()
56     message(WARNING "Unrecognized compiler: ${CMAKE_CXX_COMPILER_ID}, make sure it supports C++${CMAKE_CXX_STANDARD}")
57 endif ()
58
59 #-----------------------------------------------------------------------
60 # Flags
61 #-----------------------------------------------------------------------
62
63 set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}   -fno-strict-aliasing")
64 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing -fno-exceptions -fno-rtti")
65 set(CMAKE_POSITION_INDEPENDENT_CODE 1)
66
67 #-----------------------------------------------------------------------
68 # Defs
69 #-----------------------------------------------------------------------
70
71 add_definitions(-DRADIANT_VERSION="${NetRadiant_VERSION}")
72 add_definitions(-DRADIANT_MAJOR_VERSION="${NetRadiant_VERSION_MAJOR}")
73 add_definitions(-DRADIANT_MINOR_VERSION="${NetRadiant_VERSION_MINOR}")
74
75 add_definitions(-DRADIANT_ABOUTMSG="${NetRadiant_ABOUT}")
76
77 if (CMAKE_BUILD_TYPE MATCHES Debug)
78     add_definitions(-D_DEBUG=1)
79 endif ()
80
81 if (APPLE)
82     option(XWINDOWS "Build against X11" ON)
83     add_definitions(
84             -DPOSIX=1
85     )
86 elseif (WIN32)
87     add_definitions(
88             -DWIN32=1
89             -D_WIN32=1
90     )
91 else ()
92     set(XWINDOWS ON)
93     add_definitions(
94             -DPOSIX=1
95     )
96 endif ()
97
98 if (XWINDOWS)
99     find_package(X11 REQUIRED)
100     include_directories(${X11_INCLUDE_DIR})
101     add_definitions(-DXWINDOWS=1)
102 endif ()
103
104 include_directories("${PROJECT_SOURCE_DIR}/include")
105 include_directories("${PROJECT_SOURCE_DIR}/libs")
106
107 #-----------------------------------------------------------------------
108 # Libraries
109 #-----------------------------------------------------------------------
110
111 add_subdirectory(libs)
112 add_subdirectory(include)
113
114 #-----------------------------------------------------------------------
115 # Plugins
116 #-----------------------------------------------------------------------
117
118 if (BUILD_RADIANT)
119     add_subdirectory(contrib)
120 endif ()
121
122 #-----------------------------------------------------------------------
123 # Modules
124 #-----------------------------------------------------------------------
125
126 if (BUILD_RADIANT)
127     add_subdirectory(plugins)
128 endif ()
129
130 #-----------------------------------------------------------------------
131 # Radiant
132 #-----------------------------------------------------------------------
133
134 if (BUILD_RADIANT)
135     add_subdirectory(radiant build)
136 endif ()
137
138 if (CMAKE_EXECUTABLE_SUFFIX)
139     set(RADIANT_EXECUTABLE ${CMAKE_EXECUTABLE_SUFFIX})
140 else ()
141     execute_process(
142             COMMAND uname -m
143             OUTPUT_VARIABLE RADIANT_EXECUTABLE
144             OUTPUT_STRIP_TRAILING_WHITESPACE
145     )
146 endif ()
147
148 if (BUILD_RADIANT)
149     set_target_properties(radiant PROPERTIES
150             COMPILE_DEFINITIONS RADIANT_EXECUTABLE="${RADIANT_EXECUTABLE}"
151             )
152 endif ()
153
154 #-----------------------------------------------------------------------
155 # Tools
156 #-----------------------------------------------------------------------
157
158 add_subdirectory(tools)
159
160 if (NOT (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR))
161     # Copy data files from sources to the build directory
162     message(STATUS "Copying data files")
163     file(GLOB DATA_FILES "${PROJECT_SOURCE_DIR}/setup/data/tools/*")
164     file(COPY ${DATA_FILES} DESTINATION "${PROJECT_BINARY_DIR}")
165     file(GLOB DATA_FILES "${PROJECT_SOURCE_DIR}/docs/*")
166     file(COPY ${DATA_FILES} DESTINATION "${PROJECT_BINARY_DIR}/docs")
167 endif ()
168
169 #-----------------------------------------------------------------------
170 # Game packs
171 #-----------------------------------------------------------------------
172
173 option(DOWNLOAD_GAMEPACKS "Download game packs" ON)
174 add_custom_target(game_packs
175         COMMAND ${CMAKE_COMMAND} -E make_directory games
176         COMMAND DOWNLOAD_GAMEPACKS=yes SOURCE_DIR="${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/install-gamepacks.sh" "${PROJECT_BINARY_DIR}"
177         COMMENT "Downloading game packs"
178         )
179 if (DOWNLOAD_GAMEPACKS)
180     add_custom_target(game_packs_all ALL DEPENDS game_packs)
181 endif ()