meson.build 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # Copyright © 2020 Dylan Baker
  2. # This software is provided 'as-is', without any express or implied
  3. # warranty. In no event will the authors be held liable for any
  4. # damages arising from the use of this software.
  5. # Permission is granted to anyone to use this software for any
  6. # purpose, including commercial applications, and to alter it and
  7. # redistribute it freely, subject to the following restrictions:
  8. # 1. The origin of this software must not be misrepresented; you must
  9. # not claim that you wrote the original software. If you use this
  10. # software in a product, an acknowledgment in the product documentation
  11. # would be appreciated but is not required.
  12. # 2. Altered source versions must be plainly marked as such, and
  13. # must not be misrepresented as being the original software.
  14. # 3. This notice may not be removed or altered from any source
  15. # distribution.
  16. project(
  17. 'tinyxml2',
  18. ['cpp'],
  19. version : '9.0.0',
  20. meson_version : '>= 0.49.0',
  21. )
  22. cpp = meson.get_compiler('cpp')
  23. tinyxml_extra_args = []
  24. if cpp.get_argument_syntax() == 'msvc'
  25. tinyxml_extra_args += '-D_CRT_SECURE_NO_WARNINGS'
  26. endif
  27. if get_option('default_library') == 'shared'
  28. tinyxml_extra_args += '-DTINYXML2_EXPORT'
  29. endif
  30. if get_option('debug')
  31. tinyxml_extra_args += '-DTINYXML2_DEBUG'
  32. endif
  33. lib_tinyxml2 = library(
  34. 'tinyxml2',
  35. ['tinyxml2.cpp'],
  36. cpp_args : tinyxml_extra_args,
  37. gnu_symbol_visibility : 'hidden',
  38. version : meson.project_version(),
  39. install : true,
  40. )
  41. dep_tinyxml2 = declare_dependency(
  42. link_with : lib_tinyxml2,
  43. include_directories : include_directories('.'),
  44. )
  45. # This is the new way to set dependencies, but let's not break users of older
  46. # versions of meson
  47. if meson.version().version_compare('>= 0.54.0')
  48. meson.override_dependency('tinyxml2', dep_tinyxml2)
  49. endif
  50. if get_option('tests')
  51. # Try to find a copy command. If this is windows we probably don't have cp,
  52. # but if this is msys then we do, so make cp not required in that case, and
  53. # try Xcopy if cp isn't found
  54. prog_cp = find_program('cp', required : build_machine.system() != 'windows')
  55. command = ['-r']
  56. if not prog_cp.found()
  57. prog_cp = find_program('Xcopy')
  58. command = ['/E', '/I']
  59. endif
  60. # Copy the test resources into the build dir
  61. run_command(
  62. prog_cp,
  63. [
  64. command,
  65. meson.current_source_dir() / 'resources',
  66. meson.current_build_dir(),
  67. ],
  68. )
  69. test(
  70. 'xmltest',
  71. executable(
  72. 'xmltest',
  73. ['xmltest.cpp'],
  74. link_with : [lib_tinyxml2],
  75. ),
  76. workdir : meson.current_build_dir(),
  77. )
  78. endif
  79. install_headers('tinyxml2.h')
  80. # This is better than using the .in because meson tracks dependencies
  81. # internally, and will generate a more accurate pkg-config file
  82. pkg = import('pkgconfig')
  83. pkg.generate(
  84. lib_tinyxml2,
  85. description : 'simple, small, C++ XML parser',
  86. )