Skip to content

Commit d371172

Browse files
committed
Replace config.h with SpatialaudioConfig.h
This new file has properly prefixed defines preventing name clashes with macros defined in library consumer build systems. Additionally a new define is added that hints if the library was built statically, needed to properly disable API imports in that case, on Windows.
1 parent 0e26017 commit d371172

File tree

13 files changed

+81
-31
lines changed

13 files changed

+81
-31
lines changed

CMakeLists.txt

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
1717

1818
# Dependencies
1919
find_package(MySofa QUIET)
20-
set(HAVE_MYSOFA ${MYSOFA_FOUND})
2120

2221
# Spatialaudio library
2322
add_library(spatialaudio)
@@ -130,9 +129,28 @@ target_sources(spatialaudio
130129
include/SpatialaudioAPI.h
131130
)
132131

132+
# Generate config header
133+
set(SPATIALAUDIO_SUPPORTS_SOFA ${MYSOFA_FOUND})
134+
set(SPATIALAUDIO_SUPPORTS_MIT_HRTF ${HAVE_MIT_HRTF})
135+
set(SPATIALAUDIO_STATIC $<STREQUAL:$<TARGET_PROPERTY,spatialaudio:TYPE>,STATIC_LIBRARY>)
136+
137+
configure_file(
138+
"include/SpatialaudioConfig.h.in"
139+
"include/SpatialaudioConfig.h"
140+
)
141+
142+
target_sources(spatialaudio
143+
PUBLIC
144+
FILE_SET generated_headers
145+
TYPE HEADERS
146+
BASE_DIRS $<TARGET_PROPERTY:BINARY_DIR>/include
147+
FILES
148+
$<TARGET_PROPERTY:BINARY_DIR>/include/SpatialaudioConfig.h
149+
)
150+
133151
target_include_directories(spatialaudio
134152
PRIVATE
135-
${CMAKE_CURRENT_BINARY_DIR}
153+
$<TARGET_PROPERTY:BINARY_DIR>/include
136154
)
137155
target_compile_definitions(spatialaudio
138156
PRIVATE
@@ -148,11 +166,6 @@ if(MYSOFA_FOUND)
148166
target_link_libraries(spatialaudio ${MYSOFA_LIBRARIES})
149167
endif(MYSOFA_FOUND)
150168

151-
configure_file(
152-
"${CMAKE_CURRENT_SOURCE_DIR}/include/config.h.in"
153-
"${CMAKE_CURRENT_BINARY_DIR}/config.h"
154-
)
155-
156169
configure_file(
157170
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/spatialaudio.pc.cmake"
158171
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
@@ -164,6 +177,8 @@ install(TARGETS spatialaudio
164177
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
165178
FILE_SET HEADERS
166179
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spatialaudio
180+
FILE_SET generated_headers
181+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spatialaudio
167182
)
168183
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
169184
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,5 @@
6161
- CMake: Removed the `BUILD_STATIC_LIBS` option. Use the `BUILD_SHARED_LIBS`
6262
option to control if share or static libraries should be built. If both are
6363
needed, build twice explicitly.
64+
- The `config.h` header file was removed in favor of `SpatialaudioConfig.h` with
65+
properly prefixed defines to prevent name clashes.

include/SpatialaudioAPI.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#ifndef SPATIALAUDIO_API_H
1111
#define SPATIALAUDIO_API_H
1212

13+
#include "SpatialaudioConfig.h"
14+
1315
#if defined(__GNUC__) && (__GNUC__ >= 4)
1416
// GCC/Clang symbol visibility
1517
# define SPATIALAUDIO_EXPORT __attribute__((__visibility__("default")))

include/SpatialaudioConfig.h.in

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*############################################################################*/
2+
/*# #*/
3+
/*# Config information about the libspatialaudio build #*/
4+
/*# #*/
5+
/*# Author(s): Marvin Scholz #*/
6+
/*# Licence: LGPL + proprietary #*/
7+
/*# #*/
8+
/*############################################################################*/
9+
10+
#ifndef SPATIALAUDIO_CONFIG_H
11+
#define SPATIALAUDIO_CONFIG_H
12+
13+
// True if libspatialaudio was built with libmysofa support
14+
#cmakedefine01 SPATIALAUDIO_SUPPORTS_SOFA
15+
16+
// True if libspatialaudio was built with the integrated MIT HRTF
17+
#cmakedefine01 SPATIALAUDIO_SUPPORTS_MIT_HRTF
18+
19+
// Defined if libspatialaudio was built statically
20+
//
21+
// This is merely a hint, as both the shared and
22+
// static library could be built, in which case this
23+
// would be unset and is expected to be set correctly
24+
// by library consumers as only there it can be known
25+
// against which library is linked.
26+
#ifndef SPATIALAUDIO_STATIC
27+
#cmakedefine SPATIALAUDIO_STATIC
28+
#endif
29+
30+
#endif /* SPATIALAUDIO_CONFIG_H */

include/config.h.in

Lines changed: 0 additions & 7 deletions
This file was deleted.

include/hrtf/mit_hrtf.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#ifndef MIT_HRTF_H
22
#define MIT_HRTF_H
33

4-
#include "hrtf.h"
4+
#include "SpatialaudioConfig.h"
5+
6+
#if SPATIALAUDIO_SUPPORTS_MIT_HRTF
57

6-
#ifdef HAVE_MIT_HRTF
8+
#include "hrtf.h"
79

810
namespace spaudio {
911

include/hrtf/sofa_hrtf.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#ifndef SOFA_HRTF_H
22
#define SOFA_HRTF_H
33

4-
#include "config.h"
4+
#include "SpatialaudioConfig.h"
55

6-
#ifdef HAVE_MYSOFA
6+
#if SPATIALAUDIO_SUPPORTS_SOFA
77

88
#include <string>
99

include/meson.build

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
config_h = configure_file(
2-
output : 'config.h',
3-
configuration : conf_data
2+
input : 'SpatialaudioConfig.h.in',
3+
output : 'SpatialaudioConfig.h',
4+
configuration : conf_data,
5+
format : 'cmake',
46
)
57

68
# Public header files that are installed

meson.build

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@ conf_data = configuration_data()
1515

1616
libmysofa_dep = dependency('libmysofa', required : get_option('libmysofa'))
1717
if libmysofa_dep.found()
18-
conf_data.set('HAVE_MYSOFA', 1)
18+
conf_data.set('SPATIALAUDIO_SUPPORTS_SOFA', 1)
1919
dependencies += libmysofa_dep
2020
endif
2121

2222
if get_option('mit_hrtf').allowed()
23-
conf_data.set('HAVE_MIT_HRTF', 1)
23+
conf_data.set('SPATIALAUDIO_SUPPORTS_MIT_HRTF', 1)
2424
add_languages('c', native: false)
2525
endif
2626

27+
if get_option('default_library') == 'static'
28+
conf_data.set('SPATIALAUDIO_STATIC', 1)
29+
endif
30+
2731
subdir('include')
2832
subdir('source')
2933

source/AmbisonicBinauralizer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
/*############################################################################*/
1515

1616

17-
#include "config.h"
17+
#include "SpatialaudioConfig.h"
1818

1919
#include <iostream>
2020

@@ -385,15 +385,15 @@ namespace spaudio {
385385
{
386386
HRTF* p_hrtf;
387387

388-
#ifdef HAVE_MYSOFA
389-
# ifdef HAVE_MIT_HRTF
388+
#if SPATIALAUDIO_SUPPORTS_SOFA
389+
# if SPATIALAUDIO_SUPPORTS_MIT_HRTF
390390
if (HRTFPath == "")
391391
p_hrtf = new MIT_HRTF(nSampleRate);
392392
else
393393
# endif
394394
p_hrtf = new SOFA_HRTF(HRTFPath, nSampleRate);
395395
#else
396-
# ifdef HAVE_MIT_HRTF
396+
# if SPATIALAUDIO_SUPPORTS_MIT_HRTF
397397
p_hrtf = new MIT_HRTF(nSampleRate);
398398
(void)HRTFPath;
399399
# else

0 commit comments

Comments
 (0)