Add exporting compile_commands.json file

* Add an option in scons script to export compile_commands.json
  file to support development using language server.
* Add .cache directory to the git ignore list. It is normally
  used by clangd as the local cache.

Resolves: COMPMID-5940
Signed-off-by: Viet-Hoa Do <viet-hoa.do@arm.com>
Change-Id: I8c2a1ac85942d34ada22adea3e7de2baf2189eb2
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/9258
Benchmark: Arm Jenkins <bsgcomp@arm.com>
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Jakub Sujak <jakub.sujak@arm.com>
Comments-Addressed: Arm Jenkins <bsgcomp@arm.com>
diff --git a/SConstruct b/SConstruct
index ca53246..2e20931 100644
--- a/SConstruct
+++ b/SConstruct
@@ -140,6 +140,9 @@
     ("build_config", "Operator/Data-type/Data-layout configuration to use for tailored ComputeLibrary builds. Can be a JSON file or a JSON formatted string", "")
 )
 
+if version_at_least(SCons.__version__, "4.0"):
+    vars.Add(BoolVariable("export_compile_commands", "Export compile_commands.json file.", False))
+
 
 env = Environment(variables=vars, ENV = os.environ)
 
@@ -181,6 +184,11 @@
 
 Help(vars.GenerateHelpText(env))
 
+# Export compile_commands.json file
+if env.get("export_compile_commands", False):
+    env.Tool("compilation_db")
+    env.CompilationDatabase("%s/compile_commands.json" % build_path)
+
 if 'armv7a' in env['arch'] and env['os'] == 'android':
     print("WARNING: armv7a on Android is no longer maintained")