-
Notifications
You must be signed in to change notification settings - Fork 133
/
CMakeLists.txt
311 lines (267 loc) · 8.91 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
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
cmake_minimum_required(VERSION 3.5)
## Project branding, version and package mantainer
project(grSim)
set(VERSION "1.0.0a2")
#set(VENDOR "Parsian")
set(MAINTAINER "Mani Monajjemi <[email protected]>")
# some utils and helper vars
string(TOLOWER ${CMAKE_PROJECT_NAME} CMAKE_PROJECT_NAME_LOWER)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
include(${PROJECT_SOURCE_DIR}/cmake/Utils.cmake)
standard_config()
standard_paths(${PROJECT_SOURCE_DIR} bin lib)
# policy regarding how to handle generated stuff, OLD behavior would ignore generated files
# (which includes the generated protobuf cpp files)
if (POLICY CMP0071)
cmake_policy(SET CMP0071 NEW)
endif()
# policy regarding when to rebuild stuff when external projects downloaded with URL changes
if (POLICY CMP0135)
cmake_policy(SET CMP0135 NEW)
endif()
include(GNUInstallDirs)
set(app ${CMAKE_PROJECT_NAME})
# create the target before the sources list is known so that we can call
# add_dependencies(<target> external_proj)
add_executable(${app} "")
# definitions for knowing the OS from the code
if(MSVC)
add_definitions(-DHAVE_MSVC)
endif()
if(WIN32)
add_definitions(-DHAVE_WINDOWS)
endif()
if(UNIX)
add_definitions(-DHAVE_UNIX)
if(APPLE)
add_definitions(-DHAVE_MACOSX)
else()
#TODO: fix this, say we have FreeBSD, that's not linux
add_definitions(-DHAVE_LINUX)
endif()
endif()
# set explicitly the c++ standard to use
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
# add src dir to included directories
include_directories(${PROJECT_SOURCE_DIR}/include)
include_directories(${PROJECT_SOURCE_DIR}/include/net)
include_directories(${PROJECT_SOURCE_DIR}/include/physics)
## Handling depenendcies
# we will append all libs to this var
set(libs)
# OpenGL
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
list(APPEND libs ${OPENGL_LIBRARIES})
#find_package(GLUT REQUIRED)
#include_directories(${GLUT_INCLUDE_DIR})
# Qt
if(APPLE AND EXISTS /usr/local/opt/qt)
# Homebrew installs Qt5 (up to at least 5.9.1) in
# /usr/local/qt5, ensure it can be found by CMake since
# it is not in the default /usr/local prefix.
list(APPEND CMAKE_PREFIX_PATH "/usr/local/opt/qt")
endif()
find_package(Qt5 COMPONENTS Core Widgets OpenGL Network REQUIRED)
list(APPEND libs Qt5::Core Qt5::Widgets Qt5::OpenGL Qt5::Network)
# ODE
if(BUILD_ODE)
include(BuildODE)
add_dependencies(${app} ode_external)
else()
if(WIN32)
find_package(ODE CONFIG)
set(ODE_LIB_NAME ODE::ODE)
else()
find_package(ODE)
set(ODE_LIB_NAME ode::ode)
endif()
if(ODE_FOUND)
list(APPEND libs ${ODE_LIB_NAME})
else()
# if ODE could not be found just build it
include(BuildODE)
add_dependencies(${app} ode_external)
endif()
endif()
# VarTypes
find_package(VarTypes)
if(NOT VARTYPES_FOUND)
include(ExternalProject)
set(VARTYPES_CMAKE_ARGS "-DVARTYPES_BUILD_STATIC=ON;-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>")
if(NOT "${CMAKE_TOOLCHAIN_FILE}" STREQUAL "")
set(VARTYPES_CMAKE_ARGS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE};${VARTYPES_CMAKE_ARGS}")
endif()
ExternalProject_Add(vartypes_external
GIT_REPOSITORY https://github.com/jpfeltracco/vartypes
GIT_TAG origin/jpfeltracco/build_static
CMAKE_ARGS "${VARTYPES_CMAKE_ARGS}"
STEP_TARGETS install
)
set(VARTYPES_LIB_SUBPATH "${CMAKE_INSTALL_LIBDIR}/${CMAKE_STATIC_LIBRARY_PREFIX}vartypes${CMAKE_STATIC_LIBRARY_SUFFIX}")
# the byproducts are available after the install step
ExternalProject_Add_Step(vartypes_external out
DEPENDEES install
BYPRODUCTS
"<INSTALL_DIR>/${VARTYPES_LIB_SUBPATH}"
)
add_dependencies(${app} vartypes_external)
ExternalProject_Get_Property(vartypes_external install_dir)
add_dependencies(${app} vartypes_external)
set(VARTYPES_INCLUDE_DIRS "${install_dir}/include")
set(VARTYPES_LIBRARIES "${install_dir}/${VARTYPES_LIB_SUBPATH}")
endif()
target_include_directories(${app} PRIVATE ${VARTYPES_INCLUDE_DIRS})
list(APPEND libs ${VARTYPES_LIBRARIES})
# Protobuf
include(FindOrBuildProtobuf)
if(TARGET protobuf_external)
add_dependencies(${app} protobuf_external)
endif()
include_directories(${Protobuf_INCLUDE_DIRS})
list(APPEND libs ${Protobuf_LIBRARIES})
set (Protobuf_IMPORT_DIRS ${Protobuf_INCLUDE_DIR})
protobuf_generate_cpp(PROTO_CPP PROTO_H
src/proto/grSim_Commands.proto
src/proto/grSim_Packet.proto
src/proto/grSim_Replacement.proto
src/proto/grSim_Robotstatus.proto
src/proto/ssl_gc_common.proto
src/proto/ssl_simulation_config.proto
src/proto/ssl_simulation_control.proto
src/proto/ssl_simulation_error.proto
src/proto/ssl_simulation_robot_control.proto
src/proto/ssl_simulation_robot_feedback.proto
src/proto/ssl_simulation_synchronous.proto
src/proto/ssl_vision_detection.proto
src/proto/ssl_vision_geometry.proto
src/proto/ssl_vision_wrapper.proto
)
qt5_add_resources(RESOURCES
resources/textures.qrc
)
set(RESOURCES
${RESOURCES}
resources/grsim.rc
)
set(SOURCES
src/main.cpp
src/mainwindow.cpp
src/glwidget.cpp
src/graphics.cpp
src/physics/pworld.cpp
src/physics/pobject.cpp
src/physics/pball.cpp
src/physics/pground.cpp
src/physics/pfixedbox.cpp
src/physics/pcylinder.cpp
src/physics/pbox.cpp
src/physics/pray.cpp
src/net/robocup_ssl_server.cpp
src/net/robocup_ssl_client.cpp
src/sslworld.cpp
src/robot.cpp
src/configwidget.cpp
src/statuswidget.cpp
src/logger.cpp
src/robotwidget.cpp
src/getpositionwidget.cpp
)
set(HEADERS
include/mainwindow.h
include/glwidget.h
include/graphics.h
include/physics/pworld.h
include/physics/pobject.h
include/physics/pball.h
include/physics/pground.h
include/physics/pfixedbox.h
include/physics/pcylinder.h
include/physics/pbox.h
include/physics/pray.h
include/net/robocup_ssl_server.h
include/net/robocup_ssl_client.h
include/sslworld.h
include/robot.h
include/configwidget.h
include/statuswidget.h
include/logger.h
include/robotwidget.h
include/getpositionwidget.h
include/common.h
include/config.h
)
# files to be compiled
set(srcs
${CONFIG_FILES}
${PROTO_CPP}
${PROTO_H}
${RESOURCES}
${HEADERS}
${SOURCES}
)
file(GLOB CONFIG_FILES "config/*.ini")
set_source_files_properties(${CONFIG_FILES} PROPERTIES MACOSX_PACKAGE_LOCATION "config")
target_sources(${app} PRIVATE ${srcs})
install(TARGETS ${app} DESTINATION bin)
target_link_libraries(${app} ${libs})
if(APPLE AND CMAKE_MACOSX_BUNDLE)
# use CMAKE_MACOSX_BUNDLE if you want to build a mac bundle
set(MACOSX_BUNDLE_ICON_FILE "${PROJECT_SOURCE_DIR}/resources/icons/grsim.icns")
set(MACOSX_BUNDLE_SHORT_VERSION_STRING ${VERSION})
set(MACOSX_BUNDLE_VERSION ${VERSION})
set(MACOSX_BUNDLE_LONG_VERSION_STRING "Version ${VERSION}")
set(BUNDLE_APP ${PROJECT_SOURCE_DIR}/bin/${app}.app)
install(
CODE "
include(BundleUtilities)
fixup_bundle(\"${BUNDLE_APP}\" \"\" \"/opt/local/lib;/usr/local/lib\")"
COMPONENT Runtime)
set(CPACK_GENERATOR "DragNDrop" "TGZ")
elseif(WIN32 AND CMAKE_WIN32_EXECUTABLE)
# use CMAKE_WIN32_EXECUTABLE if you want to build a windows exe
install(DIRECTORY config DESTINATION .)
install(DIRECTORY bin DESTINATION .
FILES_MATCHING PATTERN "*.dll")
set(CPACK_PACKAGE_EXECUTABLES ${app} ${app})
else()
install(DIRECTORY config DESTINATION share/${app})
install(FILES resources/grsim.desktop DESTINATION share/applications)
install(FILES resources/icons/grsim.svg DESTINATION share/icons/hicolor/scalable/apps)
endif()
option(BUILD_CLIENTS "Choose this option if you want to build the example Qt client." ON)
if(BUILD_CLIENTS)
add_subdirectory(clients/qt)
endif()
file(COPY README.md LICENSE.md DESTINATION ${CMAKE_BINARY_DIR})
file(RENAME ${CMAKE_BINARY_DIR}/README.md ${CMAKE_BINARY_DIR}/README.txt)
file(RENAME ${CMAKE_BINARY_DIR}/LICENSE.md ${CMAKE_BINARY_DIR}/LICENSE.txt)
## Packaging
if(UNIX)
execute_process(COMMAND uname -p OUTPUT_VARIABLE ARCH)
string(STRIP ${ARCH} ARCH)
if(APPLE)
set(ARCH "osx-universal")
endif()
elseif(WIN32)
set(ARCH "win32")
set(CPACK_GENERATOR ZIP NSIS)
endif()
set(CPACK_OUTPUT_FILE_PREFIX ${PROJECT_SOURCE_DIR}/dist)
set(CPACK_PACKAGE_CONTACT ${MAINTAINER})
if(VENDOR)
set(CPACK_PACKAGE_VENDOR ${VENDOR})
string(TOLOWER ${CPACK_PACKAGE_VENDOR} FLAVOR)
endif()
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_BINARY_DIR}/LICENSE.txt")
set(CPACK_RESOURCE_FILE_README "${CMAKE_BINARY_DIR}/README.txt")
#set(CPACK_RESOURCE_FILE_WELCOME "${CMAKE_SOURCE_DIR}/WELCOME.txt")
set(CPACK_PACKAGE_VERSION ${VERSION})
# Debian based specific
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libode1 (>=0.11), vartypes (>=0.7.0)")
if(FLAVOR)
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME_LOWER}_${CPACK_PACKAGE_VERSION}-${FLAVOR}_${ARCH}")
else()
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME_LOWER}_${CPACK_PACKAGE_VERSION}_${ARCH}")
endif()
include(CPack)