From 40d277e4a4c6d9717b0554e45e8f12bb66bf7f7a Mon Sep 17 00:00:00 2001 From: Chris Copeland Date: Fri, 5 Jul 2024 15:55:40 -0700 Subject: [PATCH] add option to generate compile_commands.json --- SConstruct | 65 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/SConstruct b/SConstruct index d69ce29..4ba4529 100644 --- a/SConstruct +++ b/SConstruct @@ -159,16 +159,27 @@ AddOption( help="enable sanitizers on the host target", ) +AddOption( + "--compilation-db", + dest="compilation_db", + default=False, + action="store_true", + help="generate compile_commands.json", +) + +env = Environment(tools=["cc", "link", "ar"]) + if platform.system() == "Windows": - env = Environment(tools=["cc", "c++", "link", "ar"]) env["ENV"]["PATH"] = os.environ["PATH"] -else: - env = Environment() # for color terminal output when available if "TERM" in os.environ: env["ENV"]["TERM"] = os.environ["TERM"] +if GetOption("compilation_db"): + env.Tool("compilation_db") + env.CompilationDatabase() + def test_stamp(target, source, env): try: @@ -253,29 +264,31 @@ if "host" in targets: build_with_env("build", host_env, examples=True) - env16 = host_env.Clone() - env16.Append(CPPDEFINES={"LITH_X25519_WBITS": 16}) - build_with_env("build/16", env16) - - env32 = host_env.Clone() - env32.Append(CPPDEFINES={"LITH_X25519_WBITS": 32}) - build_with_env("build/32", env32) - - portable_asr_env = host_env.Clone() - portable_asr_env.Append(CPPDEFINES=["LITH_FORCE_PORTABLE_ASR"]) - build_with_env("build/portable_asr", portable_asr_env) - - # disable architectural optimizations - no_opt_env = host_env.Clone() - no_opt_env.Append( - CPPDEFINES={ - "LITH_LITTLE_ENDIAN": 0, - "LITH_BIG_ENDIAN": 0, - "LITH_SPONGE_WORDS": 0, - "LITH_VECTORIZE": 0, - } - ) - build_with_env("build/no_opt", no_opt_env) + # Disable other variants when building the compilation_db. + if not GetOption("compilation_db"): + env16 = host_env.Clone() + env16.Append(CPPDEFINES={"LITH_X25519_WBITS": 16}) + build_with_env("build/16", env16) + + env32 = host_env.Clone() + env32.Append(CPPDEFINES={"LITH_X25519_WBITS": 32}) + build_with_env("build/32", env32) + + portable_asr_env = host_env.Clone() + portable_asr_env.Append(CPPDEFINES=["LITH_FORCE_PORTABLE_ASR"]) + build_with_env("build/portable_asr", portable_asr_env) + + # disable architectural optimizations + no_opt_env = host_env.Clone() + no_opt_env.Append( + CPPDEFINES={ + "LITH_LITTLE_ENDIAN": 0, + "LITH_BIG_ENDIAN": 0, + "LITH_SPONGE_WORDS": 0, + "LITH_VECTORIZE": 0, + } + ) + build_with_env("build/no_opt", no_opt_env) if "arm-eabi" in targets: