Skip to content

Commit

Permalink
Add CMake build system files (only as "autotools" replacement for now) (
Browse files Browse the repository at this point in the history
#487)

* Initial set of CMake files with options and some targets.

* Added all targets to build libprojectM shared/static libraries.

* Updated currently unused (and seemingly unfinished) SDL-based JACK visualizer to use SDL2.

* Converted more targets to CMake and added install directives.

New targets:
- Presets
- Test application
- Pulseaudio/Qt visualizer
- JACK/Qt visualizer
- JACK/SDL2 visualizer

* Added libvisual plug-in target. Changed default install paths to relative.

* Use debug suffix for libraries by default, but make it configurable.

* Added target for projectMSDL application.

* Added CMake code for the ENABLE_THREADING switch, install desktop, icon, manpage and pkgconfig files.

Also added some dependency version output to the post-configuration summary and made Qt switch implicit based on Pulsaudio/JACK UI selection.

* Added CMake package config files and exported targets. Some restructuring of libprojectM targets.

Kept pkgconfig module name for CMake.

* Add -name parameter to RCC command in existing autotools Makefile.

Fixes symbol name mismatch with CMake auto-generated resources which always add the QRC file basename as resource name.

* Display an author warning that CMake files aren't production ready yet.

* Prefer system GLM library, with fallback to bundled version if not available.

Removed the option to use the system library in favor of automated detection.

* Link correct OpenGL libraries, the previous ones were Linux-specific, with GLVND not being required.

* Recreate config.h as generated by autoheader, even if most defines weren't used.

Will also force-include the file on all platforms.

* Add option to build native preset libraries, disabled by default.

* Only install "tests" presets if building the test suite.

* Fix linking LLVM libraries to libprojectM.

Wasn't inherited anymore due to changing MilkdropPresetFactory library type to OBJECT.

* Use INTERFACE IMPORTED libraries in find scripts, set minimum CMake version to 3.19.

* Added missing config.h template and renamed to config.h.cmake.in, was in the .gitignore list.

* Added Windows-specific CMake configuration and some related code changes.

These changes enable building for Windows with both Visual Studio and Ninja project generators. Installation and packaging for Windows is not yet supported. Source groups, filters and support for embedded debug symbols will be added later.

* Link required CoreFoundation framework on MacOS.

* Work around SDL2 include dir issue (upstream SDL bug #4004) by removing "/SDL2" from the path.

* Fix existing Windows build by moving bundled GLEW files into "GL" subdir.

* Place libprojectM-related targets in a "libprojectM" folder in IDEs supporting it, e.g. Visual Studio.

* Fix displaying whether system GLM is used or not in config summary.

* Disable threading support on Windows unless we don't rely solely on pthreads anymore.

* Add version check for SDL2 (>=2.0.5).

* Complete overhaul of build instructions, adding CMake build and use instructions.

* Added check for OpenMP support and fixed a compiler error in OMPTL.

Also moved compiler warning checks to features.cmake and added the DEBUG define for debug builds.

* Added a quick start guide for building on Debian and Ubuntu.

* Lower minimum required CMake version to 3.14.

Co-authored-by: Kai Blaschke <[email protected]>
  • Loading branch information
kblaschke and kblaschke authored Jun 4, 2021
1 parent fbb682a commit 83a08f3
Show file tree
Hide file tree
Showing 60 changed files with 5,179 additions and 1,176 deletions.
13 changes: 11 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ Makefile.in
/aclocal.m4
/autom4te.cache
/build-aux
/config.*
/config.h
/config.h.in
/configure
/libtool
/stamp-h1
Expand All @@ -41,11 +42,19 @@ m4/lt~obsolete.m4
/build
/dist

# Visual Studio w/CMake
/out
/.vs
/CMakeSettings.json

_sync.bat
_sync.sh
to_sync/
.DS_Store
src/projectM-sdl/build/
src/libprojectM/build/
*.pkg
*.pkg

# CLion
cmake-build-*
.idea
279 changes: 279 additions & 0 deletions BUILDING-cmake.md

Large diffs are not rendered by default.

398 changes: 361 additions & 37 deletions BUILDING.md

Large diffs are not rendered by default.

199 changes: 199 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

if(CMAKE_VERSION VERSION_LESS 3.19 AND CMAKE_GENERATOR STREQUAL "Xcode")
message(AUTHOR_WARNING "Using a CMake version before 3.19 with a recent Xcode SDK and the Xcode generator "
"will likely result in CMake failing to find the AppleClang compiler. Either upgrade CMake to at least "
"version 3.19 or use a different generator, e.g. \"Unix Makefiles\" or \"Ninja\".")
endif()

include(CMakeDependentOption)
include(CheckSymbolExists)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED YES)
set(CMAKE_POSITION_INDEPENDENT_CODE YES)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

option(ENABLE_DEBUG_POSTFIX "Add \"d\" after library names for debug builds" ON)
if(ENABLE_DEBUG_POSTFIX)
set(CMAKE_DEBUG_POSTFIX d)
endif()

# The API (SO) and detailed library versions for the shared library.
set(PROJECTM_SO_VERSION "3")
set(PROJECTM_LIB_VERSION "3.1.1")

project(projectm
LANGUAGES C CXX
VERSION 3.1.13
)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")

set(PROJECTM_BIN_DIR "bin" CACHE STRING "Executable installation directory, relative to the install prefix.")
set(PROJECTM_DATADIR_PATH "share/projectM" CACHE STRING "Default (absolute) path to the projectM data files (presets etc.)")
set(PROJECTM_LIB_DIR "lib" CACHE STRING "Library installation directory, relative to the install prefix.")
set(PROJECTM_INCLUDE_DIR "include" CACHE STRING "Header installation directory, relative to the install prefix.")

# Feature options, including dependencies.
option(ENABLE_PRESETS "Build and install bundled presets" ON)
option(ENABLE_NATIVE_PRESETS "Build and install native libraries written in C/C++" OFF)
option(ENABLE_TESTING "Build and install the projectM test suite" OFF)
option(ENABLE_EMSCRIPTEN "Build for web with emscripten" OFF)
cmake_dependent_option(ENABLE_SDL "Enable SDL2 support" ON "NOT ENABLE_EMSCRIPTEN;ENABLE_TESTING" ON)
cmake_dependent_option(ENABLE_GLES "Enable OpenGL ES support" OFF "NOT ENABLE_EMSCRIPTEN" ON)
cmake_dependent_option(ENABLE_THREADING "Enable multithreading support" ON "NOT ENABLE_EMSCRIPTEN;NOT CMAKE_SYSTEM_NAME STREQUAL Windows" OFF)
cmake_dependent_option(ENABLE_PULSEAUDIO "Build Pulseaudio-based Qt UI" OFF "ENABLE_QT;NOT ENABLE_EMSCRIPTEN;CMAKE_SYSTEM_NAME STREQUAL Linux" OFF)
cmake_dependent_option(ENABLE_JACK "Build JACK-based Qt and SDL UIs" OFF "ENABLE_QT;NOT ENABLE_EMSCRIPTEN;CMAKE_SYSTEM_NAME STREQUAL Linux" OFF)
cmake_dependent_option(ENABLE_LLVM "Enable LLVM JIT support" OFF "NOT ENABLE_EMSCRIPTEN" OFF)
cmake_dependent_option(ENABLE_LIBVISUAL "Build and install the projectM libvisual plug-in" OFF "NOT ENABLE_EMSCRIPTEN;CMAKE_SYSTEM_NAME STREQUAL Linux" OFF)

find_package(GLM)
if(NOT TARGET GLM::GLM)
add_library(GLM::GLM INTERFACE IMPORTED)
set_target_properties(GLM::GLM PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/vendor"
)

message(STATUS "GLM library not found, using bundled version.")
set(USE_SYSTEM_GLM OFF)
else()
set(USE_SYSTEM_GLM ON)
endif()

if(ENABLE_EMSCRIPTEN)
message(STATUS "${CMAKE_C_COMPILER}")
check_symbol_exists(__EMSCRIPTEN__ "" HAVE_EMSCRIPTEN)
if(NOT HAVE_EMSCRIPTEN)
message(FATAL_ERROR "You are not using an emscripten compiler.")
endif()
endif()

if(ENABLE_SDL)
find_package(SDL2 REQUIRED)

# Temporary fix to deal with wrong include dir set by SDL2's CMake configuration.
get_target_property(_SDL2_INCLUDE_DIR SDL2::SDL2 INTERFACE_INCLUDE_DIRECTORIES)
if(_SDL2_INCLUDE_DIR MATCHES "(.+)/SDL2\$")
message(STATUS "SDL2 include dir contains \"SDL2\" subdir (SDL bug #4004) - fixing to \"${CMAKE_MATCH_1}\".")
set_target_properties(SDL2::SDL2 PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_MATCH_1}"
)
endif()

if(SDL2_VERSION VERSION_LESS "2.0.5")
message(FATAL_ERROR "SDL2 libraries were found, but have version ${SDL2_VERSION}. At least version 2.0.5 is required.")
endif()
endif()

if(ENABLE_GLES)
find_package(GLES3 REQUIRED)
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)
list(APPEND PROJECTM_OPENGL_LIBRARIES GLEW::glew)
endif()
endif()

if(ENABLE_THREADING)
set(CMAKE_THREAD_PREFER_PTHREAD YES)
find_package(Threads REQUIRED)
if(NOT CMAKE_USE_PTHREADS_INIT)
message(FATAL_ERROR "Threading support requested - pthread support is required, but not available.")
endif()
set(USE_THREADS YES)
endif()

if(ENABLE_LLVM)
find_package(LLVM REQUIRED)
set(HAVE_LLVM TRUE)
else()
unset(HAVE_LLVM)
endif()

if(ENABLE_PULSEAUDIO)
find_package(Pulseaudio REQUIRED)
endif()

if(ENABLE_JACK)
find_package(JACK REQUIRED)
endif()

if(ENABLE_PULSEAUDIO OR ENABLE_JACK)
find_package(Qt5 REQUIRED COMPONENTS Gui OpenGL)
endif()

if(ENABLE_LIBVISUAL)
find_package(libvisual REQUIRED)
set(PROJECTM_LIBVISUAL_DIR "${LIBVISUAL_PLUGINSBASEDIR}/actor" CACHE STRING "Installation directory for the libvisual plug-in library.")
endif()

include(features.cmake)

add_subdirectory(presets)
add_subdirectory(src)

message(STATUS "")
message(STATUS "projectM 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 " libvisual plugin dir: ${PROJECTM_LIBVISUAL_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 " DATADIR_PATH: ${PROJECTM_DATADIR_PATH}")
message(STATUS " - - -")
message(STATUS "")
message(STATUS " Applications:")
message(STATUS " =====")
message(STATUS "")
message(STATUS " libprojectM: ON")
message(STATUS " Presets: ${ENABLE_PRESETS}")
message(STATUS " Native presets: ${ENABLE_NATIVE_PRESETS}")
message(STATUS " Tests: ${ENABLE_TESTING}")
message(STATUS " Threading: ${ENABLE_THREADING}")
message(STATUS " SDL2: ${ENABLE_SDL}")
if(ENABLE_SDL)
message(STATUS " SDL2 version: ${SDL2_VERSION}")
endif()
message(STATUS " Pulseaudio UI: ${ENABLE_PULSEAUDIO}")
if(ENABLE_PULSEAUDIO)
message(STATUS " Pulseaudio version: ${PULSEAUDIO_VERSION}")
endif()
message(STATUS " JACK UI: ${ENABLE_JACK}")
if(ENABLE_JACK)
message(STATUS " JACK version: ${JACK_VERSION}")
endif()
if(ENABLE_PULSEAUDIO OR ENABLE_JACK)
message(STATUS " Qt version: ${Qt5_VERSION}")
endif()
message(STATUS " OpenGLES: ${ENABLE_GLES}")
message(STATUS " Emscripten: ${ENABLE_EMSCRIPTEN}")
message(STATUS " LLVM JIT: ${ENABLE_LLVM}")
if(ENABLE_LLVM)
message(STATUS " LLVM version: ${LLVM_VERSION}")
endif()
message(STATUS " libvisual plug-in: ${ENABLE_LIBVISUAL}")
message(STATUS " Use system GLM: ${USE_SYSTEM_GLM}")

message(AUTHOR_WARNING
"The CMake build scripts for projectM are still in active development.\n"
"This means that build parameters, exported target names and other things can change "
"at any time until the new build system is officially documented and announced to be "
"fully supported.\n"
"DO NOT base any production work on it yet!\n"
)
26 changes: 26 additions & 0 deletions cmake/CheckEnumValueExists.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
include_guard()

include(CheckCSourceCompiles)

macro(check_enum_value_exists enum_value include variable)
if(NOT DEFINED ${variable})
message(STATUS "Looking for enum value ${enum_value}")
set(_CMAKE_REQUIRED_QUIET_tmp "${CMAKE_REQUIRED_QUIET}")
set(CMAKE_REQUIRED_QUIET ON)
check_c_source_compiles("
#include <${include}>
int main() {
int tmp = ${enum_value};
return 0;
}
"
${variable}
)
if(${variable})
message(STATUS "Looking for enum value ${enum_value} - found")
else()
message(STATUS "Looking for enum value ${enum_value} - not found")
endif()
set(CMAKE_REQUIRED_QUIET "${_CMAKE_REQUIRED_QUIET_tmp}")
endif()
endmacro()
47 changes: 47 additions & 0 deletions cmake/EnableCFlagsIfSupported.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
include(CheckCXXCompilerFlag)
include(CheckCXXSourceCompiles)

macro(enable_cflags_if_supported)
foreach(flag ${ARGN})
check_cxx_compiler_flag("${flag}" CXXFLAG_${flag}_SUPPORTED)
if(CXXFLAG_${flag}_SUPPORTED)
add_compile_options("${flag}")
endif()
endforeach()
endmacro()

macro(enable_linker_flags_if_supported)
set(_old_CMAKE_REQUIRED_LINK_OPTIONS "${CMAKE_REQUIRED_LINK_OPTIONS}")
foreach(flag ${ARGN})
set(CMAKE_REQUIRED_LINK_OPTIONS "${flag}")
check_cxx_source_compiles("int main(){return 0;}" LDCFLAG_${flag}_SUPPORTED)
if(LDCFLAG_${flag}_SUPPORTED)
add_link_options(${flag})
else()
set(CMAKE_REQUIRED_LINK_OPTIONS "LINKER:${flag}")
check_cxx_source_compiles("int main(){return 0;}" LDCFLAG_LINKER_${flag}_SUPPORTED)
if(LDFLAG_LINKER_${flag}_SUPPORTED)
add_link_options(LINKER:${flag})
endif()
endif()
endforeach()
set(CMAKE_REQUIRED_LINK_OPTIONS "${_old_CMAKE_REQUIRED_LINK_OPTIONS}")
endmacro()

macro(enable_target_linker_flags_if_supported target access)
set(_old_CMAKE_REQUIRED_LINK_OPTIONS "${CMAKE_REQUIRED_LINK_OPTIONS}")
foreach(flag ${ARGN})
set(CMAKE_REQUIRED_LINK_OPTIONS "${flag}")
check_cxx_source_compiles("int main(){return 0;}" LDCFLAG_${flag}_SUPPORTED)
if(LDCFLAG_${flag}_SUPPORTED)
target_link_options(${target} ${access} ${flag})
else()
set(CMAKE_REQUIRED_LINK_OPTIONS "LINKER:${flag}")
check_cxx_source_compiles("int main(){return 0;}" LDCFLAG_LINKER_${flag}_SUPPORTED)
if(LDFLAG_LINKER_${flag}_SUPPORTED)
target_link_options(${target} ${access} LINKER:${flag})
endif()
endif()
endforeach()
set(CMAKE_REQUIRED_LINK_OPTIONS "${_old_CMAKE_REQUIRED_LINK_OPTIONS}")
endmacro()
Empty file added cmake/FindGLES3.cmake
Empty file.
20 changes: 20 additions & 0 deletions cmake/FindGLM.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# The GLM library is header-only, so we only need to find the glm/glm.hpp header.
find_path(GLM_INCLUDE_DIR
glm/glm.hpp
)

find_file(GLM_INCLUDE_FILE
glm/glm.hpp
)

include(FindPackageHandleStandardArgs)

find_package_handle_standard_args(GLM DEFAULT_MSG GLM_INCLUDE_FILE GLM_INCLUDE_DIR)

if(GLM_FOUND AND NOT TARGET GLM::GLM)
add_library(GLM::GLM INTERFACE IMPORTED)

set_target_properties(GLM::GLM PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${GLM_INCLUDE_DIR}"
)
endif()
33 changes: 33 additions & 0 deletions cmake/FindJACK.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# First try to use PKG_CONFIG to find JACK.
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(JACK jack QUIET)
endif()

if(NOT JACK_INCLUDEDIR OR NOT JACK_LIBRARIES)
find_path(JACK_INCLUDEDIR
jack/jack.h
)

find_library(JACK_LIBRARIES
jack
)
endif()

include(FindPackageHandleStandardArgs)

find_package_handle_standard_args(JACK
REQUIRED_VARS JACK_LIBRARIES JACK_INCLUDEDIR
VERSION_VAR JACK_VERSION
)

if(JACK_FOUND AND NOT TARGET JACK::JACK)
add_library(JACK::JACK INTERFACE IMPORTED)

set_target_properties(JACK::JACK PROPERTIES
INTERFACE_LINK_LIBRARIES "${JACK_LIBRARIES}"
INTERFACE_LINK_DIRECTORIES "${JACK_LIBRARY_DIRS}"
INTERFACE_INCLUDE_DIRECTORIES "${JACK_INCLUDEDIR}"
INTERFACE_COMPILE_OPTIONS "${JACK_CFLAGS}"
)
endif()
Loading

0 comments on commit 83a08f3

Please sign in to comment.