Merge branch 'dpkdir' into 'master'
[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         set(CMAKE_CXX_FLAGS "${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 set(GTK_NS "GTK2" CACHE STRING "GTK variable prefix")
67
68 #-----------------------------------------------------------------------
69 # Defs
70 #-----------------------------------------------------------------------
71
72 add_definitions(-DRADIANT_VERSION="${NetRadiant_VERSION}")
73 add_definitions(-DRADIANT_MAJOR_VERSION="${NetRadiant_VERSION_MAJOR}")
74 add_definitions(-DRADIANT_MINOR_VERSION="${NetRadiant_VERSION_MINOR}")
75
76 add_definitions(-DRADIANT_ABOUTMSG="${NetRadiant_ABOUT}")
77
78 if (CMAKE_BUILD_TYPE MATCHES Debug)
79     add_definitions(-D_DEBUG=1)
80 endif ()
81
82 if (APPLE)
83     option(XWINDOWS "Build against X11" ON)
84     add_definitions(
85             -DPOSIX=1
86     )
87 elseif (WIN32)
88     add_definitions(
89             -DWIN32=1
90             -D_WIN32=1
91     )
92 else ()
93     set(XWINDOWS ON)
94     add_definitions(
95             -DPOSIX=1
96     )
97 endif ()
98
99 if (XWINDOWS)
100     find_package(X11 REQUIRED)
101     include_directories(${X11_INCLUDE_DIR})
102     add_definitions(-DXWINDOWS=1)
103 endif ()
104
105 include_directories("${PROJECT_SOURCE_DIR}/include")
106 include_directories("${PROJECT_SOURCE_DIR}/libs")
107
108 #-----------------------------------------------------------------------
109 # Libraries
110 #-----------------------------------------------------------------------
111
112 add_subdirectory(libs)
113 add_subdirectory(include)
114
115 #-----------------------------------------------------------------------
116 # Plugins
117 #-----------------------------------------------------------------------
118
119 if (BUILD_RADIANT)
120     add_subdirectory(contrib)
121 endif ()
122
123 #-----------------------------------------------------------------------
124 # Modules
125 #-----------------------------------------------------------------------
126
127 if (BUILD_RADIANT)
128     add_subdirectory(plugins)
129 endif ()
130
131 #-----------------------------------------------------------------------
132 # Radiant
133 #-----------------------------------------------------------------------
134
135 if (BUILD_RADIANT)
136     add_subdirectory(radiant build)
137 endif ()
138
139 if (CMAKE_EXECUTABLE_SUFFIX)
140     set(RADIANT_EXECUTABLE ${CMAKE_EXECUTABLE_SUFFIX})
141 else ()
142     execute_process(
143             COMMAND uname -m
144             OUTPUT_VARIABLE RADIANT_EXECUTABLE
145             OUTPUT_STRIP_TRAILING_WHITESPACE
146     )
147 endif ()
148
149 if (BUILD_RADIANT)
150     set_target_properties(radiant PROPERTIES
151             COMPILE_DEFINITIONS RADIANT_EXECUTABLE="${RADIANT_EXECUTABLE}"
152             )
153 endif ()
154
155 #-----------------------------------------------------------------------
156 # Tools
157 #-----------------------------------------------------------------------
158
159 add_subdirectory(tools)
160
161 if (NOT (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR))
162     # Copy data files from sources to the build directory
163     message(STATUS "Copying data files")
164     file(GLOB DATA_FILES "${PROJECT_SOURCE_DIR}/setup/data/tools/*")
165     file(COPY ${DATA_FILES} DESTINATION "${PROJECT_BINARY_DIR}")
166     file(GLOB DATA_FILES "${PROJECT_SOURCE_DIR}/docs/*")
167     file(COPY ${DATA_FILES} DESTINATION "${PROJECT_BINARY_DIR}/docs")
168 endif ()
169
170 #-----------------------------------------------------------------------
171 # Game packs
172 #-----------------------------------------------------------------------
173
174 option(DOWNLOAD_GAMEPACKS "Download game packs" ON)
175 add_custom_target(game_packs
176         COMMAND ${CMAKE_COMMAND} -E make_directory games
177         COMMAND DOWNLOAD_GAMEPACKS=yes SOURCE_DIR="${PROJECT_SOURCE_DIR}" "${PROJECT_SOURCE_DIR}/install-gamepacks.sh" "${PROJECT_BINARY_DIR}"
178         COMMENT "Downloading game packs"
179         )
180 if (DOWNLOAD_GAMEPACKS)
181     add_custom_target(game_packs_all ALL DEPENDS game_packs)
182 endif ()