-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
255 lines (199 loc) · 7.29 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
cmake_minimum_required(VERSION 3.1 FATAL_ERROR)
project(DaemonMap C CXX)
#-----------------------------------------------------------------------
# CMake modules
#-----------------------------------------------------------------------
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
#-----------------------------------------------------------------------
# Build options
#-----------------------------------------------------------------------
option(BUILD_TOOLS "Build the tools" ON)
option(USE_WERROR "Build with -Werror -pedantic-errors" OFF)
option(FHS_INSTALL "Install according to Filesystem Hierarchy Standard" OFF)
set(BUILD_BINARIES OFF CACHE INTERNAL "...")
if (BUILD_RADIANT OR BUILD_TOOLS)
set(BUILD_BINARIES ON)
endif ()
if (BUILD_BINARIES)
if (WIN32 OR APPLE
OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux"
OR "${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD" )
set(BUNDLING_SUPPORTED ON)
endif()
if (BUNDLING_SUPPORTED)
if(WIN32 AND NOT CMAKE_CROSSCOMPILING)
set(BUNDLE_LIBRARIES_DEFAULT ON)
else ()
set(BUNDLE_LIBRARIES_DEFAULT OFF)
endif ()
option(BUNDLE_LIBRARIES "Bundle libraries" ${BUNDLE_LIBRARIES_DEFAULT})
endif ()
if (BUNDLE_LIBRARIES AND BUNDLING_SUPPORTED)
set(FHS_INSTALL OFF CACHE PATH "Disabled because of BUNDLE_LIBRARIES" FORCE)
endif ()
endif ()
#-----------------------------------------------------------------------
# Paths
#-----------------------------------------------------------------------
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${PROJECT_SOURCE_DIR}/install" CACHE PATH "..." FORCE)
endif ()
set(FINAL_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
set(RADIANT_NAME "NetRadiant" CACHE INTERNAL "...")
add_definitions(-DRADIANT_NAME="${RADIANT_NAME}")
set(RADIANT_BIN_DIR ${FINAL_INSTALL_PREFIX} CACHE INTERNAL "...")
set(RADIANT_LIB_DIR ${FINAL_INSTALL_PREFIX}/lib CACHE INTERNAL "...")
if (FHS_INSTALL AND NOT BUNDLE_LIBRARIES)
set(RADIANT_BIN_DIR ${FINAL_INSTALL_PREFIX}/bin)
set(RADIANT_LIB_DIR ${FINAL_INSTALL_PREFIX}/lib)
endif ()
#-----------------------------------------------------------------------
# Language standard
#-----------------------------------------------------------------------
if (BUILD_BINARIES)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
if (CMAKE_VERSION VERSION_LESS "3.1")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(--std=c++${CMAKE_CXX_STANDARD} STD_CXX)
if (STD_CXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++${CMAKE_CXX_STANDARD}")
else ()
message(SEND_ERROR "Requires C++${CMAKE_CXX_STANDARD} or better")
endif ()
else ()
message(WARNING "Unrecognized compiler: ${CMAKE_CXX_COMPILER_ID}, make sure it supports C++${CMAKE_CXX_STANDARD}")
endif ()
endif ()
endif ()
#-----------------------------------------------------------------------
# Flags
#-----------------------------------------------------------------------
if (BUILD_BINARIES)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions -fno-rtti")
macro (addflags_c args)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${args}")
endmacro ()
macro (addflags_cxx args)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${args}")
endmacro ()
macro (addflags args)
addflags_c("${args}")
addflags_cxx("${args}")
endmacro ()
addflags("-fno-strict-aliasing")
if (NOT WIN32)
addflags("-fvisibility=hidden")
endif ()
if (USE_WERROR)
addflags("-Werror")
addflags("-pedantic-errors")
endif ()
addflags("-Wall")
addflags("-Wextra")
addflags("-pedantic")
addflags_c("-Wno-deprecated-declarations") # vfs.c: g_strdown
addflags("-Wno-unused-function")
addflags("-Wno-unused-variable")
addflags("-Wno-unused-parameter")
if (APPLE)
add_definitions(-DGL_SILENCE_DEPRECATION=1)
endif()
set(CMAKE_POSITION_INDEPENDENT_CODE 1)
endif ()
#-----------------------------------------------------------------------
# Defs
#-----------------------------------------------------------------------
if (BUILD_BINARIES)
add_definitions(-DRADIANT_VERSION="${RADIANT_VERSION}")
add_definitions(-DRADIANT_VERSION_STRING="${RADIANT_VERSION_STRING}")
if (NOT CMAKE_BUILD_TYPE MATCHES Release)
add_definitions(-D_DEBUG=1)
endif ()
endif ()
if (BUILD_BINARIES)
add_custom_target(binaries ALL)
if(APPLE OR ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
link_directories(
/usr/local/lib
)
endif ()
if (WIN32)
add_definitions(
-DWIN32=1
-D_WIN32=1
)
else ()
add_definitions(
-DPOSIX=1
)
endif ()
endif ()
if (BUILD_BINARIES)
include_directories("${PROJECT_SOURCE_DIR}/include")
include_directories("${PROJECT_SOURCE_DIR}/libs")
macro (copy_dlls target)
if (BUNDLE_LIBRARIES AND BUNDLING_SUPPORTED)
add_custom_command(TARGET ${target} POST_BUILD
COMMAND "${PROJECT_SOURCE_DIR}/library-bundler"
"register" "${PROJECT_BINARY_DIR}" "$<TARGET_FILE:${target}>"
VERBATIM
)
add_dependencies(bundle ${target})
endif ()
endmacro ()
endif ()
#-----------------------------------------------------------------------
# Bundle
#-----------------------------------------------------------------------
if (BUILD_BINARIES)
if (BUNDLE_LIBRARIES AND BUNDLING_SUPPORTED)
add_subdirectory(bundle)
endif ()
endif ()
#-----------------------------------------------------------------------
# Libraries
#-----------------------------------------------------------------------
if (BUILD_BINARIES)
add_subdirectory(libs)
endif ()
#-----------------------------------------------------------------------
# Radiant
#-----------------------------------------------------------------------
if (BUILD_BINARIES)
macro (radiant_tool name)
add_dependencies(binaries ${name})
if (WIN32)
add_executable(${name} ${ARGN} ${PROJECT_SOURCE_DIR}/include/lib.rc)
else ()
add_executable(${name} ${ARGN})
endif()
copy_dlls(${name})
install(
TARGETS ${name}
RUNTIME DESTINATION ${RADIANT_BIN_DIR}
)
endmacro ()
endif ()
#-----------------------------------------------------------------------
# Tools
#-----------------------------------------------------------------------
if (BUILD_TOOLS)
add_subdirectory(tools)
file(GLOB DATA_FILES "${PROJECT_SOURCE_DIR}/setup/data/tools/*")
if (NOT (PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR))
# Copy data files from sources to the build directory
message(STATUS "Copying data files")
file(COPY ${DATA_FILES} DESTINATION "${PROJECT_BINARY_DIR}")
endif ()
endif ()
#-----------------------------------------------------------------------
# Install
#-----------------------------------------------------------------------
install(
FILES
DESTINATION .
)
include(cmake/scripts/package.cmake)