-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCMakeLists.txt
249 lines (205 loc) · 7.42 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
#-------------------------------------------------------------------------------
# CMAKE SETTINGS
#-------------------------------------------------------------------------------
cmake_minimum_required(VERSION 2.8.12)
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
set(QT_MINIMUM_VERSION 5.9.0)
#-------------------------------------------------------------------------------
# BUILD OPTIONS
#-------------------------------------------------------------------------------
OPTION(BUILD_TESTS "Build unit tests" ON)
#-------------------------------------------------------------------------------
# SOURCE CODE
#-------------------------------------------------------------------------------
# .h files
list(APPEND HEADER_FILES
include/bluetooth.h
include/bluetoothAddress.h
include/bluetoothDevice.h
include/bluetoothDeviceDiscoveryAgent.h
include/bluetoothDeviceInfo.h
include/bluetoothEnums.h
include/bluetoothException.h
include/bluetoothHostInfo.h
include/bluetoothLocalDevice.h
include/bluetoothRadio.h
include/bluetoothServer.h
include/bluetoothServiceDiscoveryAgent.h
include/bluetoothServiceInfo.h
include/bluetoothSocket.h
include/bluetoothSocket_p.h
include/bluetoothTransferManager.h
include/bluetoothTransferReply.h
include/bluetoothTransferRequest.h
include/bluetoothUtils.h
include/bluetoothUuids.h
include/obexHeader.h
include/obexOptionalHeaders.h
include/obexRequest.h
include/obexResponse.h
include/gsl-lite.h
include/QStringHash.h
)
# .cpp files
list(APPEND SOURCE_FILES
src/bluetooth.cpp
src/bluetoothAddress.cpp
src/bluetoothDevice.cpp
src/bluetoothDeviceDiscoveryAgent.cpp
src/bluetoothDeviceInfo.cpp
src/bluetoothException.cpp
src/bluetoothHostInfo.cpp
src/bluetoothLocalDevice.cpp
src/bluetoothRadio.cpp
src/bluetoothServer.cpp
src/bluetoothServiceDiscoveryAgent.cpp
src/bluetoothServiceInfo.cpp
src/bluetoothSocket.cpp
src/bluetoothSocket_p.cpp
src/bluetoothTransferManager.cpp
src/bluetoothTransferReply.cpp
src/bluetoothTransferRequest.cpp
src/bluetoothUtils.cpp
src/bluetoothUuids.cpp
src/obexHeader.cpp
src/obexOptionalHeaders.cpp
src/obexRequest.cpp
src/obexResponse.cpp
)
# on windows, append headers to source so they show up in visual studio
if(WIN32)
LIST(APPEND SOURCE_FILES ${HEADER_FILES})
endif()
#-------------------------------------------------------------------------------
# PROJECT SETTINGS
#-------------------------------------------------------------------------------
set(TARGET_NAME win-bluetooth)
# Use git branch as project name if clones from git
find_package(Git)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE BRANCH
OUTPUT_STRIP_TRAILING_WHITESPACE
)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --abbrev=0 --tags
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(PROJECT_NAME ${TARGET_NAME}-${BRANCH})
else()
set(PROJECT_NAME ${TARGET_NAME})
endif()
# Set the project name
PROJECT(${PROJECT_NAME})
#-------------------------------------------------------------------------------
# Qt Settings
#-------------------------------------------------------------------------------
# Required Qt settings
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(QT_USE_QTMAIN TRUE)
# Setup the cmake prefix path so Qt can be found. Use the QTDIR variable if defined
if(NOT DEFINED ENV{QTDIR})
MESSAGE(STATUS "QTDIR environment variable not set. Be sure to set the QTDIR
cmake cache variable to the Qt root install location")
endif()
set(QTDIR $ENV{QTDIR} CACHE STRING "Qt install path")
list(APPEND CMAKE_PREFIX_PATH ${QTDIR})
# Find the necessary Qt5 modules
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Network REQUIRED)
# Test for supported Qt version
find_program(QMAKE_EXECUTABLE NAMES qmake HINTS ${QTDIR} ENV QTDIR PATH_SUFFIXES bin)
execute_process(COMMAND ${QMAKE_EXECUTABLE} -query QT_VERSION OUTPUT_VARIABLE QT_VERSION)
if(QT_VERSION VERSION_LESS QT_MINIMUM_VERSION)
MESSAGE(FATAL_ERROR "Minimum supported Qt version: ${QT_MINIMUM_VERSION}. Installed version: ${QT_VERSION}")
endif()
# find thread library
find_package(Threads REQUIRED)
#-------------------------------------------------------------------------------
# RESOURCES
#-------------------------------------------------------------------------------
#list(APPEND RESOURCES
#resources/resources.qrc
#)
#qt5_add_resources(RESOURCES ${QT_RESOURCES})
#list(APPEND RESOURCES
#resources/resources.rc
#)
#-------------------------------------------------------------------------------
# COMPILE FLAGS
#-------------------------------------------------------------------------------
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 17)
if(MSVC)
add_compile_options(/MP)
add_compile_options(/std:c++17)
elseif(CMAKE_COMPILER_IS_GNUCXX)
add_compile_options(-std=c++17)
endif(MSVC)
#-------------------------------------------------------------------------------
# CONFIGURATION
#-------------------------------------------------------------------------------
set(APPLICATION_NAME ${TARGET_NAME})
set(APPLICATION_VERSION ${VERSION})
set(APPLICATION_ORGANIZATION "Menari Softworks")
set(APPLICATION_ORGANIZATION_DOMAIN "https://github.com/nholthaus/")
configure_file(src/appinfo.h.in appinfo.h @ONLY NEWLINE_STYLE UNIX)
#-------------------------------------------------------------------------------
# SOURCE GROUPS
#-------------------------------------------------------------------------------
source_group(generated REGULAR_EXPRESSION "(.*_automoc.cpp)|(mocs?.*)")
source_group(resources REGULAR_EXPRESSION ".*[.][q]?rc")
source_group(source REGULAR_EXPRESSION ".*[.]cpp")
source_group(headers REGULAR_EXPRESSION ".*[.]h")
source_group(continuous-integration REGULAR_EXPRESSION ".*[.]yml")
#-------------------------------------------------------------------------------
# ADDITIONAL LIBRARIES
#-------------------------------------------------------------------------------
list(APPEND LIBRARIES
Qt5::Core
Qt5::Gui
Qt5::Widgets
Qt5::Network
Threads::Threads
)
# Remove duplicate library dependencies.
list(REMOVE_DUPLICATES LIBRARIES)
#-------------------------------------------------------------------------------
# ADDITIONAL INCLUDE DIRECTORIES
#-------------------------------------------------------------------------------
list(APPEND INCLUDE_DIRS
"./include"
)
# Remove duplicate library dependencies.
list(REMOVE_DUPLICATES INCLUDE_DIRS)
#-------------------------------------------------------------------------------
# GENERATE LIBRARY
#-------------------------------------------------------------------------------
# Set additional include directories
include_directories(${INCLUDE_DIRS})
# Generate the executable
add_library(${TARGET_NAME} STATIC ${SOURCE_FILES} ${RESOURCES})
# link libraries
target_link_libraries(${TARGET_NAME} ${LIBRARIES})
# Use the automatically determined RPATH values
set_target_properties(${TARGET_NAME} PROPERTIES INSTALL_RPATH_USE_LINK_PATH TRUE)
INSTALL(TARGETS ${TARGET_NAME} ARCHIVE DESTINATION lib)
INCLUDE(InstallRequiredSystemLibraries)
#-------------------------------------------------------------------------------
# UNIT TESTS
#-------------------------------------------------------------------------------
if(BUILD_TESTS)
set(VERSION_GTEST "1.8.0" CACHE STRING "Google Test framework version")
enable_testing()
add_subdirectory(3rdParty/gtest)
add_subdirectory(tests)
endif(BUILD_TESTS)