forked from Robot/robot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
294 lines (244 loc) · 9.68 KB
/
CMakeLists.txt
File metadata and controls
294 lines (244 loc) · 9.68 KB
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
################################################################################
## -------------------------------------------------------------------------- ##
## ##
## (C) 2010-2016 Robot Developers ##
## See LICENSE for licensing info ##
## ##
## -------------------------------------------------------------------------- ##
################################################################################
################################################################################
# Project Setup
cmake_minimum_required(VERSION 3.2)
project(Robot)
################################################################################
# Tools
# A tool for troubleshooting, to make sure we got all the files
# can be removed without affecting built binaries
function(DisplayList Header ListToShow)
message(STATUS "\t${Header}")
foreach(ListItem ${ListToShow})
message(STATUS "\t\t${ListItem}")
endforeach(ListItem ${ListToShow})
endfunction(DisplayList)
# Variables to allow us to change these things in the future
set(ProjectRootDir ${${PROJECT_NAME}_SOURCE_DIR}/)
set(ProjectBinaryDir ${${PROJECT_NAME}_BINARY_DIR}/)
set(SourceDir "${ProjectRootDir}Source/")
set(HeaderDir "${ProjectRootDir}Source/")
set(TestSourceDir "${ProjectRootDir}Test/")
set(TestHeaderDir "${ProjectRootDir}Test/")
################################################################################
# Define Source Files
# We could use a globbing expression, but is generally poor form, because
# eventually someone accidentally adds an incorrect file to their build and
# something hard to fix breaks. When there is only one place to update file list
# it is not that painful.
#
# Here are four globbing expressions that appear to work.
#file(GLOB SourceFileList ${SourceDir}*.cc)
#DisplayList("Source Files" "${SourceFileList}")
#file(GLOB HeaderFileList ${HeaderDir}*.h)
#DisplayList("Header Files" "${HeaderFileList}")
#file(GLOB TestSourceFileList ${TestSourceDir}*.cc)
#DisplayList("Test Source Files" "${TestSourceFileList}")
#file(GLOB TestHeaderFileList ${TestHeaderDir}*.h)
#DisplayList("Test Header Files" "${TestHeaderFileList}")
set(SourceFileList
"${SourceDir}Bounds.cc"
"${SourceDir}Clipboard.cc"
"${SourceDir}Color.cc"
"${SourceDir}Hash.cc"
"${SourceDir}Image.cc"
"${SourceDir}Keyboard.cc"
"${SourceDir}Memory.cc"
"${SourceDir}Module.cc"
"${SourceDir}Mouse.cc"
"${SourceDir}Point.cc"
"${SourceDir}Process.cc"
"${SourceDir}Range.cc"
"${SourceDir}Screen.cc"
"${SourceDir}Size.cc"
"${SourceDir}Timer.cc"
"${SourceDir}Window.cc"
)
DisplayList("Source Files" "${SourceFileList}")
set(HeaderFileList
"${HeaderDir}Bounds.h"
"${HeaderDir}Bounds.h"
"${HeaderDir}Clipboard.h"
"${HeaderDir}Color.h"
"${HeaderDir}Enum.h"
"${HeaderDir}Global.h"
"${HeaderDir}Hash.h"
"${HeaderDir}Image.h"
"${HeaderDir}Keyboard.h"
"${HeaderDir}Memory.h"
"${HeaderDir}Module.h"
"${HeaderDir}Mouse.h"
"${HeaderDir}Point.h"
"${HeaderDir}Process.h"
"${HeaderDir}Range.h"
"${HeaderDir}Robot.h"
"${HeaderDir}Screen.h"
"${HeaderDir}Size.h"
"${HeaderDir}Timer.h"
"${HeaderDir}Types.h"
"${HeaderDir}Window.h"
)
DisplayList("Header Files" "${HeaderFileList}")
set(TestSourceFileList
"${TestSourceDir}Clipboard.cc"
"${TestSourceDir}Keyboard.cc"
"${TestSourceDir}Main.cc"
"${TestSourceDir}Memory.cc"
"${TestSourceDir}Mouse.cc"
"${TestSourceDir}Process.cc"
"${TestSourceDir}Screen.cc"
"${TestSourceDir}Targa.cc"
"${TestSourceDir}Timer.cc"
"${TestSourceDir}Types.cc"
"${TestSourceDir}Window.cc"
)
DisplayList("Test Source Files" "${TestSourceFileList}")
set(TestHeaderFileList
"${TestHeaderDir}Targa.h"
"${TestHeaderDir}Test.h"
)
DisplayList("Test Header Files" "${TestHeaderFileList}")
#set(PeonSourceFileList
# "${TestSourceDir}Peon.cc"
#)
#DisplayList("Peon Source Files" "${PeonSourceFileList}")
################################################################################
# Detect Platform
set(SystemIsLinux OFF)
set(SystemIsWindows OFF)
set(SystemIsMacOSX OFF)
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
message(STATUS "\tDetected OS as 'Linux'.")
set(SystemIsLinux ON)
endif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
message(STATUS "\tDetected OS as 'Windows'.")
set(SystemIsWindows ON)
endif("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
if("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
message(STATUS "\tDetected OS as 'Mac OS X'.")
set(SystemIsMacOSX ON)
endif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
################################################################################
# Detect Compiler
set(CompilerIsGCC OFF)
set(CompilerIsClang OFF)
set(CompilerIsIntel OFF)
set(CompilerIsMsvc OFF)
set(CompilerDesignNix OFF)
set(CompilerDesignMS OFF)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
message(STATUS "\tDetected compiler as 'GCC'.")
set(CompilerIsGCC ON)
set(CompilerDesignNix ON)
endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
message(STATUS "\tDetected compiler as 'Clang'.")
set(CompilerIsClang ON)
set(CompilerDesignNix ON)
endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
message(STATUS "\tDetected compiler as 'Intel'.")
set(CompilerIsIntel ON)
set(CompilerDesignNix ON)
endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
message(STATUS "\tDetected compiler as 'MSVC'.")
set(CompilerIsMsvc ON)
set(CompilerDesignMS ON)
endif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
################################################################################
# Set up build
# When using the CMake-gui this creates a checkbox
option(BuildStatic "Set for Static library, unset for Dynamic library." ON)
if(BuildStatic)
set(BuildType "STATIC")
else(BuildStatic)
set(BuildType "SHARED")
endif(BuildStatic)
message(STATUS "\tLibrary Build type '${BuildType}'.")
if(CompilerIsGCC)
add_definitions("-iquote${HeaderDir}" "-iquote${TestHeaderDir}")
else(CompilerIsGCC)
include_directories("${HeaderDir}" "${TestHeaderDir}")
endif(CompilerIsGCC)
################################################################################
# System Specific Settings
if(CompilerDesignNix)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread")
# Extra flags for warnings.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-pedantic -Wall -Wextra -Wcast-align -Wcast-qual\ -Wctor-dtor-privacy\
-Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op\
-Wmissing-declarations -Wmissing-include-dirs -Wnoexcept\
-Wold-style-cast -Wredundant-decls -Wshadow -Wsign-conversion\
-Wsign-promo -Wstrict-null-sentinel -Wstrict-overflow=2 -Wundef\
-Wno-unused -Wparentheses")
endif(CompilerDesignNix)
if(CompilerIsMsvc)
# Put msvc compiler flags here.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")
endif(CompilerIsMsvc)
################################################################################
# Make build targets
# For those unfamiliar with CMake. When it spits out build files, like make
# files, ninja scripts or vs solutions, these are the top level objects
# presented to the developer.
#
# So a dev can type "make Robot" to build the library or can type "ninja Test"
# to build Test and everything it requires.
#
# If used to create files for IDEs like Code::Blocks, visual studio, or
# QtCreator these will show up appropriately as different projects or build
# targets.
add_library(Robot "${BuildType}" "${HeaderFileList}" "${SourceFileList}")
add_executable(TestRobot "${TestHeaderFileList}" "${TestSourceFileList}")
set_target_properties(TestRobot PROPERTIES SUFFIX ".BIN")
set_target_properties(TestRobot PROPERTIES OUTPUT_NAME "Test")
#add_executable(TestPeon "${PeonSourceFileList}")
# set_target_properties(TestPeon PROPERTIES SUFFIX ".BIN")
# set_target_properties(TestPeon PROPERTIES OUTPUT_NAME "Peon")
################################################################################
# Link Build Targets
set(LinkLibraries "")
if(SystemIsLinux)
# rt & X11 - Seem unneeded build succeeded without it
# These lines search the path and common include directories for the
# platform this allows for more platforms to be supported as long as they
# expose some way that the cmake knows how to look for them
find_library(Xtst_lib Xtst)
find_library(Xinerama_lib Xinerama)
find_package ( X11 REQUIRED )
if(X11_FOUND)
include_directories(${X11_INCLUDE_DIR})
link_libraries(${X11_LIBRARIES})
#message(STATUS " X11_INCLUDE_DIR: ${X11_INCLUDE_DIR}")
#message(STATUS " X11_LIBRARIES: ${X11_LIBRARIES}")
endif(X11_FOUND)
set(LinkLibraries ${LinkLibraries} ${Xtst_lib} ${Xinerama_lib} ${X11_LIBRARIES})
endif(SystemIsLinux)
if(SystemIsWindows AND CompilerIsGCC)
set(LinkLibraries ${LinkLibraries} Shlwapi psapi)
endif(SystemIsWindows AND CompilerIsGCC)
target_link_libraries(Robot "${LinkLibraries}")
target_link_libraries(TestRobot Robot)
#target_link_libraries(TestPeon Robot)
if(NOT BuildStatic)
# Adds the definition when building robot
target_compile_definitions(Robot PRIVATE -DBUILDING_ROBOT_SHARED)
# Adds the definition when something else links against Robot
target_compile_definitions(Robot INTERFACE -DUSING_ROBOT_SHARED)
endif(NOT BuildStatic)
# TODO
# install process
# d in debug build
# objective C++ and other mac stuff
# Peon Offset details
# Figure out any special VS specific logic. I don't think is any beyound /W3