-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCMakeLists.txt
214 lines (174 loc) · 8.2 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
cmake_minimum_required(VERSION 3.10.2)
project(VirtualJukebox)
cmake_policy(SET CMP0054 NEW)
################################################################################
# Set default values for input parameter
################################################################################
# Build examples, unless specified otherwise
if(NOT DEFINED BUILD_EXAMPLES)
set(BUILD_EXAMPLES TRUE)
endif()
# Build debug version by default, unless specified otherwise
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
################################################################################
# Compiler settings
################################################################################
set(CMAKE_CXX_STANDARD 17)
set(CXX_STANDARD_REQUIRED ON)
set(SRC_COMPILER_OPTIONS
-Wall
-Wextra)
################################################################################
# Include other CMake files
################################################################################
include(cmake/ClangFormat.cmake)
include(cmake/LibMicroHttpd.cmake)
include(cmake/LibHttpServer.cmake)
include(cmake/LibRestClient-cpp.cmake)
include(cmake/GoogleTest.cmake)
################################################################################
# Find packages with built-in support
################################################################################
find_package(Doxygen)
find_package(Threads)
include(cmake/FindGlog.cmake)
################################################################################
# Source files
################################################################################
# Application and tests
#-------------------------------------------------------------------------------
# Source file containing the main entrypoint
set(ENTRYPOINT_SOURCE src/main.cpp)
# All source file (excluding main) for the application
set(APP_SOURCES src/JukeBox.cpp
src/Utils/LoggingHandler.cpp
src/Utils/ConfigHandler.cpp
src/Utils/Serializer.cpp
src/Utils/SimpleScheduler.cpp
src/Spotify/SpotifyBackend.cpp
src/Spotify/SpotifyAPITypes.cpp
src/Spotify/SpotifyAPI.cpp
src/Spotify/SpotifyAuthorization.cpp
src/NetworkAPI.cpp
src/Network/RestAPI.cpp
src/Network/RestRequestHandler.cpp
src/Network/RestEndpointHandlers.cpp
src/Datastore/RAMDataStore.cpp)
set(APP_HEADER src/JukeBox.h
src/MusicBackend.h
src/NetworkListener.h
src/DataStore.h
src/NetworkAPI.h
src/Types/Tracks.h
src/Types/Queue.h
src/Types/Result.h
src/Types/GlobalTypes.h
src/Utils/LoggingHandler.h
src/Utils/ConfigHandler.h
src/Utils/Serializer.h
src/Utils/SimpleScheduler.h
src/Spotify/SpotifyBackend.h
src/Spotify/SpotifyAPITypes.h
src/Spotify/SpotifyAPI.h
src/Spotify/SpotifyAuthorization.h
src/Network/RestAPI.h
src/Network/RestRequestHandler.h
src/Network/RestEndpointHandlers.h
src/Network/RequestInformation.h
src/Datastore/RAMDataStore.h)
# Libraries and include directories of dependencies used by the application
set(APP_LIBRARIES ${LIBHTTPSERVER_LIBRARIES}
${LIBMICROHTTPD_LIBRARIES}
${LIBRESTCLIENT_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${GLOG_LIBRARY})
set(APP_INCLUDE_DIRS src/
lib/
${LIBHTTPSERVER_INCLUDE_DIRS}
${LIBMICROHTTPD_INCLUDE_DIRS}
${LIBRESTCLIENT_INCLUDE_DIRS}
${GLOG_INCLUDE_DIRS})
# All source files containing test cases
set(TEST_SOURCES test/Test_ConfigHandler.cpp
test/Test_DataStore.cpp
test/Test_SpotifyAPI.cpp
test/Test_RestAPI.cpp
test/fixtures/RestAPIFixture.cpp
test/mocks/MockNetworkListener.cpp
test/helpers/NetworkListenerHelper.cpp
test/helpers/TrackGenerator.cpp
test/Test_JukeBox.cpp)
set(TEST_HEADER test/fixtures/RestAPIFixture.h
test/mocks/MockNetworkListener.h
test/helpers/NetworkListenerHelper.h)
# Libraries and include directories of dependencies used by the tests
set(TEST_LIBRARIES ${APP_LIBRARIES}
gtest)
set(TEST_INCLUDE_DIRS test/
test/fixtures/
test/mocks/
test/helpers/)
# Specify sources for formatting
set(FORMATTING_SOURCES ${ENTRYPOINT_SOURCE} ${APP_SOURCES} ${APP_HEADER} ${TEST_SOURCES} ${TEST_HEADER})
if(BUILD_EXAMPLES)
file(GLOB EXAMPLE_FORMATTING_SOURCES examples/*.cpp examples/*.h)
set(FORMATTING_SOURCES ${FORMATTING_SOURCES} ${EXAMPLE_FORMATTING_SOURCES})
endif()
# Documentation
#-------------------------------------------------------------------------------
set(DOC_SOURCES docs/src/main.md
docs/src/RESTInterface.md
docs/src/ClassDiagram.md)
################################################################################
# Targets
################################################################################
# Compile the sources of the main application into an OBJECT library
#-------------------------------------------------------------------------------
set(APP_OBJECTS app_object_library)
add_library(${APP_OBJECTS} OBJECT ${APP_SOURCES} ${APP_HEADER})
target_compile_options(${APP_OBJECTS} PRIVATE ${SRC_COMPILER_OPTIONS})
# Main program executable
#-------------------------------------------------------------------------------
include_directories(${APP_INCLUDE_DIRS})
add_executable(${PROJECT_NAME} ${ENTRYPOINT_SOURCE} $<TARGET_OBJECTS:${APP_OBJECTS}>)
target_link_libraries(${PROJECT_NAME} ${APP_LIBRARIES})
target_compile_options(${PROJECT_NAME} PRIVATE ${SRC_COMPILER_OPTIONS})
# Test program, running unit tests
#-------------------------------------------------------------------------------
set(TEST_TARGET test${PROJECT_NAME})
enable_testing()
# Add test executable and link to required libs
include_directories(${TEST_INCLUDE_DIRS})
add_executable(${TEST_TARGET} ${TEST_SOURCES} $<TARGET_OBJECTS:${APP_OBJECTS}>)
target_link_libraries(${TEST_TARGET} ${TEST_LIBRARIES})
target_compile_options(${TEST_TARGET} PRIVATE ${SRC_COMPILER_OPTIONS})
# Add test target, so tests can be executed using `make test`
add_test(${TEST_TARGET} ${TEST_TARGET})
# Other
#-------------------------------------------------------------------------------
clang_format_add_target(${FORMATTING_SOURCES})
################################################################################
# Doxygen
################################################################################
if(DOXYGEN_FOUND)
message(STATUS "Add Doxygen target")
set(DOXYGEN_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/docs/)
doxygen_add_docs(doc ${DOC_SOURCES} ${ENTRYPOINT_SOURCE} ${APP_SOURCES} ${APP_HEADER})
else()
message(STATUS "Do not add Doxygen target (Doxygen was not found)")
endif()
################################################################################
# Examples
################################################################################
if(BUILD_EXAMPLES)
message(STATUS "Build examples")
# prepare some variables so the examples can use them easily
set(EXAMPLE_APP_LIBRARIES ${APP_LIBRARIES})
set(EXAMPLE_APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS})
set(EXAMPLE_APP_OBJECTS ${APP_OBJECTS})
add_subdirectory(examples/)
else()
message(STATUS "Do not build examples")
endif()