meson.build 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. rootca_key_pem = custom_target(
  31. 'rootca_key_pem',
  32. output: 'rootCA.key.pem',
  33. command: [openssl, 'genrsa', '-out', '@OUTPUT@', '2048']
  34. )
  35. rootca_cert_pem = custom_target(
  36. 'rootca_cert_pem',
  37. input: rootca_key_pem,
  38. output: 'rootCA.cert.pem',
  39. command: [openssl, 'req', '-x509', '-new', '-batch', '-config', files('test.rootCA.conf'), '-key', '@INPUT@', '-days', '1024', '-out', '@OUTPUT@']
  40. )
  41. client_key_pem = custom_target(
  42. 'client_key_pem',
  43. output: 'client.key.pem',
  44. command: [openssl, 'genrsa', '-out', '@OUTPUT@', '2048']
  45. )
  46. client_temp_req = custom_target(
  47. 'client_temp_req',
  48. input: client_key_pem,
  49. output: 'client_temp_req',
  50. command: [openssl, 'req', '-new', '-batch', '-config', test_conf, '-key', '@INPUT@', '-out', '@OUTPUT@']
  51. )
  52. client_cert_pem = custom_target(
  53. 'client_cert_pem',
  54. input: [client_temp_req, rootca_cert_pem, rootca_key_pem],
  55. output: 'client.cert.pem',
  56. command: [openssl, 'x509', '-in', '@INPUT0@', '-days', '370', '-req', '-CA', '@INPUT1@', '-CAkey', '@INPUT2@', '-CAcreateserial', '-out', '@OUTPUT@']
  57. )
  58. # Copy test files to the build directory
  59. configure_file(input: 'ca-bundle.crt', output: 'ca-bundle.crt', copy: true)
  60. configure_file(input: 'image.jpg', output: 'image.jpg', copy: true)
  61. subdir(join_paths('www', 'dir'))
  62. subdir(join_paths('www2', 'dir'))
  63. subdir(join_paths('www3', 'dir'))
  64. test(
  65. 'main',
  66. executable(
  67. 'main',
  68. 'test.cc',
  69. dependencies: [
  70. cpp_httplib_dep,
  71. gtest_dep
  72. ]
  73. ),
  74. depends: [
  75. key_pem,
  76. cert_pem,
  77. cert2_pem,
  78. rootca_key_pem,
  79. rootca_cert_pem,
  80. client_key_pem,
  81. client_cert_pem
  82. ],
  83. workdir: meson.current_build_dir(),
  84. timeout: 300
  85. )