binding.gyp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. {
  2. 'variables': {
  3. 'vips_version': '<!(node -p "require(\'./lib/libvips\').minimumLibvipsVersion")',
  4. 'platform_and_arch': '<!(node -p "require(\'./lib/platform\')()")',
  5. 'sharp_vendor_dir': './vendor/<(vips_version)/<(platform_and_arch)'
  6. },
  7. 'targets': [{
  8. 'target_name': 'libvips-cpp',
  9. 'conditions': [
  10. ['OS == "win"', {
  11. # Build libvips C++ binding for Windows due to MSVC std library ABI changes
  12. 'type': 'shared_library',
  13. 'defines': [
  14. 'VIPS_CPLUSPLUS_EXPORTS',
  15. '_ALLOW_KEYWORD_MACROS'
  16. ],
  17. 'sources': [
  18. 'src/libvips/cplusplus/VConnection.cpp',
  19. 'src/libvips/cplusplus/VError.cpp',
  20. 'src/libvips/cplusplus/VImage.cpp',
  21. 'src/libvips/cplusplus/VInterpolate.cpp',
  22. 'src/libvips/cplusplus/VRegion.cpp'
  23. ],
  24. 'include_dirs': [
  25. '<(sharp_vendor_dir)/include',
  26. '<(sharp_vendor_dir)/include/glib-2.0',
  27. '<(sharp_vendor_dir)/lib/glib-2.0/include'
  28. ],
  29. 'link_settings': {
  30. 'library_dirs': ['<(sharp_vendor_dir)/lib'],
  31. 'libraries': [
  32. 'libvips.lib',
  33. 'libglib-2.0.lib',
  34. 'libgobject-2.0.lib'
  35. ],
  36. },
  37. 'configurations': {
  38. 'Release': {
  39. 'msvs_settings': {
  40. 'VCCLCompilerTool': {
  41. 'ExceptionHandling': 1,
  42. 'Optimization': 1,
  43. 'WholeProgramOptimization': 'true'
  44. },
  45. 'VCLibrarianTool': {
  46. 'AdditionalOptions': [
  47. '/LTCG:INCREMENTAL'
  48. ]
  49. },
  50. 'VCLinkerTool': {
  51. 'ImageHasSafeExceptionHandlers': 'false',
  52. 'OptimizeReferences': 2,
  53. 'EnableCOMDATFolding': 2,
  54. 'LinkIncremental': 1,
  55. 'AdditionalOptions': [
  56. '/LTCG:INCREMENTAL'
  57. ]
  58. }
  59. },
  60. 'msvs_disabled_warnings': [
  61. 4275
  62. ]
  63. }
  64. }
  65. }, {
  66. # Ignore this target for non-Windows
  67. 'type': 'none'
  68. }]
  69. ]
  70. }, {
  71. 'target_name': 'sharp-<(platform_and_arch)',
  72. 'defines': [
  73. 'NAPI_VERSION=7',
  74. 'NODE_ADDON_API_DISABLE_DEPRECATED',
  75. 'NODE_API_SWALLOW_UNTHROWABLE_EXCEPTIONS'
  76. ],
  77. 'dependencies': [
  78. '<!(node -p "require(\'node-addon-api\').gyp")',
  79. 'libvips-cpp'
  80. ],
  81. 'variables': {
  82. 'runtime_link%': 'shared',
  83. 'conditions': [
  84. ['OS != "win"', {
  85. 'pkg_config_path': '<!(node -p "require(\'./lib/libvips\').pkgConfigPath()")',
  86. 'use_global_libvips': '<!(node -p "Boolean(require(\'./lib/libvips\').useGlobalLibvips()).toString()")'
  87. }, {
  88. 'pkg_config_path': '',
  89. 'use_global_libvips': ''
  90. }]
  91. ]
  92. },
  93. 'sources': [
  94. 'src/common.cc',
  95. 'src/metadata.cc',
  96. 'src/stats.cc',
  97. 'src/operations.cc',
  98. 'src/pipeline.cc',
  99. 'src/utilities.cc',
  100. 'src/sharp.cc'
  101. ],
  102. 'include_dirs': [
  103. '<!(node -p "require(\'node-addon-api\').include_dir")',
  104. ],
  105. 'conditions': [
  106. ['use_global_libvips == "true"', {
  107. # Use pkg-config for include and lib
  108. 'include_dirs': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --cflags-only-I vips-cpp vips glib-2.0 | sed s\/-I//g)'],
  109. 'conditions': [
  110. ['runtime_link == "static"', {
  111. 'libraries': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --libs --static vips-cpp)']
  112. }, {
  113. 'libraries': ['<!@(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --libs vips-cpp)']
  114. }],
  115. ['OS == "linux"', {
  116. 'defines': [
  117. # Inspect libvips-cpp.so to determine which C++11 ABI version was used and set _GLIBCXX_USE_CXX11_ABI accordingly. This is quite horrible.
  118. '_GLIBCXX_USE_CXX11_ABI=<!(if readelf -Ws "$(PKG_CONFIG_PATH="<(pkg_config_path)" pkg-config --variable libdir vips-cpp)/libvips-cpp.so" | c++filt | grep -qF __cxx11;then echo "1";else echo "0";fi)'
  119. ]
  120. }]
  121. ]
  122. }, {
  123. # Use pre-built libvips stored locally within node_modules
  124. 'include_dirs': [
  125. '<(sharp_vendor_dir)/include',
  126. '<(sharp_vendor_dir)/include/glib-2.0',
  127. '<(sharp_vendor_dir)/lib/glib-2.0/include'
  128. ],
  129. 'conditions': [
  130. ['OS == "win"', {
  131. 'defines': [
  132. '_ALLOW_KEYWORD_MACROS',
  133. '_FILE_OFFSET_BITS=64'
  134. ],
  135. 'link_settings': {
  136. 'library_dirs': ['<(sharp_vendor_dir)/lib'],
  137. 'libraries': [
  138. 'libvips.lib',
  139. 'libglib-2.0.lib',
  140. 'libgobject-2.0.lib'
  141. ]
  142. }
  143. }],
  144. ['OS == "mac"', {
  145. 'link_settings': {
  146. 'library_dirs': ['../<(sharp_vendor_dir)/lib'],
  147. 'libraries': [
  148. 'libvips-cpp.42.dylib'
  149. ]
  150. },
  151. 'xcode_settings': {
  152. 'OTHER_LDFLAGS': [
  153. # Ensure runtime linking is relative to sharp.node
  154. '-Wl,-rpath,\'@loader_path/../../<(sharp_vendor_dir)/lib\''
  155. ]
  156. }
  157. }],
  158. ['OS == "linux"', {
  159. 'defines': [
  160. '_GLIBCXX_USE_CXX11_ABI=1'
  161. ],
  162. 'link_settings': {
  163. 'library_dirs': ['../<(sharp_vendor_dir)/lib'],
  164. 'libraries': [
  165. '-l:libvips-cpp.so.42'
  166. ],
  167. 'ldflags': [
  168. # Ensure runtime linking is relative to sharp.node
  169. '-Wl,-s -Wl,--disable-new-dtags -Wl,-rpath=\'$$ORIGIN/../../<(sharp_vendor_dir)/lib\''
  170. ]
  171. }
  172. }]
  173. ]
  174. }]
  175. ],
  176. 'cflags_cc': [
  177. '-std=c++0x',
  178. '-fexceptions',
  179. '-Wall',
  180. '-Os'
  181. ],
  182. 'xcode_settings': {
  183. 'CLANG_CXX_LANGUAGE_STANDARD': 'c++11',
  184. 'MACOSX_DEPLOYMENT_TARGET': '10.13',
  185. 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
  186. 'GCC_ENABLE_CPP_RTTI': 'YES',
  187. 'OTHER_CPLUSPLUSFLAGS': [
  188. '-fexceptions',
  189. '-Wall',
  190. '-Oz'
  191. ]
  192. },
  193. 'configurations': {
  194. 'Release': {
  195. 'conditions': [
  196. ['OS == "linux"', {
  197. 'cflags_cc': [
  198. '-Wno-cast-function-type'
  199. ]
  200. }],
  201. ['target_arch == "arm"', {
  202. 'cflags_cc': [
  203. '-Wno-psabi'
  204. ]
  205. }],
  206. ['OS == "win"', {
  207. 'msvs_settings': {
  208. 'VCCLCompilerTool': {
  209. 'ExceptionHandling': 1,
  210. 'Optimization': 1,
  211. 'WholeProgramOptimization': 'true'
  212. },
  213. 'VCLibrarianTool': {
  214. 'AdditionalOptions': [
  215. '/LTCG:INCREMENTAL'
  216. ]
  217. },
  218. 'VCLinkerTool': {
  219. 'ImageHasSafeExceptionHandlers': 'false',
  220. 'OptimizeReferences': 2,
  221. 'EnableCOMDATFolding': 2,
  222. 'LinkIncremental': 1,
  223. 'AdditionalOptions': [
  224. '/LTCG:INCREMENTAL'
  225. ]
  226. }
  227. },
  228. 'msvs_disabled_warnings': [
  229. 4275
  230. ]
  231. }]
  232. ]
  233. }
  234. },
  235. }]
  236. }