|
| 1 | +cmake_minimum_required(VERSION 3.14 FATAL_ERROR) |
| 2 | + |
| 3 | +if(CMAKE_VERSION VERSION_LESS 3.19 AND CMAKE_GENERATOR STREQUAL "Xcode") |
| 4 | + message(AUTHOR_WARNING "Using a CMake version before 3.19 with a recent Xcode SDK and the Xcode generator " |
| 5 | + "will likely result in CMake failing to find the AppleClang compiler. Either upgrade CMake to at least " |
| 6 | + "version 3.19 or use a different generator, e.g. \"Unix Makefiles\" or \"Ninja\".") |
| 7 | +endif() |
| 8 | + |
| 9 | +include(CMakeDependentOption) |
| 10 | +include(CheckSymbolExists) |
| 11 | + |
| 12 | +set(CMAKE_CXX_STANDARD 11) |
| 13 | +set(CMAKE_CXX_STANDARD_REQUIRED YES) |
| 14 | +set(CMAKE_POSITION_INDEPENDENT_CODE YES) |
| 15 | + |
| 16 | +set_property(GLOBAL PROPERTY USE_FOLDERS ON) |
| 17 | + |
| 18 | +option(ENABLE_DEBUG_POSTFIX "Add \"d\" after library names for debug builds" ON) |
| 19 | +if(ENABLE_DEBUG_POSTFIX) |
| 20 | + set(CMAKE_DEBUG_POSTFIX d) |
| 21 | +endif() |
| 22 | + |
| 23 | +# The API (SO) and detailed library versions for the shared library. |
| 24 | +set(PROJECTM_SO_VERSION "3") |
| 25 | +set(PROJECTM_LIB_VERSION "3.1.1") |
| 26 | + |
| 27 | +project(projectm |
| 28 | + LANGUAGES C CXX |
| 29 | + VERSION 3.1.13 |
| 30 | + ) |
| 31 | + |
| 32 | +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") |
| 33 | + |
| 34 | +set(PROJECTM_BIN_DIR "bin" CACHE STRING "Executable installation directory, relative to the install prefix.") |
| 35 | +set(PROJECTM_DATADIR_PATH "share/projectM" CACHE STRING "Default (absolute) path to the projectM data files (presets etc.)") |
| 36 | +set(PROJECTM_LIB_DIR "lib" CACHE STRING "Library installation directory, relative to the install prefix.") |
| 37 | +set(PROJECTM_INCLUDE_DIR "include" CACHE STRING "Header installation directory, relative to the install prefix.") |
| 38 | + |
| 39 | +# Feature options, including dependencies. |
| 40 | +option(ENABLE_PRESETS "Build and install bundled presets" ON) |
| 41 | +option(ENABLE_NATIVE_PRESETS "Build and install native libraries written in C/C++" OFF) |
| 42 | +option(ENABLE_TESTING "Build and install the projectM test suite" OFF) |
| 43 | +option(ENABLE_EMSCRIPTEN "Build for web with emscripten" OFF) |
| 44 | +cmake_dependent_option(ENABLE_SDL "Enable SDL2 support" ON "NOT ENABLE_EMSCRIPTEN;ENABLE_TESTING" ON) |
| 45 | +cmake_dependent_option(ENABLE_GLES "Enable OpenGL ES support" OFF "NOT ENABLE_EMSCRIPTEN" ON) |
| 46 | +cmake_dependent_option(ENABLE_THREADING "Enable multithreading support" ON "NOT ENABLE_EMSCRIPTEN;NOT CMAKE_SYSTEM_NAME STREQUAL Windows" OFF) |
| 47 | +cmake_dependent_option(ENABLE_PULSEAUDIO "Build Pulseaudio-based Qt UI" OFF "ENABLE_QT;NOT ENABLE_EMSCRIPTEN;CMAKE_SYSTEM_NAME STREQUAL Linux" OFF) |
| 48 | +cmake_dependent_option(ENABLE_JACK "Build JACK-based Qt and SDL UIs" OFF "ENABLE_QT;NOT ENABLE_EMSCRIPTEN;CMAKE_SYSTEM_NAME STREQUAL Linux" OFF) |
| 49 | +cmake_dependent_option(ENABLE_LLVM "Enable LLVM JIT support" OFF "NOT ENABLE_EMSCRIPTEN" OFF) |
| 50 | +cmake_dependent_option(ENABLE_LIBVISUAL "Build and install the projectM libvisual plug-in" OFF "NOT ENABLE_EMSCRIPTEN;CMAKE_SYSTEM_NAME STREQUAL Linux" OFF) |
| 51 | + |
| 52 | +find_package(GLM) |
| 53 | +if(NOT TARGET GLM::GLM) |
| 54 | + add_library(GLM::GLM INTERFACE IMPORTED) |
| 55 | + set_target_properties(GLM::GLM PROPERTIES |
| 56 | + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/vendor" |
| 57 | + ) |
| 58 | + |
| 59 | + message(STATUS "GLM library not found, using bundled version.") |
| 60 | + set(USE_SYSTEM_GLM OFF) |
| 61 | +else() |
| 62 | + set(USE_SYSTEM_GLM ON) |
| 63 | +endif() |
| 64 | + |
| 65 | +if(ENABLE_EMSCRIPTEN) |
| 66 | + message(STATUS "${CMAKE_C_COMPILER}") |
| 67 | + check_symbol_exists(__EMSCRIPTEN__ "" HAVE_EMSCRIPTEN) |
| 68 | + if(NOT HAVE_EMSCRIPTEN) |
| 69 | + message(FATAL_ERROR "You are not using an emscripten compiler.") |
| 70 | + endif() |
| 71 | +endif() |
| 72 | + |
| 73 | +if(ENABLE_SDL) |
| 74 | + find_package(SDL2 REQUIRED) |
| 75 | + |
| 76 | + # Temporary fix to deal with wrong include dir set by SDL2's CMake configuration. |
| 77 | + get_target_property(_SDL2_INCLUDE_DIR SDL2::SDL2 INTERFACE_INCLUDE_DIRECTORIES) |
| 78 | + if(_SDL2_INCLUDE_DIR MATCHES "(.+)/SDL2\$") |
| 79 | + message(STATUS "SDL2 include dir contains \"SDL2\" subdir (SDL bug #4004) - fixing to \"${CMAKE_MATCH_1}\".") |
| 80 | + set_target_properties(SDL2::SDL2 PROPERTIES |
| 81 | + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_MATCH_1}" |
| 82 | + ) |
| 83 | + endif() |
| 84 | + |
| 85 | + if(SDL2_VERSION VERSION_LESS "2.0.5") |
| 86 | + message(FATAL_ERROR "SDL2 libraries were found, but have version ${SDL2_VERSION}. At least version 2.0.5 is required.") |
| 87 | + endif() |
| 88 | +endif() |
| 89 | + |
| 90 | +if(ENABLE_GLES) |
| 91 | + find_package(GLES3 REQUIRED) |
| 92 | +else() |
| 93 | + find_package(OpenGL REQUIRED) |
| 94 | + set(PROJECTM_OPENGL_LIBRARIES OpenGL::GL) |
| 95 | + # GLX is required by SOIL2 on platforms with the X Window System (e.g. most Linux distributions) |
| 96 | + if(TARGET OpenGL::GLX) |
| 97 | + list(APPEND PROJECTM_OPENGL_LIBRARIES OpenGL::GLX) |
| 98 | + endif() |
| 99 | + if(CMAKE_SYSTEM_NAME STREQUAL "Windows") |
| 100 | + find_package(GLEW REQUIRED) |
| 101 | + list(APPEND PROJECTM_OPENGL_LIBRARIES GLEW::glew) |
| 102 | + endif() |
| 103 | +endif() |
| 104 | + |
| 105 | +if(ENABLE_THREADING) |
| 106 | + set(CMAKE_THREAD_PREFER_PTHREAD YES) |
| 107 | + find_package(Threads REQUIRED) |
| 108 | + if(NOT CMAKE_USE_PTHREADS_INIT) |
| 109 | + message(FATAL_ERROR "Threading support requested - pthread support is required, but not available.") |
| 110 | + endif() |
| 111 | + set(USE_THREADS YES) |
| 112 | +endif() |
| 113 | + |
| 114 | +if(ENABLE_LLVM) |
| 115 | + find_package(LLVM REQUIRED) |
| 116 | + set(HAVE_LLVM TRUE) |
| 117 | +else() |
| 118 | + unset(HAVE_LLVM) |
| 119 | +endif() |
| 120 | + |
| 121 | +if(ENABLE_PULSEAUDIO) |
| 122 | + find_package(Pulseaudio REQUIRED) |
| 123 | +endif() |
| 124 | + |
| 125 | +if(ENABLE_JACK) |
| 126 | + find_package(JACK REQUIRED) |
| 127 | +endif() |
| 128 | + |
| 129 | +if(ENABLE_PULSEAUDIO OR ENABLE_JACK) |
| 130 | + find_package(Qt5 REQUIRED COMPONENTS Gui OpenGL) |
| 131 | +endif() |
| 132 | + |
| 133 | +if(ENABLE_LIBVISUAL) |
| 134 | + find_package(libvisual REQUIRED) |
| 135 | + set(PROJECTM_LIBVISUAL_DIR "${LIBVISUAL_PLUGINSBASEDIR}/actor" CACHE STRING "Installation directory for the libvisual plug-in library.") |
| 136 | +endif() |
| 137 | + |
| 138 | +include(features.cmake) |
| 139 | + |
| 140 | +add_subdirectory(presets) |
| 141 | +add_subdirectory(src) |
| 142 | + |
| 143 | +message(STATUS "") |
| 144 | +message(STATUS "projectM v${PROJECT_VERSION}") |
| 145 | +message(STATUS " =====") |
| 146 | +message(STATUS "") |
| 147 | +message(STATUS " prefix: ${CMAKE_INSTALL_PREFIX}") |
| 148 | +message(STATUS " libdir: ${PROJECTM_LIB_DIR}") |
| 149 | +message(STATUS " includedir: ${PROJECTM_INCLUDE_DIR}") |
| 150 | +message(STATUS " bindir: ${PROJECTM_BIN_DIR}") |
| 151 | +message(STATUS " libvisual plugin dir: ${PROJECTM_LIBVISUAL_DIR}") |
| 152 | +message(STATUS "") |
| 153 | +message(STATUS " compiler: ${CMAKE_CXX_COMPILER}") |
| 154 | +message(STATUS " cflags: ${CMAKE_C_FLAGS}") |
| 155 | +message(STATUS " cxxflags: ${CMAKE_CXX_FLAGS}") |
| 156 | +message(STATUS " ldflags: ${CMAKE_SHARED_LINKER_FLAGS}") |
| 157 | +message(STATUS "") |
| 158 | +message(STATUS " DATADIR_PATH: ${PROJECTM_DATADIR_PATH}") |
| 159 | +message(STATUS " - - -") |
| 160 | +message(STATUS "") |
| 161 | +message(STATUS " Applications:") |
| 162 | +message(STATUS " =====") |
| 163 | +message(STATUS "") |
| 164 | +message(STATUS " libprojectM: ON") |
| 165 | +message(STATUS " Presets: ${ENABLE_PRESETS}") |
| 166 | +message(STATUS " Native presets: ${ENABLE_NATIVE_PRESETS}") |
| 167 | +message(STATUS " Tests: ${ENABLE_TESTING}") |
| 168 | +message(STATUS " Threading: ${ENABLE_THREADING}") |
| 169 | +message(STATUS " SDL2: ${ENABLE_SDL}") |
| 170 | +if(ENABLE_SDL) |
| 171 | + message(STATUS " SDL2 version: ${SDL2_VERSION}") |
| 172 | +endif() |
| 173 | +message(STATUS " Pulseaudio UI: ${ENABLE_PULSEAUDIO}") |
| 174 | +if(ENABLE_PULSEAUDIO) |
| 175 | + message(STATUS " Pulseaudio version: ${PULSEAUDIO_VERSION}") |
| 176 | +endif() |
| 177 | +message(STATUS " JACK UI: ${ENABLE_JACK}") |
| 178 | +if(ENABLE_JACK) |
| 179 | + message(STATUS " JACK version: ${JACK_VERSION}") |
| 180 | +endif() |
| 181 | +if(ENABLE_PULSEAUDIO OR ENABLE_JACK) |
| 182 | + message(STATUS " Qt version: ${Qt5_VERSION}") |
| 183 | +endif() |
| 184 | +message(STATUS " OpenGLES: ${ENABLE_GLES}") |
| 185 | +message(STATUS " Emscripten: ${ENABLE_EMSCRIPTEN}") |
| 186 | +message(STATUS " LLVM JIT: ${ENABLE_LLVM}") |
| 187 | +if(ENABLE_LLVM) |
| 188 | + message(STATUS " LLVM version: ${LLVM_VERSION}") |
| 189 | +endif() |
| 190 | +message(STATUS " libvisual plug-in: ${ENABLE_LIBVISUAL}") |
| 191 | +message(STATUS " Use system GLM: ${USE_SYSTEM_GLM}") |
| 192 | + |
| 193 | +message(AUTHOR_WARNING |
| 194 | + "The CMake build scripts for projectM are still in active development.\n" |
| 195 | + "This means that build parameters, exported target names and other things can change " |
| 196 | + "at any time until the new build system is officially documented and announced to be " |
| 197 | + "fully supported.\n" |
| 198 | + "DO NOT base any production work on it yet!\n" |
| 199 | + ) |
0 commit comments