-
-
Notifications
You must be signed in to change notification settings - Fork 375
/
CMakeLists.txt
300 lines (255 loc) · 11.8 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
cmake_minimum_required(VERSION 3.21 FATAL_ERROR)
include(CMakeDependentOption)
include(CheckSymbolExists)
# Save the current source/binary dirs if we're in a subdirectory of a larger CMake project.
set(PROJECTM_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
set(PROJECTM_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}")
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_POSITION_INDEPENDENT_CODE YES)
# Don't export any symbols except those explicitly exported.
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# General build options
option(ENABLE_SYSTEM_GLM "Enable use of system-install GLM library" OFF)
option(ENABLE_SYSTEM_PROJECTM_EVAL "Enable use of a system-installed/external projectM-eval library" ON)
option(ENABLE_DEBUG_POSTFIX "Add \"d\" (by default) after library names for debug builds." ON)
option(ENABLE_PLAYLIST "Enable building the playlist management library" ON)
option(ENABLE_BOOST_FILESYSTEM "Force the use of boost::filesystem, even if the compiler supports C++17." OFF)
option(ENABLE_SDL_UI "Build the SDL2-based developer test UI. Ignored when building with Emscripten or for Android." OFF)
option(BUILD_TESTING "Build the libprojectM test suite" OFF)
option(BUILD_DOCS "Build documentation" OFF)
# Enable vcpkg manifest features according to the build options set
if(ENABLE_SYSTEM_GLM)
list(APPEND VCPKG_MANIFEST_FEATURES external-glm)
endif()
if(ENABLE_SYSTEM_PROJECTM_EVAL)
list(APPEND VCPKG_MANIFEST_FEATURES external-evallib)
endif()
if(ENABLE_BOOST_FILESYSTEM)
list(APPEND VCPKG_MANIFEST_FEATURES boost-filesystem)
endif()
if(ENABLE_SDL_UI)
list(APPEND VCPKG_MANIFEST_FEATURES gui)
endif()
if(BUILD_TESTING)
list(APPEND VCPKG_MANIFEST_FEATURES test)
endif()
if(ENABLE_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Output file debug postfix. Default is \"d\".")
endif()
project(libprojectM
LANGUAGES C CXX
VERSION 4.1.0
)
# The API (SO) version for the shared library. Should be incremented whenever the binary interface changes
# in a non-backwards-compatible way, e.g. changing parameters or return values of existing functions or removing
# functions. Adding new function should be okay if documented.
set(PROJECTM_SO_VERSION "4")
# Base filename of all installed libraries. Also used as package name in pkgconfig.
set(PROJECTM_LIBRARY_BASE_OUTPUT_NAME "projectM-${PROJECT_VERSION_MAJOR}")
# The actual (full) library version of projectM
set(PROJECTM_LIB_VERSION "${CMAKE_PROJECT_VERSION}")
list(APPEND CMAKE_MODULE_PATH "${PROJECTM_SOURCE_DIR}/cmake")
include(VCSVersion)
include(GNUInstallDirs)
set(PROJECTM_BIN_DIR "${CMAKE_INSTALL_BINDIR}" CACHE STRING "Executable installation directory, relative to the install prefix.")
set(PROJECTM_LIB_DIR "${CMAKE_INSTALL_LIBDIR}" CACHE STRING "Library installation directory, relative to the install prefix.")
set(PROJECTM_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}" CACHE STRING "Header installation directory, relative to the install prefix.")
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
set(PROJECTM_RUNTIME_DIR "${PROJECTM_BIN_DIR}")
else()
set(PROJECTM_RUNTIME_DIR "${PROJECTM_LIB_DIR}")
endif()
# Dummy file for merged static libs.
set(PROJECTM_DUMMY_SOURCE_FILE "${PROJECTM_BINARY_DIR}/dummy.cpp")
file(TOUCH "${PROJECTM_DUMMY_SOURCE_FILE}")
if(CMAKE_SYSTEM_NAME STREQUAL Emscripten)
set(ENABLE_EMSCRIPTEN ON CACHE BOOL "Build for web with emscripten. Will also build the SDL2-based entrypoint." FORCE)
option(USE_PTHREADS "Enable multithreading support" OFF)
else()
set(ENABLE_EMSCRIPTEN OFF CACHE BOOL "Build for web with emscripten. Requires emscripten toolset for building." FORCE)
endif()
# Compiler-/system-dependent options, including dependencies.
cmake_dependent_option(BUILD_SHARED_LIBS "Build and install libprojectM as a shared libraries. If OFF, builds as static libraries." ON "NOT ENABLE_EMSCRIPTEN" OFF)
cmake_dependent_option(ENABLE_GLES "Enable OpenGL ES support" OFF "NOT ENABLE_EMSCRIPTEN AND NOT CMAKE_SYSTEM_NAME STREQUAL Android" ON)
cmake_dependent_option(ENABLE_INSTALL "Enable installing projectM libraries and headers." OFF "NOT PROJECT_IS_TOP_LEVEL" ON)
# Experimental/unsupported features
option(ENABLE_CXX_INTERFACE "Enable exporting C++ symbols for ProjectM and PCM classes, not only the C API. Warning: This is not very portable." OFF)
if(ENABLE_SYSTEM_GLM)
find_package(GLM REQUIRED)
endif()
if(ENABLE_SYSTEM_PROJECTM_EVAL)
find_package(projectM-Eval)
endif()
if(NOT BUILD_SHARED_LIBS AND CMAKE_SYSTEM_NAME STREQUAL "Windows")
# Add "lib" in front of static library files to allow installing both shared and static libs in the same dir.
set(CMAKE_STATIC_LIBRARY_PREFIX lib)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
# Silence OpenGL API deprecation warnings on macOS.
add_compile_definitions(GL_SILENCE_DEPRECATION)
endif()
if(ENABLE_EMSCRIPTEN)
message(STATUS "${CMAKE_C_COMPILER} on ${CMAKE_SYSTEM_NAME}")
check_symbol_exists(__EMSCRIPTEN__ "" HAVE_EMSCRIPTEN)
if(NOT HAVE_EMSCRIPTEN)
message(FATAL_ERROR "You are not using an emscripten compiler.")
endif()
# emscripten uses different options to compile and link libraries, so we can't use find_package().
# Instead, specifying the required options directly to emcc is the way to go.
# Note: The "SHELL:" syntax is required to pass each argument as-is, but without quotes and CMake's de-duplication.
add_compile_options(
"SHELL:-s USE_SDL=2"
"SHELL:-s NO_DISABLE_EXCEPTION_CATCHING"
)
add_link_options(
"SHELL:-s USE_SDL=2"
"SHELL:-s MIN_WEBGL_VERSION=2"
"SHELL:-s MAX_WEBGL_VERSION=2"
"SHELL:-s FULL_ES2=1"
"SHELL:-s FULL_ES3=1"
"SHELL:-s ALLOW_MEMORY_GROWTH=1"
"SHELL:-s NO_DISABLE_EXCEPTION_CATCHING"
)
if(USE_PTHREADS)
add_compile_options("SHELL:-s USE_PTHREADS=1")
add_link_options("SHELL:-s USE_PTHREADS=1")
endif()
set(USE_GLES ON)
else()
if(ENABLE_SDL_UI)
find_package(SDL2 REQUIRED)
# Apply some fixes, as SDL2's CMake support is new and still a WiP.
include(SDL2Target)
endif()
if(ENABLE_GLES)
message(STATUS "Building for OpenGL Embedded Profile")
if(NOT CMAKE_SYSTEM_NAME STREQUAL Linux
AND NOT CMAKE_SYSTEM_NAME STREQUAL Android)
message(FATAL_ERROR "OpenGL ES 3 support is currently only available for Linux platforms. You're building for ${CMAKE_SYSTEM_NAME}.")
endif()
# We use a local find script for OpenGL::GLES3 until the proposed changes are merged upstream.
list(APPEND CMAKE_MODULE_PATH "${PROJECTM_SOURCE_DIR}/cmake/gles")
find_package(OpenGL REQUIRED COMPONENTS GLES3)
if(NOT TARGET OpenGL::GLES3)
message(FATAL_ERROR "No suitable GLES3 library was found.")
endif()
set(PROJECTM_OPENGL_LIBRARIES OpenGL::GLES3)
set(USE_GLES ON)
else()
message(STATUS "Building for OpenGL Core Profile")
find_package(OpenGL REQUIRED)
set(PROJECTM_OPENGL_LIBRARIES OpenGL::GL)
# GLX is required by SOIL2 on platforms with the X Window System (e.g. most Linux distributions)
if(TARGET OpenGL::GLX)
list(APPEND PROJECTM_OPENGL_LIBRARIES OpenGL::GLX)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
find_package(GLEW REQUIRED)
# Prefer shared, but check for static lib if shared is not available.
if(TARGET GLEW::glew)
list(APPEND PROJECTM_OPENGL_LIBRARIES GLEW::glew)
elseif(TARGET GLEW::glew_s)
list(APPEND PROJECTM_OPENGL_LIBRARIES GLEW::glew_s)
endif()
endif()
endif()
endif()
if(ENABLE_CXX_INTERFACE)
set(CMAKE_C_VISIBILITY_PRESET default)
set(CMAKE_CXX_VISIBILITY_PRESET default)
set(CMAKE_VISIBILITY_INLINES_HIDDEN OFF)
else()
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
endif()
if(BUILD_DOCS)
find_package(Doxygen REQUIRED)
find_package(Sphinx REQUIRED breathe exhale)
set(DOXYGEN_GENERATE_HTML NO)
set(DOXYGEN_GENERATE_XML YES)
# All doxygen comments are in header files. Processing cpp files
# produces duplicate C++ function definitions in doxygen, resulting
# in various problems.
# See https://github.com/breathe-doc/breathe/issues/772
set(DOXYGEN_EXCLUDE_PATTERNS "*.cpp")
doxygen_add_docs(
projectm_doxygen
src
COMMENT "Generate HTML documentation")
sphinx_add_docs(
projectm_sphinx
BREATHE_PROJECTS projectm_doxygen
BUILDER html
SOURCE_DIRECTORY docs)
endif()
add_subdirectory(vendor)
include(features.cmake)
add_subdirectory(presets)
add_subdirectory(src)
if(BUILD_TESTING)
enable_testing()
add_subdirectory(tests)
endif()
message(STATUS "")
message(STATUS "libprojectM v${PROJECT_VERSION}")
message(STATUS "==============================================")
message(STATUS "")
message(STATUS " prefix: ${CMAKE_INSTALL_PREFIX}")
message(STATUS " libdir: ${PROJECTM_LIB_DIR}")
message(STATUS " includedir: ${PROJECTM_INCLUDE_DIR}")
message(STATUS " bindir: ${PROJECTM_BIN_DIR}")
message(STATUS "")
message(STATUS " compiler: ${CMAKE_CXX_COMPILER}")
message(STATUS " cflags: ${CMAKE_C_FLAGS}")
message(STATUS " cxxflags: ${CMAKE_CXX_FLAGS}")
message(STATUS " ldflags: ${CMAKE_SHARED_LINKER_FLAGS}")
message(STATUS "")
message(STATUS "Features:")
message(STATUS "==============================================")
message(STATUS "")
message(STATUS " Build shared libraries: ${BUILD_SHARED_LIBS}")
if(ENABLE_BOOST_FILESYSTEM)
message(STATUS " Filesystem support: Boost")
message(STATUS " Boost version: ${Boost_VERSION}")
else()
message(STATUS " Filesystem support: C++17 STL")
endif()
message(STATUS " SDL2: ${ENABLE_SDL_UI}")
if(ENABLE_SDL_UI)
message(STATUS " SDL2 version: ${SDL2_VERSION}")
endif()
message(STATUS " OpenGL ES: ${ENABLE_GLES}")
message(STATUS " Emscripten: ${ENABLE_EMSCRIPTEN}")
if(CMAKE_SYSTEM_NAME STREQUAL Emscripten)
message(STATUS " - PThreads: ${USE_PTHREADS}")
endif()
message(STATUS " Use system GLM: ${ENABLE_SYSTEM_GLM}")
message(STATUS " Use system projectM-eval: ${ENABLE_SYSTEM_PROJECTM_EVAL}")
message(STATUS " Link UI with shared lib: ${ENABLE_SHARED_LINKING}")
message(STATUS "")
message(STATUS "Targets and applications:")
message(STATUS "==============================================")
message(STATUS "")
message(STATUS " libprojectM: (always built)")
message(STATUS " Playlist library: ${ENABLE_PLAYLIST}")
message(STATUS " SDL2 Test UI: ${ENABLE_SDL_UI}")
message(STATUS " Tests: ${BUILD_TESTING}")
message(STATUS " Documentation: ${BUILD_DOCS}")
message(STATUS "")
if(ENABLE_CXX_INTERFACE)
message(AUTHOR_WARNING
"This build is configured to export C++ symbols for ProjectM and PCM classes in the shared library.\n"
"Using C++ STL types across library borders only works if all components were built "
"with the exact same toolchain and C++ language level, otherwise it will cause crashes.\n"
"Only use this if you know what you're doing. You have been warned!"
)
endif()
# Create CPack configuration
set(CPACK_PACKAGE_NAME "projectM")
set(CPACK_VERBATIM_VARIABLES YES)
include(CPack)