forked from synergylab-ntu/myKINOVA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
191 lines (155 loc) · 5.06 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
# ----------------------------------------------------------------------------
# CMakeLists.txt for C++ Kortex API Examples
# Copyright © 2018 Kinova Robotics
#
# Build instructions for the supported platforms (CMake only) :
#
# In Linux (x86-64 architecture):
# From the api_cpp/examples directory, invoke:
# $ mkdir build
# $ cd build/
# $ cmake ..
# $ make
#
# In Windows (MinGW) :
# From the api_cpp/examples directory, invoke:
# $ mkdir build
# $ cd build/
# $ cmake .. -G "MinGW Makefiles"
# $ mingw32-make
#
# In Windows (MSVC command line) :
# From the api_cpp/examples directory, invoke:
# $ call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliary\Build\vcvars64.bat" [MODIFY THIS PATH FOR YOURS]
# $ mkdir build
# $ cd build/
# $ cmake .. -G "NMake Makefiles"
# $ nmake
#
# ----------------------------------------------------------------------------
cmake_minimum_required(VERSION 3.5)
project(kortexApiCppExamples VERSION 2.2.0 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_COLOR_MAKEFILE ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_definitions(-D_USE_MATH_DEFINES)
find_package(RL COMPONENTS MDL REQUIRED)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
option(USE_CONAN "Use the Conan package manager to automatically fetch the Kortex API" OFF)
option(DOWNLOAD_API "Automatically download the API if conan is not used" OFF)
# Activate C++ 11
set (CMAKE_CXX_STANDARD 11)
macro(configure_msvc_runtime)
# Default to statically-linked runtime.
if("${MSVC_RUNTIME}" STREQUAL "")
set(MSVC_RUNTIME "static1")
endif()
# Set compiler options.
set(variables
CMAKE_C_FLAGS_DEBUG
CMAKE_C_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
)
if(${MSVC_RUNTIME} STREQUAL "static")
message(STATUS
"MSVC -> forcing use of statically-linked runtime."
)
foreach(variable ${variables})
if(${variable} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${variable} "${${variable}}")
endif()
endforeach()
else()
message(STATUS
"MSVC -> forcing use of dynamically-linked runtime."
)
foreach(variable ${variables})
if(${variable} MATCHES "/MT")
string(REGEX REPLACE "/MT" "/MD" ${variable} "${${variable}}")
endif()
endforeach()
endif()
endmacro()
include_directories(${PROJECT_SOURCE_DIR}/thirdParty/cxxopts/)
if(MSVC)
configure_msvc_runtime()
else()
add_compile_options(-Wall)
add_compile_options(-Wno-reorder)
endif()
if(UNIX)
add_definitions(-D_OS_UNIX)
elseif(WIN32)
add_definitions(-D_OS_WINDOWS -DNOMINMAX)
if(MSVC)
add_compile_options(/bigobj)
endif()
endif()
# Setup Kortex Api Path
if(NOT KORTEX_SUB_DIR)
set(KORTEX_SUB_DIR "")
else()
set(KORTEX_SUB_DIR "${KORTEX_SUB_DIR}/")
endif()
set(KORTEX_DIR "${PROJECT_SOURCE_DIR}/kortex_api/${KORTEX_SUB_DIR}")
if(CMAKE_BUILD_TYPE EQUAL "Debug")
set(KORTEX_LIB_SUBDIR "debug")
else()
set(KORTEX_LIB_SUBDIR "release")
endif()
# Download the API
if(UNIX)
execute_process(COMMAND ./download_kortex_api.sh ${KORTEX_SUB_DIR}
WORKING_DIRECTORY ../scripts
RESULT_VARIABLE DOWNLOAD_API_RESULT
OUTPUT_VARIABLE DOWNLOAD_API_OUTPUT)
if(NOT DOWNLOAD_API_RESULT EQUAL 0)
message("Kortex API was not downloaded prior to running CMake.")
message(FATAL_ERROR ${DOWNLOAD_API_OUTPUT})
endif()
link_libraries(${KORTEX_DIR}lib/${KORTEX_LIB_SUBDIR}/libKortexApiCpp.a)
elseif(WIN32)
execute_process(COMMAND ./download_kortex_api.bat ${KORTEX_SUB_DIR}
WORKING_DIRECTORY ../scripts
RESULT_VARIABLE DOWNLOAD_API_RESULT
OUTPUT_VARIABLE DOWNLOAD_API_OUTPUT)
# if(NOT DOWNLOAD_API_RESULT EQUAL 0)
# message("Kortex API was not downloaded prior to running CMake.")
# message(FATAL_ERROR ${DOWNLOAD_API_OUTPUT})
# endif()
link_libraries(${KORTEX_DIR}lib/${KORTEX_LIB_SUBDIR}/KortexApiCpp.lib)
endif()
# Add Include Directories
include_directories(${KORTEX_DIR}include)
include_directories(${KORTEX_DIR}include/client)
include_directories(${KORTEX_DIR}include/common)
include_directories(${KORTEX_DIR}include/messages)
include_directories(${KORTEX_DIR}include/client_stubs)
include_directories(${KORTEX_DIR}include/custom)
# link other libs
if(UNIX)
link_libraries(pthread)
elseif(WIN32)
link_libraries(winMM ws2_32)
else()
MESSAGE(FATAL_ERROR "Unknown os! Not supported yet")
endif()
# C++ Robotics Library
link_libraries(${RL_LIBRARIES})
# Create executable for each example
# Look for examples under folders
file(GLOB EXE_LIST RELATIVE ${PROJECT_SOURCE_DIR} "[0-9]*-*/[0-9]*.cpp")
foreach ( SRC_FILE ${EXE_LIST} )
string(REPLACE ".cpp" "" TARGET_EXE_NAME ${SRC_FILE})
string(REPLACE "/" "_" TARGET_EXE_NAME ${TARGET_EXE_NAME})
MESSAGE("creating TARGET_EXE_NAME: '${TARGET_EXE_NAME}'")
add_executable(${TARGET_EXE_NAME} ${SRC_FILE} utilities.cpp)
endforeach()