Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

272 lines
12KB

  1. cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
  2. if(CMAKE_VERSION VERSION_LESS 3.19 AND CMAKE_GENERATOR STREQUAL "Xcode")
  3. message(AUTHOR_WARNING "Using a CMake version before 3.19 with a recent Xcode SDK and the Xcode generator "
  4. "will likely result in CMake failing to find the AppleClang compiler. Either upgrade CMake to at least "
  5. "version 3.19 or use a different generator, e.g. \"Unix Makefiles\" or \"Ninja\".")
  6. endif()
  7. include(CMakeDependentOption)
  8. include(CheckSymbolExists)
  9. set(CMAKE_CXX_STANDARD 14)
  10. set(CMAKE_CXX_STANDARD_REQUIRED YES)
  11. set(CMAKE_POSITION_INDEPENDENT_CODE YES)
  12. set_property(GLOBAL PROPERTY USE_FOLDERS ON)
  13. option(ENABLE_DEBUG_POSTFIX "Add \"d\" after library names for debug builds" ON)
  14. if(ENABLE_DEBUG_POSTFIX)
  15. set(CMAKE_DEBUG_POSTFIX d)
  16. endif()
  17. # The API (SO) and detailed library versions for the shared library.
  18. set(PROJECTM_SO_VERSION "3")
  19. set(PROJECTM_LIB_VERSION "3.1.1")
  20. project(projectm
  21. LANGUAGES C CXX
  22. VERSION 3.1.13
  23. )
  24. list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
  25. set(PROJECTM_BIN_DIR "bin" CACHE STRING "Executable installation directory, relative to the install prefix.")
  26. set(PROJECTM_DATADIR_PATH "share/projectM" CACHE STRING "Default (absolute) path to the projectM data files (presets etc.)")
  27. set(PROJECTM_LIB_DIR "lib" CACHE STRING "Library installation directory, relative to the install prefix.")
  28. set(PROJECTM_INCLUDE_DIR "include" CACHE STRING "Header installation directory, relative to the install prefix.")
  29. # Feature options, including dependencies.
  30. option(ENABLE_STATIC_LIB "Build and install libprojectM as a static library" ON)
  31. cmake_dependent_option(ENABLE_SHARED_LIB "Build and install libprojectM as a shared library" ON "NOT CMAKE_SYSTEM_NAME STREQUAL Windows" OFF)
  32. cmake_dependent_option(ENABLE_SHARED_LINKING "Link all built UI applications against the shared library." OFF "ENABLE_SHARED_LIB" OFF)
  33. option(ENABLE_DOXYGEN "Build and install Doxygen source code documentation in PROJECTM_DATADIR_PATH/docs." OFF)
  34. option(ENABLE_CXX_INTERFACE "Enable exporting all C++ symbols, not only the C API, in the shared library. Warning: This is not very portable." OFF)
  35. option(ENABLE_PRESETS "Build and install bundled presets" ON)
  36. option(ENABLE_NATIVE_PRESETS "Build and install native libraries written in C/C++" OFF)
  37. option(ENABLE_TESTING "Build and install the projectM test suite" OFF)
  38. option(ENABLE_EMSCRIPTEN "Build for web with emscripten" OFF)
  39. cmake_dependent_option(ENABLE_SDL "Enable SDL2 support" ON "NOT ENABLE_EMSCRIPTEN;NOT ENABLE_TESTING" ON)
  40. cmake_dependent_option(ENABLE_SDL_UI "Build the SDL2-based reference UI" ON "NOT ENABLE_EMSCRIPTEN" OFF)
  41. cmake_dependent_option(ENABLE_GLES "Enable OpenGL ES support" OFF "NOT ENABLE_EMSCRIPTEN" ON)
  42. cmake_dependent_option(ENABLE_THREADING "Enable multithreading support" ON "NOT ENABLE_EMSCRIPTEN;NOT CMAKE_SYSTEM_NAME STREQUAL Windows" OFF)
  43. cmake_dependent_option(ENABLE_PULSEAUDIO "Build PulseAudio-based Qt UI" OFF "NOT ENABLE_EMSCRIPTEN;CMAKE_SYSTEM_NAME STREQUAL Linux" OFF)
  44. cmake_dependent_option(ENABLE_JACK "Build JACK-based Qt and SDL UIs" OFF "NOT ENABLE_EMSCRIPTEN;CMAKE_SYSTEM_NAME STREQUAL Linux" OFF)
  45. cmake_dependent_option(ENABLE_QT "Build Qt UI library" OFF "NOT ENABLE_PULSEAUDIO;NOT ENABLE_JACK" ON)
  46. cmake_dependent_option(ENABLE_LLVM "Enable LLVM JIT support" OFF "NOT ENABLE_EMSCRIPTEN" OFF)
  47. cmake_dependent_option(ENABLE_LIBVISUAL "Build and install the projectM libvisual plug-in" OFF "NOT ENABLE_EMSCRIPTEN;CMAKE_SYSTEM_NAME STREQUAL Linux" OFF)
  48. if(NOT ENABLE_STATIC_LIB AND NOT ENABLE_SHARED_LIB)
  49. message(FATAL_ERROR "At least one of either ENABLE_STATIC_LIB or ENABLE_SHARED_LIB options must be set to ON.")
  50. endif()
  51. if(ENABLE_DOXYGEN)
  52. find_package(Doxygen REQUIRED)
  53. endif()
  54. find_package(GLM)
  55. if(NOT TARGET GLM::GLM)
  56. add_library(GLM::GLM INTERFACE IMPORTED)
  57. set_target_properties(GLM::GLM PROPERTIES
  58. INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/vendor"
  59. )
  60. message(STATUS "GLM library not found, using bundled version.")
  61. set(USE_SYSTEM_GLM OFF)
  62. else()
  63. set(USE_SYSTEM_GLM ON)
  64. endif()
  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. if(ENABLE_SDL)
  73. find_package(SDL2 REQUIRED)
  74. # Apply some fixes, as SDL2's CMake support is new and still a WiP.
  75. include(SDL2Target)
  76. endif()
  77. if(ENABLE_GLES)
  78. # Might be implemented in the CMake OpenGL module.
  79. # We may provide a find module in the future, and add support for CMake's own module later:
  80. # https://gitlab.kitware.com/cmake/cmake/-/blob/3fc3b43933d0b486aa4eb5d63fc257475feff348/Modules/FindOpenGL.cmake#L520
  81. message(FATAL_ERROR "GLES support is currently not implemented for CMake builds.")
  82. find_package(GLES3 REQUIRED)
  83. else()
  84. find_package(OpenGL REQUIRED)
  85. set(PROJECTM_OPENGL_LIBRARIES OpenGL::GL)
  86. # GLX is required by SOIL2 on platforms with the X Window System (e.g. most Linux distributions)
  87. if(TARGET OpenGL::GLX)
  88. list(APPEND PROJECTM_OPENGL_LIBRARIES OpenGL::GLX)
  89. endif()
  90. if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
  91. find_package(GLEW REQUIRED)
  92. list(APPEND PROJECTM_OPENGL_LIBRARIES GLEW::glew)
  93. endif()
  94. endif()
  95. if(ENABLE_THREADING)
  96. set(CMAKE_THREAD_PREFER_PTHREAD YES)
  97. find_package(Threads REQUIRED)
  98. if(NOT CMAKE_USE_PTHREADS_INIT)
  99. message(FATAL_ERROR "Threading support requested - pthread support is required, but not available.")
  100. endif()
  101. set(USE_THREADS YES)
  102. endif()
  103. if(ENABLE_LLVM)
  104. find_package(LLVM REQUIRED)
  105. if(LLVM_VERSION VERSION_LESS 10.0)
  106. message(FATAL_ERROR "LLVM JIT support requires at least version 10.0, but only ${LLVM_VERSION} was found.")
  107. endif()
  108. set(HAVE_LLVM TRUE)
  109. else()
  110. unset(HAVE_LLVM)
  111. endif()
  112. if(ENABLE_PULSEAUDIO)
  113. find_package(Pulseaudio REQUIRED)
  114. endif()
  115. if(ENABLE_JACK)
  116. find_package(JACK REQUIRED)
  117. endif()
  118. if(ENABLE_PULSEAUDIO OR ENABLE_JACK)
  119. set(QT_REQUIRED_COMPONENTS Gui Widgets OpenGL Xml)
  120. if(DEFINED QT_VERSION)
  121. find_package(Qt${QT_VERSION} REQUIRED COMPONENTS ${QT_REQUIRED_COMPONENTS})
  122. else()
  123. # Try to determine the Qt version available, starting with Qt6
  124. message(STATUS "Determining Qt version. To use a specific version, set QT_VERSION to either 5 or 6.")
  125. find_package(Qt6 QUIET COMPONENTS ${QT_REQUIRED_COMPONENTS})
  126. if(TARGET Qt6::Core)
  127. set(QT_VERSION 6)
  128. else()
  129. find_package(Qt5 QUIET COMPONENTS ${QT_REQUIRED_COMPONENTS})
  130. if(TARGET Qt5::Core)
  131. set(QT_VERSION 5)
  132. else()
  133. message(FATAL_ERROR "Could not find either Qt 5 or 6, one is required to build the PulseAudio or JACK UIs.")
  134. endif()
  135. endif()
  136. endif()
  137. # OpenGLWidgets were put into their own component since Qt 6.
  138. if(QT_VERSION EQUAL 6)
  139. list(APPEND QT_REQUIRED_COMPONENTS OpenGLWidgets)
  140. find_package(Qt6 REQUIRED COMPONENTS OpenGLWidgets)
  141. endif()
  142. set(QT_LINK_TARGETS "")
  143. foreach(component ${QT_REQUIRED_COMPONENTS})
  144. list(APPEND QT_LINK_TARGETS Qt${QT_VERSION}::${component})
  145. endforeach()
  146. endif()
  147. if(ENABLE_LIBVISUAL)
  148. find_package(libvisual REQUIRED)
  149. set(PROJECTM_LIBVISUAL_DIR "${LIBVISUAL_PLUGINSBASEDIR}/actor" CACHE STRING "Installation directory for the libvisual plug-in library.")
  150. endif()
  151. if(ENABLE_CXX_INTERFACE)
  152. set(CMAKE_C_VISIBILITY_PRESET default)
  153. set(CMAKE_CXX_VISIBILITY_PRESET default)
  154. set(CMAKE_VISIBILITY_INLINES_HIDDEN OFF)
  155. else()
  156. set(CMAKE_C_VISIBILITY_PRESET hidden)
  157. set(CMAKE_CXX_VISIBILITY_PRESET hidden)
  158. set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
  159. endif()
  160. include(features.cmake)
  161. add_subdirectory(presets)
  162. add_subdirectory(src)
  163. message(STATUS "")
  164. message(STATUS "projectM v${PROJECT_VERSION}")
  165. message(STATUS "==============================================")
  166. message(STATUS "")
  167. message(STATUS " prefix: ${CMAKE_INSTALL_PREFIX}")
  168. message(STATUS " libdir: ${PROJECTM_LIB_DIR}")
  169. message(STATUS " includedir: ${PROJECTM_INCLUDE_DIR}")
  170. message(STATUS " bindir: ${PROJECTM_BIN_DIR}")
  171. message(STATUS " libvisual plugin dir: ${PROJECTM_LIBVISUAL_DIR}")
  172. message(STATUS "")
  173. message(STATUS " compiler: ${CMAKE_CXX_COMPILER}")
  174. message(STATUS " cflags: ${CMAKE_C_FLAGS}")
  175. message(STATUS " cxxflags: ${CMAKE_CXX_FLAGS}")
  176. message(STATUS " ldflags: ${CMAKE_SHARED_LINKER_FLAGS}")
  177. message(STATUS "")
  178. message(STATUS " DATADIR_PATH: ${PROJECTM_DATADIR_PATH}")
  179. message(STATUS "")
  180. message(STATUS "Features:")
  181. message(STATUS "==============================================")
  182. message(STATUS "")
  183. message(STATUS " Presets: ${ENABLE_PRESETS}")
  184. message(STATUS " Native presets: ${ENABLE_NATIVE_PRESETS}")
  185. message(STATUS " Threading: ${ENABLE_THREADING}")
  186. message(STATUS " SDL2: ${ENABLE_SDL}")
  187. if(ENABLE_SDL)
  188. message(STATUS " SDL2 version: ${SDL2_VERSION}")
  189. endif()
  190. message(STATUS " OpenGLES: ${ENABLE_GLES}")
  191. message(STATUS " Emscripten: ${ENABLE_EMSCRIPTEN}")
  192. message(STATUS " LLVM JIT: ${ENABLE_LLVM}")
  193. if(ENABLE_LLVM)
  194. message(STATUS " LLVM version: ${LLVM_VERSION}")
  195. endif()
  196. message(STATUS " Use system GLM: ${USE_SYSTEM_GLM}")
  197. message(STATUS " Link UI with shared lib: ${ENABLE_SHARED_LINKING}")
  198. message(STATUS "")
  199. message(STATUS "Targets and applications:")
  200. message(STATUS "==============================================")
  201. message(STATUS "")
  202. message(STATUS " libprojectM static: ${ENABLE_STATIC_LIB}")
  203. message(STATUS " libprojectM shared: ${ENABLE_SHARED_LIB}")
  204. message(STATUS " SDL2 UI: ${ENABLE_SDL_UI}")
  205. message(STATUS " Doxygen API docs: ${ENABLE_DOXYGEN}")
  206. message(STATUS " Tests: ${ENABLE_TESTING}")
  207. message(STATUS " PulseAudio UI: ${ENABLE_PULSEAUDIO}")
  208. if(ENABLE_PULSEAUDIO)
  209. message(STATUS " PulseAudio version: ${PULSEAUDIO_VERSION}")
  210. endif()
  211. message(STATUS " JACK UI: ${ENABLE_JACK}")
  212. if(ENABLE_JACK)
  213. message(STATUS " JACK version: ${JACK_VERSION}")
  214. endif()
  215. if(ENABLE_PULSEAUDIO OR ENABLE_JACK)
  216. message(STATUS " Qt version: ${Qt${QT_VERSION}_VERSION}")
  217. endif()
  218. message(STATUS " libvisual plug-in: ${ENABLE_LIBVISUAL}")
  219. message(STATUS "")
  220. message(AUTHOR_WARNING
  221. "The CMake build scripts for projectM are still in active development.\n"
  222. "This means that build parameters, exported target names and other things can change "
  223. "at any time until the new build system is officially documented and announced to be "
  224. "fully supported.\n"
  225. "DO NOT base any production work on it yet!\n"
  226. )
  227. if(ENABLE_CXX_INTERFACE)
  228. message(AUTHOR_WARNING "This build is configured to export all C++ symbols in the shared library.\n"
  229. "Using C++ STL types across library borders only works if all components were built "
  230. "with the exact same toolchain and C++ language level, otherwise it will cause crashes.\n"
  231. "Enabling this option will not export additional symbols in Windows DLL builds.\n"
  232. "Only use this if you know what you're doing. You have been warned!"
  233. )
  234. endif()
  235. # Create CPack configuration
  236. set(CPACK_PACKAGE_NAME "projectM")
  237. set(CPACK_VERBATIM_VARIABLES YES)
  238. include(CPack)