forked from projectM-visualizer/projectm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
255 lines (218 loc) · 10 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
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
include(CMakeDependentOption)
include(CheckSymbolExists)
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)
option(ENABLE_DEBUG_POSTFIX "Add \"d\" (by default) after library names for debug builds." ON)
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.0.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")
# The actual (full) library version of projectM
set(PROJECTM_LIB_VERSION "${CMAKE_PROJECT_VERSION}")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_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.")
# Dummy file for merged static libs.
set(PROJECTM_DUMMY_SOURCE_FILE "${CMAKE_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)
else()
set(ENABLE_EMSCRIPTEN OFF CACHE BOOL "Build for web with emscripten. Requires emscripten toolset for building." FORCE)
endif()
# Feature options, including dependencies.
option(BUILD_TESTING "Build the libprojectM test suite" OFF)
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)
option(ENABLE_PLAYLIST "Enable building the playlist management library" ON)
cmake_dependent_option(ENABLE_SDL_UI "Build the SDL2-based developer test UI" OFF "NOT ENABLE_EMSCRIPTEN" OFF)
cmake_dependent_option(ENABLE_GLES "Enable OpenGL ES support" OFF "NOT ENABLE_EMSCRIPTEN" ON)
cmake_dependent_option(ENABLE_OPENMP "Enable OpenMP support if available" ON "NOT ENABLE_EMSCRIPTEN" OFF)
cmake_dependent_option(ENABLE_THREADING "Enable multithreading support." ON "NOT ENABLE_EMSCRIPTEN" OFF)
option(ENABLE_SYSTEM_GLM "Enable use of system-install GLM library" OFF)
# Experimental/unsupported features
cmake_dependent_option(ENABLE_LLVM "Enable experimental LLVM JIT support" OFF "NOT ENABLE_EMSCRIPTEN" OFF)
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)
else()
add_library(GLM::GLM INTERFACE IMPORTED)
set_target_properties(GLM::GLM PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/vendor"
)
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 MIN_WEBGL_VERSION=2"
"SHELL:-s MAX_WEBGL_VERSION=2"
"SHELL:-s ALLOW_MEMORY_GROWTH=1"
"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 ALLOW_MEMORY_GROWTH=1"
"SHELL:-s NO_DISABLE_EXCEPTION_CATCHING"
)
if(ENABLE_THREADING)
message(AUTHOR_WARNING "Threading on emscripten is deemed stable, but may have issues. Use with care.\n"
"See https://emscripten.org/docs/porting/pthreads.html for more information.")
add_compile_options(-pthread)
add_link_options(-pthread)
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)
if(NOT CMAKE_SYSTEM_NAME STREQUAL Linux)
message(FATAL_ERROR "OpenGL ES 3 support is currently only available for Linux platforms.")
endif()
# We use a local find script for OpenGL::GLES3 until the proposed changes are merged upstream.
list(APPEND CMAKE_MODULE_PATH "${CMAKE_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()
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()
if(ENABLE_OPENMP)
find_package(OpenMP)
if(NOT OpenMP_FOUND OR NOT OpenMP_CXX_FOUND)
set(ENABLE_OPENMP OFF)
endif()
endif()
if(ENABLE_THREADING)
find_package(Threads REQUIRED)
set(PROJECTM_USE_THREADS YES)
endif()
if(ENABLE_LLVM)
find_package(LLVM REQUIRED)
if(LLVM_VERSION VERSION_LESS 10.0)
message(FATAL_ERROR "LLVM JIT support requires at least version 10.0, but only ${LLVM_VERSION} was found.")
endif()
set(HAVE_LLVM TRUE)
else()
unset(HAVE_LLVM)
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()
include(features.cmake)
add_subdirectory(presets)
add_subdirectory(vendor)
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}")
message(STATUS " Threading: ${ENABLE_THREADING}")
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 " OpenMP: ${ENABLE_OPENMP}")
if(ENABLE_OPENMP)
message(STATUS " OpenMP version: ${OpenMP_CXX_VERSION}")
endif()
message(STATUS " Emscripten: ${ENABLE_EMSCRIPTEN}")
message(STATUS " LLVM JIT: ${ENABLE_LLVM}")
if(ENABLE_LLVM)
message(STATUS " LLVM version: ${LLVM_VERSION}")
endif()
message(STATUS " Use system GLM: ${ENABLE_SYSTEM_GLM}")
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 "")
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)