Skip to content

Commit 1d55ade

Browse files
committed
Update CMake build instructions to match current state of development.
1 parent 46378e5 commit 1d55ade

File tree

1 file changed

+106
-89
lines changed

1 file changed

+106
-89
lines changed

Diff for: BUILDING-cmake.md

+106-89
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,37 @@ This file contains in-depth information for building with the CMake build system
66

77
Want to build it fast?
88

9-
Required tools: `cmake`.
9+
Required tools and dependencies:
10+
11+
- CMake 3.20 or higher.
12+
- A working toolchain, e.g. Visual Studio on Windows or the `build-essentials` package on Ubuntu Linux.
13+
- Main OpenGL libraries and development files.
14+
- The `GLEW` Library on Windows.
15+
16+
To use the library in other projects, it is required to install it. Use `CMAKE_INSTALL_PREFIX` to specify the
17+
installation directory.
18+
19+
From the project root, execute:
1020

1121
```shell
1222
mkdir build
1323
cd build
14-
cmake ..
15-
make -j8
24+
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/path/to/install-dir
25+
cmake --build . --target install --config Release
1626
```
1727

18-
Output binaries will be in `build/src/...`.
28+
If the build succeeded, you should now have the projectM libraries and include files in the specified install dir.
1929

20-
SDL2 binary can be found in `build/src/projectM-sdl/projectMSDL`.
30+
To use the library in other CMake projects, simply point the build to your install dir by adding it
31+
to `CMAKE_PREFIX_PATH` and call `find_package(libprojectM)` in the other project's `CMakeLists.txt`.
2132

33+
If you use other build systems, you have to specify the include and library paths manually.
2234

2335
## Selecting a specific project file generator
2436

37+
Building libprojectM does not require any specific CMake generator. It should work with any available generator, single-
38+
and multi-config.
39+
2540
To specify a CMake generator, use the `-G` switch, followed by the generator name. Some newer generators take an
2641
additional architecture using the `-A` switch. To list all available generators available on your current platform,
2742
leave out the generator name:
@@ -78,25 +93,35 @@ CMake has no built-in way of printing all available configuration options. You c
7893
top-level `CMakeLists.txt` which contains a block of `option` and `cmake_dependent_option` commands, or use one of the
7994
available CMake UIs which will display the options after configuring the project once.
8095

81-
### Boolean switches
96+
### Important build switches
8297

83-
The following table also gives you an overview of the available options and their defaults. All options accept a boolean
98+
The following table also gives you an overview of important build options and their defaults. All options accept a
99+
boolean
84100
value (`YES`/`NO`, `TRUE`/`FALSE`, `ON`/`OFF` or `1`/`0`) and can be provided on the configuration-phase command line
85101
using the `-D` switch.
86102

87-
| CMake option | Default | Required dependencies | Description |
88-
|-------------------------|---------|-----------------------|------------------------------------------------------------------------------------------------------------|
89-
| `ENABLE_DEBUG_PREFIX` | `ON` | | Adds `d` to the name of any binary file in debug builds. |
90-
| `ENABLE_EMSCRIPTEN` | `OFF` | `GLES`, `Emscripten` | Build for the web using Emscripten. |
91-
| `ENABLE_SDL` | `ON` | `SDL2` | Builds and installs the standalone SDL visualizer application. Also required for Emscripten and the tests. |
92-
| `ENABLE_GLES` | `OFF` | `GLES` | Use OpenGL ES 3 profile for rendering instead of the Core profile. |
93-
| `ENABLE_THREADING` | `ON` | `pthreads` | Enable multithreading support. If enabled, will cause an error if pthreads are not available. |
94-
| `ENABLE_PRESETS` | `ON` | | Installs several thousand shipped presets. |
95-
| `ENABLE_PULSEAUDIO` | `OFF` | `Qt5`, `Pulseaudio` | Build the Qt5-based Pulseaudio visualizer application. |
96-
| `ENABLE_JACK` | `OFF` | `Qt5`, `JACK` | Build the Qt5-based JACK visualizer application. |
97-
| `ENABLE_LIBVISUAL` | `OFF` | `libvisual-0.4` | Build the libvisual plug-in/actor library. |
98-
| `ENABLE_TESTING` | `OFF` | `SDL2` | Builds the unit tests. |
99-
| `ENABLE_LLVM` | `OFF` | `LLVM` | Enables experimental LLVM JIT support. |
103+
| CMake option | Default | Required dependencies | Description |
104+
|---------------------|---------|-----------------------|---------------------------------------------------------------------------------------------|
105+
| `BUILD_TESTING` | `OFF` | | Builds the unit tests. |
106+
| `BUILD_SHARED_LIBS` | `ON` | | Build projectM as shared libraries. If `OFF`, build static libraries. |
107+
| `ENABLE_PLAYLIST` | `ON` | | Builds and installs the playlist library. |
108+
| `ENABLE_EMSCRIPTEN` | `OFF` | `Emscripten` | Build for the web using Emscripten. Only supports build as a static library and using GLES. |
109+
110+
### Experimental and application-dependent build switches
111+
112+
The following table contains a list of build options which are only useful in special circumstances, e.g. when
113+
developing libprojectM, trying experimental features or building the library for a special use-case/environment.
114+
115+
| CMake option | Default | Required dependencies | Description |
116+
|------------------------|---------|-----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------|
117+
| `ENABLE_SDL_UI` | `ON` | `SDL2` | Builds the SDL-based test application. Only used for development testing, will not be installed. |
118+
| `ENABLE_GLES` | `OFF` | `GLES` | Use OpenGL ES 3 profile for rendering instead of the Core profile. |
119+
| `ENABLE_THREADING` | `ON` | | Enable multithreading support for preset loading if available. |
120+
| `ENABLE_OPENMP` | `ON` | `OpenMP` | Enable OpenMP support if available. |
121+
| `ENABLE_DEBUG_POSTFIX` | `ON` | | Adds `d` (by default) to the name of any binary file in debug builds. |
122+
| `ENABLE_SYSTEM_GLM` | `OFF` | | Builds against a system-installed GLM library. |
123+
| `ENABLE_LLVM` | `OFF` | `LLVM` | Enables **highly experimental** LLVM JIT support. Will most probably not build, as the LLVM API changes frequently. |
124+
| `ENABLE_CXX_INTERFACE` | `OFF` | | Exports symbols for the `ProjectM` and `PCM` C++ classes and installs the additional the headers. Using the C++ interface is not recommended and unsupported. |
100125

101126
### Path options
102127

@@ -105,15 +130,23 @@ the following options are appended to the value
105130
of [`CMAKE_INSTALL_PREFIX`](https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html) (which, on most UNIX
106131
platforms, defaults to `/usr/local`):
107132

108-
| CMake option | Default | Description |
109-
|-------------------------|------------------|----------------------------------------------------------------------------------|
110-
| `PROJECTM_BIN_DIR` | `bin` | Directory where executables (e.g. the SDL standalone application) are installed. |
111-
| `PROJECTM_LIB_DIR` | `lib` | Directory where libprojectM is installed[<sup>[*]</sup>](#libvisual-path). |
112-
| `PROJECTM_INCLUDE_DIR` | `include` | Directory where the libprojectM include files will be installed under. |
113-
| `PROJECTM_DATADIR_PATH` | `share/projectM` | Directory where the default configuration and presets are installed under. |
133+
| CMake option | Default | Description |
134+
|------------------------|----------------|--------------------------------------------------------------------------------------------|
135+
| `CMAKE_INSTALL_PREFIX` | (OS dependent) | Base directory where the projectM libraries, includes and support files will be installed. |
136+
| `PROJECTM_BIN_DIR` | `bin` | Directory where executables (e.g. the SDL standalone application) are installed. |
137+
| `PROJECTM_LIB_DIR` | `lib[64]` | Directory where libprojectM is installed. |
138+
| `PROJECTM_INCLUDE_DIR` | `include` | Directory where the libprojectM include files will be installed under. |
139+
140+
### Other options
114141

115-
<a name="libvisual-path"></a>[*]: The libvisual projectM plug-in install location is determined automatically via
116-
pkgconfig and not influenced by this option.
142+
Various other options for specific needs.
143+
144+
| CMake option | Default | Description |
145+
|----------------------------|----------------------------------------|-------------------------------------------------------------------------------------------------------------------|
146+
| `CMAKE_DEBUG_POSTFIX` | `d` (if `ENABLE_DEBUG_POSTFIX` is set) | Postfix appended to debug libraries. |
147+
| `CMAKE_INSTALL_BINDIR` | `bin` | Another way to specify the binary installation directory. Used as default value for `PROJECTM_BIN_DIR`. |
148+
| `CMAKE_INSTALL_LIBDIR` | `lib` or `lib64` | Another way to specify the library installation directory. Used as default value for `PROJECTM_LIB_DIR`. |
149+
| `CMAKE_INSTALL_INCLUDEDIR` | `include` | Another way to specify the include file installation directory. Used as default value for `PROJECTM_INCLUDE_DIR`. |
117150

118151
## Always perform out-of-tree builds!
119152

@@ -168,8 +201,8 @@ several reasons:
168201
deleting the build directory).
169202
3. For some configurations, even Release build artifacts may contain debug symbols until they are installed.
170203

171-
It is fine to build and run executables from the build directory for development and debugging. For packaging, always
172-
use the `install` target and copy files from there.
204+
It is fine to build and run executables from the build directory for development and debugging. For packaging or using
205+
libprojectM in other projects, always use the `install` target and copy files from there.
173206

174207
### Generated files
175208

@@ -185,13 +218,8 @@ In the top-level build directory, CMake creates a few files that are present on
185218
- The top-level project file for use with the selected build toolset, e.g. `Makefile`, `build.ninja`, `projectm.sln`
186219
or `projectm.xcodeproj`, plus additional toolset-specific files.
187220

188-
The projectM build files generate additional files used in the build and install phases:
189-
190-
- `config.inp`: The default configuration file, by default installed to `<prefix>/share/projectM`.
191-
- `libprojectM.pc`: Package configuration file for use with `pkgconfig`.
192-
- `include/config.h`: A forced include file that contains macro definitions to enable or disable certain code features
193-
based on the build configuration and availability of platform headers and features. Similar to the
194-
autoheader-generated file.
221+
The projectM build files generate additional files used in the build and install phases. These are scattered over the
222+
build tree, but installed into the proper directories. Do not try and gather these files yourself from the build tree.
195223

196224
### Subdirectory structure
197225

@@ -200,6 +228,8 @@ a `CMakeLists.txt` file will also be created in the build tree with the same rel
200228
contains a `CMakeFiles` directory with CMake-internal data, generated project files for the select toolset, e.g.
201229
makefiles and any temporary compile artifacts.
202230

231+
The directory structure is created by CMake and may change depending on the generator and CMake version used.
232+
203233
### Executable and library locations
204234

205235
Build targets - shared/static libraries and executables - are created in the same subdirectory in the build tree as
@@ -213,84 +243,71 @@ on Windows.
213243

214244
## Using libprojectM in other CMake projects
215245

216-
The projectM library can be used as a static library and, on non-Windows platforms, as a shared library in other
217-
CMake-based projects to provide embedded audio visualization. There are two ways:
246+
The projectM library can be used as a static library or shared library in other CMake-based projects to provide embedded
247+
audio visualization. It is highly recommended to build projectM as shared libraries for maximum compatibility and LGPL
248+
compliance.
218249

219-
- Importing the library CMake targets directly from the build tree without installation.
220-
- Using the library from an installed location or package with the provided CMake package config files.
250+
The build directory is not structured in a way that other projects can make use of it. Use the `install` target to copy
251+
all required files to the configured installation prefix. You can customize the subdirectories for libraries, includes
252+
and binaries using the `PROJECTM_<X>>_DIR` variables when configuring the CMake project.
221253

222254
### Importing libprojectM targets from the build tree
223255

224-
This approach is useful for projects that either require more in-depth access to the projectM library files, especially
225-
to headers that are not installed as part of the public API. This might cause issues if the internal headers change, but
226-
gives a broader set of features and more control to the developer.
227-
228-
To use the targets, follow these steps:
256+
This approach is not recommended, but can be useful for projects that either require more in-depth access to the
257+
projectM library files, especially to headers that are not installed as part of the public API. This might cause issues
258+
if the internal headers change, but gives a broader set of features and more control to the developer.
229259

230-
- Configure the build directory as needed.
231-
- Build the required library targets `projectM_static` and `projectM_shared` as needed, or simply everything.
232-
- Include the file `src/libprojectM/projectM-exports.cmake` from the projectM build tree in your project.
233-
234-
All targets and their interface properties are now defined and can be used.
235-
236-
#### Example
237-
238-
```cmake
239-
# libprojectM.a/.lib is already built.
240-
set(PROJECTM_BUILD_DIR "/some/path/to/projectM/build")
241-
include("${PROJECTM_BUILD_DIR}/src/libprojectM/projectM-exports.cmake")
242-
243-
add_executable(MyApp main.cpp)
244-
245-
target_link_libraries(MyApp PRIVATE libprojectM::static)
246-
```
247-
248-
This will also add all projectM include directories to the target's source files, pointing to the respective projectM
249-
source directories.
250-
251-
Look at the generated file in the build tree if you need more details about the available targets.
260+
Please refer to the [`ExternalProject`](https://cmake.org/cmake/help/latest/module/ExternalProject.html) CMake module
261+
documentation on how to set up the libprojectM build system for use in another project.
252262

253263
### Importing libprojectM targets from an installed version
254264

255-
This is the recommended way of importing libprojectM in your project. This project installs a set of CMake files
256-
in `<PREFIX>/<LIBDIR>/cmake/libprojectM`, containing target definitions, version and dependency checks as well as any
257-
additional libraries required for linking. Other projects then use CMake's `find_package` command to search for these
258-
files in [different locations](https://cmake.org/cmake/help/latest/command/find_package.html#search-procedure).
265+
This is the recommended and supported way of importing libprojectM in your project. This project installs a set of CMake
266+
files in `<PREFIX>/<LIBDIR>/cmake/libprojectM`, containing target definitions, version and dependency checks as well as
267+
any additional libraries required for linking. Other projects then use CMake's `find_package` command to search for
268+
these files in [different locations](https://cmake.org/cmake/help/latest/command/find_package.html#search-procedure).
259269

260270
In the case projectM libraries and headers are not installed in any system search path, you need to add either the
261271
install prefix path (the top-level install dir) or the directory containing the libraries (the `lib` dir by default) to
262272
the [`CMAKE_PREFIX_PATH`](https://cmake.org/cmake/help/latest/variable/CMAKE_PREFIX_PATH.html) list.
263273

264-
If the package was found, you can then link against one of these provided targets:
265-
266-
- `libprojectM::static` - The static library (`.a` or `.lib`).
267-
- `libprojectM::shared` - The shared library (`.so`, `.dylib` or `.dll`).
268-
269-
Note that the availability of the targets depend on the platform and build configuration, so only one of those might be
270-
available. You can check with `if(TARGET libprojectM::static)` and `if(TARGET libprojectM::shared)` to select the
271-
available or preferred one.
274+
If the package was found, you can then link against libprojectM by using the `libprojectM::projectM` target.
272275

273276
Depending on how the package was built, targets might be available for multiple configurations or only `Release`. CMake
274277
will automatically select the most appropriate one to link.
275278

276279
Include dirs, additional link dependencies and possible compiler options will be propagated to any target the library is
277280
linked to.
278281

279-
#### Example
282+
#### Using the optional playlist library
280283

281-
Links the shared library preferably, with fallback to static:
284+
If you want to use the optional playlist library, you need to specifically request it as a component:
282285

283286
```cmake
284-
find_package(libprojectM REQUIRED)
287+
find_package(libprojectM COMPONENTS Playlist)
288+
```
289+
290+
You can either use `REQUIRED` to force a fatal error if the component cannot be found or check if the target exists
291+
using:
285292

286-
if(TARGET libprojectM::shared)
287-
set(PROJECTM_LINK_TARGET libprojectM::shared)
288-
else()
289-
# If this target is also unavailable, CMake will error out on target_link_libraries().
290-
set(PROJECTM_LINK_TARGET libprojectM::static)
293+
```cmake
294+
if(TARGET libprojectM::playlist)
295+
# ...
291296
endif()
297+
```
298+
299+
If you link the playlist library, the main `libprojectM::projectM` target will be linked automatically as a dependency.
300+
301+
#### Example
302+
303+
Searches for projectM and the playlist library and links both to the application:
304+
305+
```cmake
306+
find_package(libprojectM REQUIRED COMPONENTS Playlist)
292307
293308
add_executable(MyApp main.cpp)
294309
295-
target_link_libraries(MyApp PRIVATE ${PROJECTM_LINK_TARGET})
310+
target_link_libraries(MyApp PRIVATE
311+
libprojectM::Playlist
312+
)
296313
```

0 commit comments

Comments
 (0)