[CMake] : Add precompiled header support with FLATBUFFERS_ENABLE_PCH (#5827)

* [CMake] : Add precompiled header support with FLATBUFFERS_ENABLE_PCH

FLATBUFFERS_ENABLE_PCH enable precompile headers support for 'flatbuffers' and 'flatc'. Default if OFF.
You need to set it to ON to make it work. 'cmake -DFLATBUFFERS_ENABLE_PCH=ON ..'
This will only work if CMake version is >= 3.16, because target_precompile_headers is used.
If CMake doesn't have target_precompile_headers, then nothing will happen.
This can speed up compilation time.
Precompiled header file for 'flatbuffers' is 'pch.h'
Precompiled header file for 'flatc' is 'flatc_pch.h'

* Enable FLATBUFFERS_ENABLE_PCH for VC 2017 and VS2019 builds

* [CMake]: Fix error in FLATBUFFERS_ENABLE_PCH description

* Add a function add_pch_to_target to avoid copy and pasting the same code like add_fsanitize_to_target
Move pch.h and flatc_pch.h from include/flatbuffers to include/flatbuffers/pch
Make flatc_pch.h depends on pch.h since it extend it
4 files changed
tree: 9963245c43d7c21da3149b5fe008387669ad3c47
  1. .appveyor/
  2. .bazelci/
  3. .github/
  4. .travis/
  5. android/
  6. CMake/
  7. conan/
  8. dart/
  9. docs/
  10. go/
  11. grpc/
  12. include/
  13. java/
  14. js/
  15. lobster/
  16. lua/
  17. net/
  18. php/
  19. python/
  20. reflection/
  21. rust/
  22. samples/
  23. snap/
  24. src/
  25. swift/
  26. tests/
  27. .clang-format
  28. .editorconfig
  29. .gitattributes
  30. .gitignore
  31. .travis.yml
  32. appveyor.yml
  33. BUILD
  34. build_defs.bzl
  35. CMakeLists.txt
  36. composer.json
  37. conanfile.py
  38. CONTRIBUTING.md
  39. LICENSE.txt
  40. package.json
  41. pom.xml
  42. readme.md
  43. WORKSPACE
readme.md

logo FlatBuffers

Build Status Build status Join the chat at https://gitter.im/google/flatbuffers Discord Chat Twitter Follow

FlatBuffers is a cross platform serialization library architected for maximum memory efficiency. It allows you to directly access serialized data without parsing/unpacking it first, while still having great forwards/backwards compatibility.

Go to our landing page to browse our documentation.

Supported operating systems

  • Windows
  • MacOS X
  • Linux
  • Android
  • And any others with a recent C++ compiler.

Supported programming languages

  • C++
  • C#
  • C
  • Dart
  • Go
  • Java
  • JavaScript
  • Lobster
  • Lua
  • PHP
  • Python
  • Rust
  • TypeScript

and more in progress...

Contribution

To contribute to this project, see CONTRIBUTING.

Licensing

Flatbuffers is licensed under the Apache License, Version 2.0. See LICENSE for the full license text.