common-cxxflags.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #
  2. # common-cxxflags.py
  3. # Convenience script to apply customizations to CPP flags
  4. #
  5. import pioutil
  6. if pioutil.is_pio_build():
  7. env = pioutil.env
  8. cxxflags = [
  9. # "-Wno-incompatible-pointer-types",
  10. # "-Wno-unused-const-variable",
  11. # "-Wno-maybe-uninitialized",
  12. # "-Wno-sign-compare"
  13. ]
  14. if "teensy" not in env["PIOENV"]:
  15. cxxflags += ["-Wno-register"]
  16. env.Append(CXXFLAGS=cxxflags)
  17. env.Append(CFLAGS=["-Wno-implicit-function-declaration"])
  18. #
  19. # Add CPU frequency as a compile time constant instead of a runtime variable
  20. #
  21. def add_cpu_freq():
  22. if "BOARD_F_CPU" in env:
  23. env["BUILD_FLAGS"].append("-DBOARD_F_CPU=" + env["BOARD_F_CPU"])
  24. # Useful for JTAG debugging
  25. #
  26. # It will separate release and debug build folders.
  27. # This is useful to keep two live versions: a debug version and a release version,
  28. # for flashing when upload is not done automatically by jlink/stlink.
  29. # Without this, PIO needs to recompile everything twice for any small change.
  30. if env.GetBuildType() == "debug" and env.get("UPLOAD_PROTOCOL") not in ["jlink", "stlink", "custom"]:
  31. env["BUILD_DIR"] = "$PROJECT_BUILD_DIR/$PIOENV/debug"
  32. def on_program_ready(source, target, env):
  33. import shutil
  34. shutil.copy(target[0].get_abspath(), env.subst("$PROJECT_BUILD_DIR/$PIOENV"))
  35. env.AddPostAction("$PROGPATH", on_program_ready)
  36. # On some platform, F_CPU is a runtime variable. Since it's used to convert from ns
  37. # to CPU cycles, this adds overhead preventing small delay (in the order of less than
  38. # 30 cycles) to be generated correctly. By using a compile time constant instead
  39. # the compiler will perform the computation and this overhead will be avoided
  40. add_cpu_freq()