Skip to content

Commit b34e477

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 b34e477

File tree

13 files changed

+82
-32
lines changed

13 files changed

+82
-32
lines changed

CMakeLists.txt

Lines changed: 26 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,32 @@ 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+
if(NOT BUILD_SHARED_LIBS)
136+
set(SPATIALAUDIO_STATIC YES)
137+
endif()
138+
139+
message("Type: $<TARGET_PROPERTY:spatialaudio,TYPE>")
140+
141+
configure_file(
142+
"include/SpatialaudioConfig.h.in"
143+
"include/SpatialaudioConfig.h"
144+
)
145+
146+
target_sources(spatialaudio
147+
PUBLIC
148+
FILE_SET generated_headers
149+
TYPE HEADERS
150+
BASE_DIRS $<TARGET_PROPERTY:BINARY_DIR>/include
151+
FILES
152+
${CMAKE_CURRENT_BINARY_DIR}/include/SpatialaudioConfig.h
153+
)
154+
133155
target_include_directories(spatialaudio
134156
PRIVATE
135-
${CMAKE_CURRENT_BINARY_DIR}
157+
${CMAKE_CURRENT_BINARY_DIR}/include
136158
)
137159
target_compile_definitions(spatialaudio
138160
PRIVATE
@@ -148,11 +170,6 @@ if(MYSOFA_FOUND)
148170
target_link_libraries(spatialaudio ${MYSOFA_LIBRARIES})
149171
endif(MYSOFA_FOUND)
150172

151-
configure_file(
152-
"${CMAKE_CURRENT_SOURCE_DIR}/include/config.h.in"
153-
"${CMAKE_CURRENT_BINARY_DIR}/config.h"
154-
)
155-
156173
configure_file(
157174
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/spatialaudio.pc.cmake"
158175
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
@@ -164,6 +181,8 @@ install(TARGETS spatialaudio
164181
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
165182
FILE_SET HEADERS
166183
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spatialaudio
184+
FILE_SET generated_headers
185+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/spatialaudio
167186
)
168187
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc"
169188
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
#include "hrtf.h"
55

6-
#ifdef HAVE_MIT_HRTF
6+
#if SPATIALAUDIO_SUPPORTS_MIT_HRTF
77

88
namespace spaudio {
99

include/hrtf/sofa_hrtf.h

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

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

6-
#ifdef HAVE_MYSOFA
6+
#if SPATIALAUDIO_SUPPORTS_SOFA
77

88
#include <string>
99

1010
#include <mysofa.h>
1111

12-
#include "hrtf.h"
13-
1412
namespace spaudio {
1513

1614
class SPAUDIO_API SOFA_HRTF : public HRTF

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)