meson.build 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # SPDX-FileCopyrightText: 2021 Andrea Pappacoda
  2. #
  3. # SPDX-License-Identifier: MIT
  4. gtest_dep = dependency('gtest', main: true)
  5. openssl = find_program('openssl')
  6. test_conf = files('test.conf')
  7. key_pem = custom_target(
  8. 'key_pem',
  9. output: 'key.pem',
  10. command: [openssl, 'genrsa', '-out', '@OUTPUT@', '2048']
  11. )
  12. temp_req = custom_target(
  13. 'temp_req',
  14. input: key_pem,
  15. output: 'temp_req',
  16. command: [openssl, 'req', '-new', '-batch', '-config', test_conf, '-key', '@INPUT@', '-out', '@OUTPUT@']
  17. )
  18. cert_pem = custom_target(
  19. 'cert_pem',
  20. input: [temp_req, key_pem],
  21. output: 'cert.pem',
  22. command: [openssl, 'x509', '-in', '@INPUT0@', '-days', '3650', '-req', '-signkey', '@INPUT1@', '-out', '@OUTPUT@']
  23. )
  24. cert2_pem = custom_target(
  25. 'cert2_pem',
  26. input: key_pem,
  27. output: 'cert2.pem',
  28. command: [openssl, 'req', '-x509', '-config', test_conf, '-key', '@INPUT@', '-sha256', '-days', '3650', '-nodes', '-out', '@OUTPUT@', '-extensions', 'SAN']
  29. )
  30. cert_encrypted_pem = custom_target(
  31. 'cert_encrypted_pem',
  32. input: key_encrypted_pem,
  33. output: 'cert_encrypted.pem',
  34. command: [openssl, 'req', '-x509', '-config', test_conf, '-key', '@INPUT@', '-sha256', '-days', '3650', '-nodes', '-out', '@OUTPUT@', '-extensions', 'SAN']
  35. )
  36. rootca_key_pem = custom_target(
  37. 'rootca_key_pem',
  38. output: 'rootCA.key.pem',
  39. command: [openssl, 'genrsa', '-out', '@OUTPUT@', '2048']
  40. )
  41. rootca_cert_pem = custom_target(
  42. 'rootca_cert_pem',
  43. input: rootca_key_pem,
  44. output: 'rootCA.cert.pem',
  45. command: [openssl, 'req', '-x509', '-new', '-batch', '-config', files('test.rootCA.conf'), '-key', '@INPUT@', '-days', '1024', '-out', '@OUTPUT@']
  46. )
  47. client_key_pem = custom_target(
  48. 'client_key_pem',
  49. output: 'client.key.pem',
  50. command: [openssl, 'genrsa', '-out', '@OUTPUT@', '2048']
  51. )
  52. client_temp_req = custom_target(
  53. 'client_temp_req',
  54. input: client_key_pem,
  55. output: 'client_temp_req',
  56. command: [openssl, 'req', '-new', '-batch', '-config', test_conf, '-key', '@INPUT@', '-out', '@OUTPUT@']
  57. )
  58. client_cert_pem = custom_target(
  59. 'client_cert_pem',
  60. input: [client_temp_req, rootca_cert_pem, rootca_key_pem],
  61. output: 'client.cert.pem',
  62. command: [openssl, 'x509', '-in', '@INPUT0@', '-days', '370', '-req', '-CA', '@INPUT1@', '-CAkey', '@INPUT2@', '-CAcreateserial', '-out', '@OUTPUT@']
  63. )
  64. # Copy test files to the build directory
  65. configure_file(input: 'ca-bundle.crt', output: 'ca-bundle.crt', copy: true)
  66. configure_file(input: 'image.jpg', output: 'image.jpg', copy: true)
  67. subdir(join_paths('www', 'dir'))
  68. subdir(join_paths('www2', 'dir'))
  69. subdir(join_paths('www3', 'dir'))
  70. test(
  71. 'main',
  72. executable(
  73. 'main',
  74. 'test.cc',
  75. dependencies: [
  76. cpp_httplib_dep,
  77. gtest_dep
  78. ]
  79. ),
  80. depends: [
  81. key_pem,
  82. cert_pem,
  83. cert2_pem,
  84. rootca_key_pem,
  85. rootca_cert_pem,
  86. client_key_pem,
  87. client_cert_pem
  88. ],
  89. workdir: meson.current_build_dir(),
  90. timeout: 300
  91. )