fix-build.patch 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
  2. index dcaa92a..76fd021 100644
  3. --- a/src/CMakeLists.txt
  4. +++ b/src/CMakeLists.txt
  5. @@ -10,38 +10,39 @@ endmacro(use_c99)
  6. use_c99()
  7. +find_package(ZLIB REQUIRED)
  8. configure_file(config.h.in config.h)
  9. -include_directories(${CMAKE_CURRENT_BINARY_DIR})
  10. +include_directories(${CMAKE_CURRENT_BINARY_DIR} ${ZLIB_INCLUDE_DIRS})
  11. if(NOT MSVC)
  12. - if(NOT WIN32)
  13. + if(NOT WIN32 AND NOT EMSCRIPTEN)
  14. find_library(MATH m)
  15. else()
  16. set(MATH "")
  17. endif()
  18. - include(FindZLIB)
  19. else()
  20. set(MATH "")
  21. + if(0)
  22. find_program(NUGET nuget)
  23. if(NUGET)
  24. execute_process(COMMAND ${NUGET} install zlib)
  25. endif()
  26. include_directories(
  27. ${PROJECT_SOURCE_DIR}/windows/third-party/zlib-1.2.11/include/)
  28. + endif()
  29. endif()
  30. if(NOT MSVC)
  31. - if(NOT WIN32)
  32. + if(NOT WIN32 AND NOT EMSCRIPTEN)
  33. find_library(MATH m)
  34. else()
  35. set(MATH "")
  36. endif()
  37. - include(FindZLIB)
  38. - include_directories(${ZLIB_INCLUDE_DIRS})
  39. set(PKG_CONFIG_PRIVATELIBS "-lm ${PKG_CONFIG_PRIVATELIBS}")
  40. set(PKG_CONFIG_PRIVATELIBS "-lz ${PKG_CONFIG_PRIVATELIBS}")
  41. else()
  42. set(MATH "")
  43. + if(0)
  44. find_program(NUGET nuget)
  45. if(NOT NUGET)
  46. message(
  47. @@ -53,6 +54,7 @@ else()
  48. endif()
  49. include_directories(
  50. ${PROJECT_SOURCE_DIR}/windows/third-party/zlib-1.2.11/include/)
  51. + endif()
  52. endif()
  53. set(libsrc
  54. @@ -80,6 +82,7 @@ set(libsrc
  55. set(public-headers
  56. hrtf/mysofa.h
  57. )
  58. +install(FILES "${public-headers}" DESTINATION include)
  59. if(BUILD_STATIC_LIBS)
  60. add_library(mysofa-static STATIC ${libsrc})
  61. @@ -88,7 +91,7 @@ target_include_directories(mysofa-static
  62. "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/hrtf>"
  63. $<INSTALL_INTERFACE:include/>
  64. )
  65. -target_link_libraries(mysofa-static LINK_PRIVATE ${MATH} ${ZLIB_LIBRARIES})
  66. +target_link_libraries(mysofa-static LINK_PRIVATE ${MATH} ZLIB::ZLIB)
  67. set_target_properties(
  68. mysofa-static
  69. PROPERTIES OUTPUT_NAME mysofa CLEAN_DIRECT_OUTPUT 1 POSITION_INDEPENDENT_CODE
  70. @@ -169,6 +172,11 @@ else()
  71. mysofa_export.h)
  72. endif()
  73. +install(
  74. + FILES ${PROJECT_BINARY_DIR}/src/mysofa_export.h
  75. + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
  76. +)
  77. +
  78. if(BUILD_TESTS)
  79. add_executable(mysofa2json tests/sofa2json.c tests/json.c)
  80. if(BUILD_STATIC_LIBS)
  81. diff --git a/src/hrtf/mysofa.h b/src/hrtf/mysofa.h
  82. index 206e77b..82bc9d9 100644
  83. --- a/src/hrtf/mysofa.h
  84. +++ b/src/hrtf/mysofa.h
  85. @@ -14,6 +14,7 @@ extern "C" {
  86. #include <stdint.h>
  87. #include <stddef.h>
  88. +#include "mysofa_export.h"
  89. #define MYSOFA_DEFAULT_NEIGH_STEP_ANGLE 0.5f
  90. #define MYSOFA_DEFAULT_NEIGH_STEP_RADIUS 0.01f
  91. @@ -127,44 +128,44 @@ enum {
  92. MYSOFA_ONLY_SOURCES_WITH_MC_SUPPORTED
  93. };
  94. -struct MYSOFA_HRTF *mysofa_load(const char *filename, int *err);
  95. -struct MYSOFA_HRTF *mysofa_load_data(const char *data, size_t size, int *err);
  96. +MYSOFA_EXPORT struct MYSOFA_HRTF *mysofa_load(const char *filename, int *err);
  97. +MYSOFA_EXPORT struct MYSOFA_HRTF *mysofa_load_data(const char *data, size_t size, int *err);
  98. -int mysofa_check(struct MYSOFA_HRTF *hrtf);
  99. -char *mysofa_getAttribute(struct MYSOFA_ATTRIBUTE *attr, char *name);
  100. -void mysofa_tospherical(struct MYSOFA_HRTF *hrtf);
  101. -void mysofa_tocartesian(struct MYSOFA_HRTF *hrtf);
  102. -void mysofa_free(struct MYSOFA_HRTF *hrtf);
  103. +MYSOFA_EXPORT int mysofa_check(struct MYSOFA_HRTF *hrtf);
  104. +MYSOFA_EXPORT char *mysofa_getAttribute(struct MYSOFA_ATTRIBUTE *attr, char *name);
  105. +MYSOFA_EXPORT void mysofa_tospherical(struct MYSOFA_HRTF *hrtf);
  106. +MYSOFA_EXPORT void mysofa_tocartesian(struct MYSOFA_HRTF *hrtf);
  107. +MYSOFA_EXPORT void mysofa_free(struct MYSOFA_HRTF *hrtf);
  108. -struct MYSOFA_LOOKUP *mysofa_lookup_init(struct MYSOFA_HRTF *hrtf);
  109. -int mysofa_lookup(struct MYSOFA_LOOKUP *lookup, float *coordinate);
  110. -void mysofa_lookup_free(struct MYSOFA_LOOKUP *lookup);
  111. +MYSOFA_EXPORT struct MYSOFA_LOOKUP *mysofa_lookup_init(struct MYSOFA_HRTF *hrtf);
  112. +MYSOFA_EXPORT int mysofa_lookup(struct MYSOFA_LOOKUP *lookup, float *coordinate);
  113. +MYSOFA_EXPORT void mysofa_lookup_free(struct MYSOFA_LOOKUP *lookup);
  114. -struct MYSOFA_NEIGHBORHOOD *
  115. +MYSOFA_EXPORT struct MYSOFA_NEIGHBORHOOD *
  116. mysofa_neighborhood_init(struct MYSOFA_HRTF *hrtf,
  117. struct MYSOFA_LOOKUP *lookup);
  118. -struct MYSOFA_NEIGHBORHOOD *mysofa_neighborhood_init_withstepdefine(
  119. +MYSOFA_EXPORT struct MYSOFA_NEIGHBORHOOD *mysofa_neighborhood_init_withstepdefine(
  120. struct MYSOFA_HRTF *hrtf, struct MYSOFA_LOOKUP *lookup,
  121. float neighbor_angle_step, float neighbor_radius_step);
  122. -int *mysofa_neighborhood(struct MYSOFA_NEIGHBORHOOD *neighborhood, int pos);
  123. -void mysofa_neighborhood_free(struct MYSOFA_NEIGHBORHOOD *neighborhood);
  124. +MYSOFA_EXPORT int *mysofa_neighborhood(struct MYSOFA_NEIGHBORHOOD *neighborhood, int pos);
  125. +MYSOFA_EXPORT void mysofa_neighborhood_free(struct MYSOFA_NEIGHBORHOOD *neighborhood);
  126. -float *mysofa_interpolate(struct MYSOFA_HRTF *hrtf, float *cordinate,
  127. +MYSOFA_EXPORT float *mysofa_interpolate(struct MYSOFA_HRTF *hrtf, float *cordinate,
  128. int nearest, int *neighborhood, float *fir,
  129. float *delays);
  130. -int mysofa_resample(struct MYSOFA_HRTF *hrtf, float samplerate);
  131. -float mysofa_loudness(struct MYSOFA_HRTF *hrtf);
  132. -int mysofa_minphase(struct MYSOFA_HRTF *hrtf, float threshold);
  133. +MYSOFA_EXPORT int mysofa_resample(struct MYSOFA_HRTF *hrtf, float samplerate);
  134. +MYSOFA_EXPORT float mysofa_loudness(struct MYSOFA_HRTF *hrtf);
  135. +MYSOFA_EXPORT int mysofa_minphase(struct MYSOFA_HRTF *hrtf, float threshold);
  136. -struct MYSOFA_EASY *mysofa_cache_lookup(const char *filename, float samplerate);
  137. -struct MYSOFA_EASY *mysofa_cache_store(struct MYSOFA_EASY *,
  138. +MYSOFA_EXPORT struct MYSOFA_EASY *mysofa_cache_lookup(const char *filename, float samplerate);
  139. +MYSOFA_EXPORT struct MYSOFA_EASY *mysofa_cache_store(struct MYSOFA_EASY *,
  140. const char *filename, float samplerate);
  141. -void mysofa_cache_release(struct MYSOFA_EASY *);
  142. -void mysofa_cache_release_all(void);
  143. +MYSOFA_EXPORT void mysofa_cache_release(struct MYSOFA_EASY *);
  144. +MYSOFA_EXPORT void mysofa_cache_release_all(void);
  145. -void mysofa_c2s(float values[3]);
  146. -void mysofa_s2c(float values[3]);
  147. +MYSOFA_EXPORT void mysofa_c2s(float values[3]);
  148. +MYSOFA_EXPORT void mysofa_s2c(float values[3]);
  149. struct MYSOFA_EASY {
  150. struct MYSOFA_HRTF *hrtf;
  151. @@ -173,38 +174,38 @@ struct MYSOFA_EASY {
  152. float *fir;
  153. };
  154. -struct MYSOFA_EASY *mysofa_open(const char *filename, float samplerate,
  155. +MYSOFA_EXPORT struct MYSOFA_EASY *mysofa_open(const char *filename, float samplerate,
  156. int *filterlength, int *err);
  157. -struct MYSOFA_EASY *mysofa_open_no_norm(const char *filename, float samplerate,
  158. +MYSOFA_EXPORT struct MYSOFA_EASY *mysofa_open_no_norm(const char *filename, float samplerate,
  159. int *filterlength, int *err);
  160. -struct MYSOFA_EASY *mysofa_open_advanced(const char *filename, float samplerate,
  161. +MYSOFA_EXPORT struct MYSOFA_EASY *mysofa_open_advanced(const char *filename, float samplerate,
  162. int *filterlength, int *err, bool norm,
  163. float neighbor_angle_step,
  164. float neighbor_radius_step);
  165. -struct MYSOFA_EASY *mysofa_open_data(const char *data, long size,
  166. +MYSOFA_EXPORT struct MYSOFA_EASY *mysofa_open_data(const char *data, long size,
  167. float samplerate, int *filterlength,
  168. int *err);
  169. -struct MYSOFA_EASY *mysofa_open_data_no_norm(const char *data, long size,
  170. +MYSOFA_EXPORT struct MYSOFA_EASY *mysofa_open_data_no_norm(const char *data, long size,
  171. float samplerate,
  172. int *filterlength, int *err);
  173. -struct MYSOFA_EASY *mysofa_open_data_advanced(
  174. +MYSOFA_EXPORT struct MYSOFA_EASY *mysofa_open_data_advanced(
  175. const char *data, long size, float samplerate, int *filterlength, int *err,
  176. bool norm, float neighbor_angle_step, float neighbor_radius_step);
  177. -struct MYSOFA_EASY *mysofa_open_cached(const char *filename, float samplerate,
  178. +MYSOFA_EXPORT struct MYSOFA_EASY *mysofa_open_cached(const char *filename, float samplerate,
  179. int *filterlength, int *err);
  180. -void mysofa_getfilter_short(struct MYSOFA_EASY *easy, float x, float y, float z,
  181. +MYSOFA_EXPORT void mysofa_getfilter_short(struct MYSOFA_EASY *easy, float x, float y, float z,
  182. short *IRleft, short *IRright, int *delayLeft,
  183. int *delayRight);
  184. -void mysofa_getfilter_float(struct MYSOFA_EASY *easy, float x, float y, float z,
  185. +MYSOFA_EXPORT void mysofa_getfilter_float(struct MYSOFA_EASY *easy, float x, float y, float z,
  186. float *IRleft, float *IRright, float *delayLeft,
  187. float *delayRight);
  188. -void mysofa_getfilter_float_nointerp(struct MYSOFA_EASY *easy, float x, float y,
  189. +MYSOFA_EXPORT void mysofa_getfilter_float_nointerp(struct MYSOFA_EASY *easy, float x, float y,
  190. float z, float *IRleft, float *IRright,
  191. float *delayLeft, float *delayRight);
  192. -void mysofa_close(struct MYSOFA_EASY *easy);
  193. -void mysofa_close_cached(struct MYSOFA_EASY *easy);
  194. +MYSOFA_EXPORT void mysofa_close(struct MYSOFA_EASY *easy);
  195. +MYSOFA_EXPORT void mysofa_close_cached(struct MYSOFA_EASY *easy);
  196. -void mysofa_getversion(int *major, int *minor, int *patch);
  197. +MYSOFA_EXPORT void mysofa_getversion(int *major, int *minor, int *patch);
  198. #ifdef __cplusplus
  199. }
  200. diff --git a/src/hrtf/portable_endian.h b/src/hrtf/portable_endian.h
  201. index d1e76f5..5fb4b55 100644
  202. --- a/src/hrtf/portable_endian.h
  203. +++ b/src/hrtf/portable_endian.h
  204. @@ -13,7 +13,7 @@
  205. #endif
  206. -#if defined(__linux__) || defined(__CYGWIN__)
  207. +#if defined(__linux__) || defined(__CYGWIN__) || defined(__illumos__) || defined(__GNU__) || defined(__linux) || defined(linux) || defined(__gnu_linux__)
  208. # include <endian.h>
  209. @@ -41,23 +41,10 @@
  210. # define __LITTLE_ENDIAN LITTLE_ENDIAN
  211. # define __PDP_ENDIAN PDP_ENDIAN
  212. -#elif defined(__OpenBSD__)
  213. +#elif defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
  214. # include <sys/endian.h>
  215. -#elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
  216. -
  217. -# include <sys/endian.h>
  218. -
  219. -# define be16toh(x) betoh16(x)
  220. -# define le16toh(x) letoh16(x)
  221. -
  222. -# define be32toh(x) betoh32(x)
  223. -# define le32toh(x) letoh32(x)
  224. -
  225. -# define be64toh(x) betoh64(x)
  226. -# define le64toh(x) letoh64(x)
  227. -
  228. #elif defined(__WINDOWS__)
  229. # include <windows.h>