Add d-bus support to CMake build system, and add howto to README.cmake. (Thanks, plcl!)

This commit is contained in:
David Henningsson 2010-06-25 11:12:49 +00:00
parent 277262b5ea
commit 335f21b697
6 changed files with 112 additions and 1 deletions

View file

@ -61,6 +61,7 @@ option ( enable-midishare "compile MidiShare support (if it is available)" on )
option ( enable-dart "compile DART support (if it is available)" on )
option ( enable-readline "compile readline lib line editing (if it is available)" on )
option ( enable-lash "compile LASH support (if it is available)" on )
option ( enable-dbus "compile DBUS support (if it is available)" on )
# Initialize the library directory name suffix.
if ( CMAKE_SIZEOF_VOID_P EQUAL 8 )
@ -325,6 +326,13 @@ if ( enable-ladcca )
set ( LADCCA_SUPPORT ${LADCCA_FOUND} )
endif ( enable-ladcca )
set ( DBUS_SUPPORT )
set ( DBUS_LIBRARIES )
if ( enable-dbus )
pkg_check_modules ( DBUS dbus-1>=1.0.0 )
set ( DBUS_SUPPORT ${DBUS_FOUND} )
endif ( enable-dbus )
# General configuration file
configure_file ( ${CMAKE_SOURCE_DIR}/src/config.cmake
${CMAKE_BINARY_DIR}/config.h )

View file

@ -1,3 +1,11 @@
Select build system
===================
We currently have two different build systems and you can choose
which one works best for you. If you want to use the CMake build
system, please see the README.cmake file. For the autotools build
system, see below.
Basic Installation
==================

View file

@ -83,3 +83,80 @@ The CMake build system for FluidSynth is experimental. It will take a while
until it becomes stable and fully tested. You can help providing feedback,
please send a report containing your problems to the FluidSynth development
mailing list: http://lists.nongnu.org/mailman/listinfo/fluid-dev
For developers - how to add a new feature to the CMake build system
===================================================================
Let's explain this issue with an example. We are adding D-Bus support to FluidSynth as an optional feature, conditionally adding source files that require this feature. The first step is to add a macro "option()" to the main CMakeLists.txt file, the one that is located at the fluidsynth root directory.
file CMakeLists.txt, line 64:
option ( enable-dbus "compile DBUS support (if it is available)" on )
Now, let's check if the dbus-1 library and headers are installed, using pkg-config:
file CMakeLists.txt, lines 329-334:
set ( DBUS_SUPPORT )
set ( DBUS_LIBRARIES )
if ( enable-dbus )
pkg_check_modules ( DBUS dbus-1>=1.0.0 )
set ( DBUS_SUPPORT ${DBUS_FOUND} )
endif ( enable-dbus )
The two first lines clear the values of the CMake variables DBUS_LIBRARIES and DBUS_SUPPORT. If the value of the option "enable-dbus" is true, then the macro pkg_check_modules() is used to test a package named "dbus-1" with version 1.0.0 or later. This macro automatically defines the variables DBUS_LIBRARIES, DBUS_INCLUDEDIR, DBUS_FOUND and others. The value of the last one is assigned to our variable DBUS_SUPPORT for later use.
There is a report to summarize the performed checks and the enabled features after the configuration steps, so let's add a line in this report regarding the D-Bus support.
file cmake_admin/report.cmake, lines 14-18:
if ( DBUS_SUPPORT )
message ( "D-Bus: yes" )
else ( DBUS_SUPPORT )
message ( "D-Bus: no" )
endif ( DBUS_SUPPORT )
The variable DBUS_SUPPORT is available for the CMake files, but we want to make it available to the compilers as well, to conditionally build code using "#ifdef DBUS_SUPPORT". This can be done adding a line to the config.cmake file:
file src/config.cmake, lines 22-23:
/* Define if D-Bus support is enabled */
#cmakedefine DBUS_SUPPORT @DBUS_SUPPORT@
The file config.cmake will be processed at configure time, producing a header file "config.h" in the build directory with this content, if the dbus support has been enabled and found:
/* Define if D-Bus support is enabled */
#define DBUS_SUPPORT 1
Finally, we can add the new source files to the build system for the compiler target with the macro add_library(), and the libraries for the linker target with the macros link_directories() and target_link_libraries().
file src/CMakeLists.txt, lines 57-60
if ( DBUS_SUPPORT )
set ( fluid_dbus_SOURCES fluid_rtkit.c fluid_rtkit.h )
include_directories ( ${DBUS_INCLUDEDIR} ${DBUS_INCLUDE_DIRS} )
endif ( DBUS_SUPPORT )
file src/CMakeLists.txt, lines 163-197
link_directories (
...
${DBUS_LIBDIR}
${DBUS_LIBRARY_DIRS}
)
add_library ( libfluidsynth SHARED
...
${fluid_dbus_SOURCES}
...
)
file src/CMakeLists.txt, lines 163-197
target_link_libraries ( libfluidsynth
...
${DBUS_LIBRARIES}
...
)

View file

@ -11,6 +11,12 @@ else ( LIBSNDFILE_SUPPORT )
message ( "libsndfile: no (raw audio file rendering only)" )
endif ( LIBSNDFILE_SUPPORT )
if ( DBUS_SUPPORT )
message ( "D-Bus: yes" )
else ( DBUS_SUPPORT )
message ( "D-Bus: no" )
endif ( DBUS_SUPPORT )
if ( PULSE_SUPPORT )
message ( "PulseAudio: yes" )
else ( PULSE_SUPPORT )

View file

@ -54,6 +54,11 @@ if ( COREMIDI_SUPPORT )
set ( fluid_coremidi_SOURCES drivers/fluid_coremidi.c )
endif ( COREMIDI_SUPPORT )
if ( DBUS_SUPPORT )
set ( fluid_dbus_SOURCES fluid_rtkit.c fluid_rtkit.h )
include_directories ( ${DBUS_INCLUDEDIR} ${DBUS_INCLUDE_DIRS} )
endif ( DBUS_SUPPORT )
if ( JACK_SUPPORT )
set ( fluid_jack_SOURCES drivers/fluid_jack.c )
include_directories ( ${JACK_INCLUDEDIR} ${JACK_INCLUDE_DIRS} )
@ -172,6 +177,8 @@ link_directories (
${PORTAUDIO_LIBRARY_DIRS}
${LIBSNDFILE_LIBDIR}
${LIBSNDFILE_LIBRARY_DIRS}
${DBUS_LIBDIR}
${DBUS_LIBRARY_DIRS}
)
add_library ( libfluidsynth SHARED
@ -179,6 +186,7 @@ add_library ( libfluidsynth SHARED
${fluid_coreaudio_SOURCES}
${fluid_coremidi_SOURCES}
${fluid_dart_SOURCES}
${fluid_dbus_SOURCES}
${fluid_jack_SOURCES}
${fluid_lash_SOURCES}
${fluid_ladspa_SOURCES}
@ -218,13 +226,14 @@ target_link_libraries ( libfluidsynth
${PULSE_LIBRARIES}
${PORTAUDIO_LIBRARIES}
${LIBSNDFILE_LIBRARIES}
${DBUS_LIBRARIES}
${READLINE_LIBS}
${DART_LIBS}
${COREAUDIO_LIBS}
${COREMIDI_LIBS}
${WINDOWS_LIBS}
${MidiShare_LIBS}
${LIBFLUID_LIBS}
${LIBFLUID_LIBS}
)
# ************ CLI program ************

View file

@ -19,6 +19,9 @@
/* Define if building for Mac OS X Darwin */
#cmakedefine DARWIN @DARWIN@
/* Define if D-Bus support is enabled */
#cmakedefine DBUS_SUPPORT @DBUS_SUPPORT@
/* Define to enable FPE checks */
#cmakedefine FPE_CHECK @FPE_CHECK@