Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 2 FirstFirst 1 2
Results 26 to 37 of 37

Thread: use #if __has_include - for something like user_defs.h in Arduino sketch?

  1. #26
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    896
    Quote Originally Posted by PaulStoffregen View Post
    For 1.52, we're much too close to release to make this sort of build system change which could have unintended consequence.
    Farther in the future, maybe.
    First let's see what Arduino says on that issue. If (when) Arduino rejects it, that's not necessarily the end of story here. But it certainly is something to consider.
    To follow this up: Since Arduino didn't answer for two weeks now, I think they won't.
    Anyway, I meanwhile added a platform.local.txt to the TeensyTimerTool which fixes the issue for those who want to use project scope library settings with the Arduino IDE. (PlatformIO and VisualTeensy work out of the box). If anyone is interested, here the link to the instructions and the platform.local.txt: https://github.com/luni64/TeensyTime...scope-settings. (BTW: this would enable project scope settings for all libraries and/or the core via the _has_include feature of gcc).

  2. #27
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,874
    Does it allow to set #defines like SERIAL1_TX_BUFFER_SIZE or Audiosamplerate? And to set the optimization level and warnings or other compiler settings? F_BUS or F_CPU?

    If yes, that would be easier than my way:

    HOWTO: Store Project Settings
    Last edited by Frank B; 05-19-2020 at 05:55 PM.

  3. #28
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    896
    There is no magic in it, it just adds the sketch folder to the include search path so that you can use the _has_include feature to read any optional user header file from within libraries. Works nicely for settings (#defines, consts etc) like shown in #2. Regarding compiler flags: I doubt that one could override compiler flags by including a header from a lib. Never tried...

    I'll try to add your 'defs.h' solution to platform.local.txt later and see how that works out.

  4. #29
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,874
    Basically the same as yours - it just does not use "-I" but "@" instead.

    you need to add this:
    Code:
    recipe.hooks.sketch.prebuild.1.pattern.windows=cmd /c if not exist "{build.path}\sketch\defs.h" "echo.>{build.path}\sketch\defs.h"
    recipe.hooks.sketch.prebuild.1.pattern.linux=bash -c "[ -f {build.path}/sketch/defs.h ] || touch {build.path}/sketch/defs.h"
    #recipe.hooks.sketch.prebuild.1.pattern.macosx=bash -c "[ -f {build.path}/sketch/defs.h ] || touch {build.path}/sketch/defs.h"
    and this to the commandlines:
    "@{build.path}/sketch/defs.h"

  5. #30
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    896
    What is the @ doing, never saw that as a parameter to the command line?

  6. #31
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,874
    Basically the same as your I - but it allows to put the GCC Comandlineparameters there. Maybe you can add a -I in the file, too.

    But it complains if the file is not there - so that
    if not exist "{build.path}\sketch\defs.h" "echo.>{build.path}\sketch\defs.h"
    is needed. This creates the file(empty) on the fly, if it is not there.

  7. #32
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    896
    Found some documentation about the @filename parameter and gave it a try (didn't do the copying stuff for the test). Interesting method indeed, didn't know of the @parameter so far.

    All in all it works like advertised. Here a few quick observations:

    • The file obviously can have compiler flags only, so no consts, no constexpr etc, just plain -DSOMETHING. This is of course sufficient in principle but somehow tedious for large library configurations. (here a user config example i use)
    • Changes in the file do not trigger a recompilation so that might be confusing. One needs to do a clean build (do you know a reliable way to trigger that in the Arduino IDE?) after each change to the file
    • You can of course add some -ImyHeader.h but the compiler will only search for it in the include path. Since Arduino compiles from its temp folder you would need to somehow get this info (path to temp) into your defs.h. Seems to be difficult
    • If you want to use this mechanism from more than one library you need to tell users to combine both settings into one file. Not a big deal, but it might get messy if both libraries want to use the same #defines for settings. - Edit: but this will be a mess anyway, with or without defs.h :-)
    • Beginners might get a bit confused if their settings from the Arduino IDE get overridden by that file?
    • Some of the compiler flags (e.g. LTO) have dependencies, so you need to make sure to set that stuff correctly.


    Of course it is intriguing to set compiler flags like USB type etc on project scope but this is a very Arduino IDE specific issue. (Other build systems store those settings per project anyway).

    -> All in all, for my purposes the simple adding of the sketch folder to the include search path seems to be more convenient and easier to use. But this is only my personal need, others will have other needs...

  8. #33
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,814
    Quote Originally Posted by luni View Post
    To follow this up: Since Arduino didn't answer for two weeks now, I think they won't.
    Not surprising, since Arduino has consistently rejected this proposal every time someone brings it up. And believe me, it has indeed come up over and over throughout Arduino's long history.

    Occasionally Cristian Maglie (who for years was Arduino's main technical lead, though now that position might be held by Dario Pennisi) has taken the time to explain Arduino's position on this matter. The response has always been the same, never a gracious "thank you for explaining", always an argument and refusal to accept Arduino's answer. There seems to be sometime special and unique about this proposal (and also printf proposals) that bring out this refusal to accept "no" as a valid answer. So when they don't write any answer for you, please understand their silence may be because they are very busy or distracted by the pandemic, but the many times they have answered before only to get an argument probably also play a factor.

  9. #34
    Senior Member
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    896
    Quote Originally Posted by PaulStoffregen View Post
    Not surprising, since Arduino has consistently rejected this proposal every time someone brings it up. And believe me, it has indeed come up over and over throughout Arduino's long history.

    Occasionally Cristian Maglie (who for years was Arduino's main technical lead, though now that position might be held by Dario Pennisi) has taken the time to explain Arduino's position on this matter. The response has always been the same, never a gracious "thank you for explaining", always an argument and refusal to accept Arduino's answer. There seems to be sometime special and unique about this proposal (and also printf proposals) that bring out this refusal to accept "no" as a valid answer. So when they don't write any answer for you, please understand is may be because they are very busy or distracted by the pandemic, but the many times they have answered before only to get an argument probably also play a factor.
    No problem at all. The workaround with platform.local.txt (see above) does the trick for now. Would be great to have that in the teensyduino platform.txt some time but copying that platform.local.txt file to the architecture folder is not a big deal if you need project scope settings.

  10. #35
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,874
    I still don't know a valid reason to deny it.
    Can someone point me, give me a link to an answer other than a simple "no"?

    As all other IDEs (i.e. platformio etc..) support this, Arduino will have to support this one day anyway. Users don't like it.
    And -speaking for mw - to this day have not read any valid Argument against it. No, not any argument.
    Maybe I've missed it. So, please, a link would be great.

    To say Teensyduino will not do it because Arduino does not do it..is.. not valid, too. With the same reason you have to ask yourself why it has all the changes to Arduino.
    Last edited by Frank B; 05-19-2020 at 09:27 PM.

  11. #36
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,874
    An no: A simple "no" is NOT a valid answer. You can give that answer to employees . Not to users. To the guys who pay your business (Speaking to Arduino, here. To Massimo, who told me years ago the IDE will become much better. Nothing worth to mention happened)

  12. #37
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany NRW
    Posts
    6,874
    I always can accept a "no".
    If I know the reason.

    Yes this is just a Hobby. Not more. So Arduino should do everything not to frustate their users.
    If their project does not compile or work because they used settings in the IDE they do not remember they are not happy. Even more if they have to patch files in the cores. To set Serial Buffer sizes or other most simple, basic things.

    Done.

    I imagine..what would be If I had to patch the Firmware of my Nikon cam to be able to take pictures .. or if it would'nt rember its settings....(my other hobby, fotography) I'd had it thrown it away a long time ago.

    Lol, or if my TV would forget the stations each time i switch it off...
    Last edited by Frank B; 05-19-2020 at 10:15 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •