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