-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
219 lines (184 loc) · 8.15 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
cmake_minimum_required(VERSION 2.8.3)
project(grip2)
# Define some colors for fun output
if(NOT WIN32)
string(ASCII 27 Esc)
set(ColorReset "${Esc}[m")
set(Red "${Esc}[1;31m")
set(Yellow "${Esc}[1;33m")
endif()
if(APPLE)
set(X11_THREADS_LIB "X11")
# set X11 include path for Mac OS X
include_directories(/opt/X11/include)
link_directories(/opt/X11/lib)
else(APPLE)
# linux uses rt for XInitThreads()
set(X11_THREADS_LIB "rt")
endif()
#-----------------------------------------------
# COMPILE SETTINGS
#-----------------------------------------------
set(CMAKE_BUILD_TYPE "Debug")
list(APPEND CMAKE_CXX_FLAGS "-std=c++0x -Wall")
# set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/build)
# set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR}/lib)
# Define preprocessor macro for Debug printing in Debug mode
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "\nBuilding in \"Debug\" mode.\n-- CMAKE_CXX_FLAGS_DEBUG is ${CMAKE_CXX_FLAGS_DEBUG}")
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
message(STATUS "\nBuilding in \"Release\" mode.\n-- CMAKE_CXX_FLAGS_RELEASE is ${CMAKE_CXX_FLAGS_RELEASE}")
else()
endif()
#-----------------------------------------------
# UNINSTALL TARGET
#-----------------------------------------------
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
#-----------------------------------------------
# FIND PACKAGES
#-----------------------------------------------
# add local include to include path (for source installs; should be cmake default)
include_directories(/usr/local/include)
# Find QT
find_package(Qt4 COMPONENTS QtCore QtGui QtOpenGL QtXml REQUIRED) # Qt3Support
add_definitions(${QT_DEFINITIONS})
include(${QT_USE_FILE})
# try to find the OpenSceneGraph cmake package
find_package(OpenSceneGraph 3.0 QUIET
COMPONENTS osg osgViewer osgManipulator osgGA osgDB)
find_package(OpenSceneGraph 3.0 QUIET COMPONENTS osgQt)
if(${OpenSceneGraph_FOUND})
message("Found OpenSceneGraph cmake package.")
include_directories(${OpenSceneGraph_INCLUDE_DIRS})
add_definitions(${OpenSourceGraph_DEFINITIONS})
set(OPENSCENEGRAPH_LIBRARIES ${OPENSCENEGRAPH_LIBRARIES} osgQt)
else(${OpenSceneGraph_FOUND})
message("OpenSceneGraph cmake package not found. Searching for library...")
find_library(OpenSceneGraph REQUIRED
COMPONENTS osg osgViewer osgManipulator osgGA osgDB osgQt)
if(${OpenSceneGraph-NOTFOUND})
message("OpenSceneGraph library not found!")
else(${OpenSceneGraph-NOTFOUND})
message("Found installed OpenSceneGraph library.")
endif()
if(APPLE)
set(OSG_LIBRARY_PATH "/usr/local/lib") # works on OSX 10.9.4
set(LIB_SUFFIX "dylib")
else(APPLE)
# set(OSG_LIBRARY_PATH "/usr/local/lib64") # works on ubuntu 14.04, src install
set(OSG_LIBRARY_PATH "/usr/lib") # works on ubuntu 14.04, apt-get install
set(LIB_SUFFIX "so")
endif()
set(OPENSCENEGRAPH_LIBRARIES ${OSG_LIBRARY_PATH}/libosg.${LIB_SUFFIX}
${OSG_LIBRARY_PATH}/libosgViewer.${LIB_SUFFIX}
${OSG_LIBRARY_PATH}/libosgManipulator.${LIB_SUFFIX}
${OSG_LIBRARY_PATH}/libosgGA.${LIB_SUFFIX}
${OSG_LIBRARY_PATH}/libosgDB.${LIB_SUFFIX}
${OSG_LIBRARY_PATH}/libOpenThreads.${LIB_SUFFIX}
${OSG_LIBRARY_PATH}/libosgQt.${LIB_SUFFIX}
${OSG_LIBRARY_PATH}/libosg.${LIB_SUFFIX}
${OSG_LIBRARY_PATH}/libosg.${LIB_SUFFIX}
${OSG_LIBRARY_PATH}/libOpenThreads.${LIB_SUFFIX})
endif()
# Find Eigen3
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
find_package(Eigen REQUIRED)
include_directories(${Eigen_INCLUDE_DIR})
# Find DART
find_package(DART REQUIRED)
include_directories(${DART_INCLUDE_DIRS})
link_directories(${DART_LIBRARY_DIRS})
#-----------------------------------------------
# INCLUDES & SUBDIRECTORY LIBRARIRES
#-----------------------------------------------
include_directories(include)
include_directories(${CMAKE_BINARY_DIR}/qtWidgets)
# Add QT Widgets library
add_subdirectory(qtWidgets)
include_directories(qtWidgets)
# Add OpenSceneGraph Nodes library
add_subdirectory(osgGolems)
include_directories(osgGolems)
# Add DART OSG library
add_subdirectory(osgDart)
include_directories(osgDart)
# Set project libraries variable
set(project_libs qtWidgets osgGolems osgDart)
# Add Main Window library
QT4_WRAP_CPP(GUI_MOC_HEADERS ${PROJECT_SOURCE_DIR}/include/MainWindow.h ${PROJECT_SOURCE_DIR}/include/GripSimulation.h)
file(GLOB GUI_SRC include/*.h src/*.cpp)
LIST(REMOVE_ITEM GUI_SRC "${CMAKE_CURRENT_LIST_DIR}/include/TestMainWindow.h"
"${CMAKE_CURRENT_LIST_DIR}/src/TestMainWindow.cpp")
add_library(mainWindow SHARED ${GUI_MOC_HEADERS} ${GUI_SRC})
target_link_libraries(mainWindow ${project_libs} ${QT_LIBRARIES} ${DART_LIBRARIES} ${X11_THREADS_LIB})
# Set project libraries variable
set(project_libs ${project_libs} mainWindow)
#-----------------------------------------------
# BUILD GRIP
#-----------------------------------------------
# QT4_WRAP_CPP(TEST_MOC_HEADERS ${PROJECT_SOURCE_DIR}/include/TestMainWindow.h)
# FILE(GLOB TEST_SRC src/TestMainWindow.cpp)
# add_library(grip-test SHARED ${TEST_MOC_HEADERS} ${TEST_SRC})
# target_link_libraries(grip-test ${QT_LIBRARIES} ${DART_LIBRARIES} ${OPENSCENEGRAPH_LIBRARIES})
add_executable(grip ${PROJECT_SOURCE_DIR}/src/grip.cpp)
target_link_libraries(grip ${project_libs} ${QT_LIBRARIES} ${DART_LIBRARIES} ${OPENSCENEGRAPH_LIBRARIES})
FILE(GLOB grip-srcs osgGolems/*.h osgGolems/src/*.cpp osgDart/*.h osgDart/src/*.cpp qtWidgets/*.h qtWidgets/src/*.cpp)
add_library(grip-core SHARED ${grip-srcs})
target_link_libraries(grip-core ${project_libs} ${QT_LIBRARIES} ${DART_LIBRARIES} ${OPENSCENEGRAPH_LIBRARIES})
add_library(grip-interface SHARED src/GripInterface.cpp include/GripInterface.h)
target_link_libraries(grip-interface ${project_libs} ${QT_LIBRARIES} ${DART_LIBRARIES} ${OPENSCENEGRAPH_LIBRARIES})
#-----------------------------------------------
# BUILD TESTS
#-----------------------------------------------
# Get test files
file(GLOB unit_tests_source "test/*.cpp")
LIST(SORT unit_tests_source)
# Build test programs
message(STATUS "\n-- UNIT TEST: ")
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})
foreach(utest_src_file ${unit_tests_source})
get_filename_component(test_base ${utest_src_file} NAME_WE)
message(STATUS "Adding test ${test_base}")
add_executable(${test_base} ${utest_src_file})
target_link_libraries(${test_base} ${project_libs} ${DART_LIBRARIES} ${OPENSCENEGRAPH_LIBRARIES} ${QT_LIBRARIES})
add_test(${test_base} ${EXECUTABLE_OUTPUT_PATH}/${test_base})
add_custom_target(${test_base}.run ${test_base} ${ARGN})
add_dependencies(check ${test_base})
endforeach(utest_src_file)
#-----------------------------------------------
# INSTALLATION
#-----------------------------------------------
# Install grip
INSTALL(PROGRAMS "${EXECUTABLE_OUTPUT_PATH}/grip"
DESTINATION /usr/local/bin/)
# Install library of grips libraries
INSTALL(TARGETS grip-core
DESTINATION lib/)
# Install header files by namespace and directory
FILE(GLOB osgDartHeaders "osgDart/*.h")
INSTALL(FILES ${osgDartHeaders}
DESTINATION include/grip/osgDart/)
FILE(GLOB osgGolemsHeaders "osgGolems/*.h")
INSTALL(FILES ${osgGolemsHeaders}
DESTINATION include/grip/osgGolems/)
FILE(GLOB qtWidgetsHeaders "qtWidgets/*.h")
INSTALL(FILES ${qtWidgetsHeaders}
DESTINATION include/grip/qtWidgets/)
FILE(GLOB mainHeaders "include/*.h")
INSTALL(FILES ${mainHeaders}
DESTINATION include/grip/include/)
# Install cmake find file for grip
INSTALL(FILES cmake/FindGRIP.cmake
DESTINATION share/cmake/)
# Install desktop file to call grip from desktop
INSTALL(FILES "doc/grip.desktop"
DESTINATION share/applications/)
INSTALL(FILES "src/icons/grip-icon.png"
DESTINATION share/icons/)