-
-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include global UserSettings.h file #15
Comments
To enable this function you could use arduino/arduino-builder#15
I think I have a commit which successfully allows macros (
Followers of the DRY principle can take advantage of the property expansion method in arduino-builder:
A global
I'm not ready to submit a pull request since I have not added any unit tests but I would appreciate feedback and testing to know if this is useful. The commit can be found at stevemarple@a5fc12b |
The idea of having a specially-named .h file in the sketch be included during compilation of the core and libraries is a long-standing one: https://code.google.com/p/arduino/issues/detail?id=27 I've some concerns about opening this possibility to developers, I think that @damellis has very well explained the reasons here:
In 4 years I've seen cases where this rationale applies for true, the most significant are:
To conclude, is this feature really worth it? the things that are absolutely not possible without #defines and #ifdefs are really compelling for end users? |
I agree with all these reasons and experience shows that better/easier to maintain solutions have been found without relying on #define. |
Nah. I really do need this file inclusion, not only a library.properties. I need a setting which can be added to the sketch as additional .h file tab. Its not just about enabling debug. If i'd want this I can just put it in the librarys header itself. Its about the time after you release stuff and the user wants to customize stuff. You dont need to tell him which source file he needs to find and what to edit. And the next time he needs a different setting and needs to search it again. This way we can have settings per sketch. I suggest two options at the same time:
You could also do a separate CoreSettings.h (which is included by the Arduino.h file) and a LibrarySettings.h file (which may be included by the library). A Wrapper for including both could be to just use Having 2 separate Settings files would be required for deactivating the USB-Core (how it is right now). In the CoreSettings.h you just |
I agree that in some circumstances There are many useful contributed libraries which require users to modify the library header files to comment/uncomment the appropriate The effect of inserting a Whilst I accept you must consider the environment for novice users (that was me a few years ago) the Arduino ecosystem has grown. As the existence of the Arduino at Heart program shows some of that growth is towards more advanced/industrial users. Please consider their needs too. Would a new pull request which only read build_options.txt when |
Am I think we are talking about two different features here.
I think both cases are really helpful. I really like your idea, but you should probably discuss this in the PR you opened. I can imagine things like: preserving some registers from being used for very special libraries etc. If this makes sense in all cases is out of question here. However I'd rather put those compiler flags in the libraries.properties file. The dot_a_linkage setting is placed there as well, and why do we need another file? Also I think an option like |
@NicoHood Pull request #29 is a generalisation of this feature request. It enables a global config file to be included with gcc's |
I was not aware that you can add Is there a way to point to the sketch folder directly? Is there a way to ignore the include if no file was found? I am still not 100% if this solves the whole issue, but sure it enables us a wide range of new possibilities. And finally how can I test this build (your PR)? |
@NicoHood Instructions are in my first post in this thread, including how to reference the sketch source folder. You need a very recent version of the Arduino IDE (nightly build or built from the latest sources). Replace the |
In the end I worked round this by defining my own |
really could do with this feature, injecting #defines into a library at compile time allow me to write code that is stripped back to optimal, saving space and allowing for things like endianess without switch/if statments based on variables passed at 'begin' (extra code and kills performance on every access) and this sooo nearly works .... I notice from looking at building other simple project that the environment is pulling ALL files into the temp area including the copies of the libraries and the sketch but there is a preprocessing step that fails on the project first build (it seems to build a library in place at the library path first) .... so I did the following wrote my own library put it in the proper place
it seems to me ... if the environment is going to cache the files in temp anyway ... why does it not do that step FIRST and pre-compile the library with that copy there ? since its going to be doing everything else in there until I close the envirnment. If the copy was made first then everything would work as people desire |
Since IDE does not support the concept of PROJECTS nor the definition of environment variables. That would be the least to do. Most IDE has a configuration file to specify this type of configuration. |
@ricardojlrufino It might be a better idea to keep the name "Project" out of Arduino, and try to achieve the goals by tweaking the existing sketch format. For the For other IDE settings, I would prefer |
Everyone recently commenting on this issue should re-read Cristian's comment posted on Oct 5, 2015. |
here is that post. That solution would be fine had it been merged. |
When avr-gcc 5.0 arrives in Arduino land then the __has_include macro will be available. That would mean that a UserSettings.h optionally being provided and with no impact if not provided should be as simple as adding
For alternative core developers it will be trivially simple to add this to their core, but without the Arduino core itself doing so there risks to be a proliferation of differing standards " Indeed, if even the sketch source folder is available to the GCC preprocessor, it would probably be possible to construct include file paths in macros with some magic somehow, the quote marks necessary for My interest is mostly in tiny processors where every byte counts. Currently I'm writing a library for sleep management which for some cases uses the WDT, but not all use-cases employ it, for example sleeping "forever" doesn't need the WDT, sleeping "deeply" does, sleeping "idle" doesn't necessarily. The compiler has no way to optimize out an unused ISR like the WDT, so even if the library-user never calls |
Slightly off-topic, but there is a trick with using a .a archive file for linking, which is used by HardwareSerial. See this comment (which only applies for files linked through .a files, but you can specify some property in |
@sleemanj Core developers can add the desired functionality now, no need for avr-gcc 5.0. See #15 (comment) and https://github.com/stevemarple/Calunium/blob/master/software/arduino-1.6/calunium/avr/boards.txt |
@stevemarple doesn't that (-include) cause an error if the file does not exist? It does in my avr-gcc (4.8.2)
With __has_include no error would happen if the file doesn't exist. Edit: I see you have set that up to only be used if you select the appropriate menu option, in which case, yeah you could do that certainly, accepting that if the user picks that option and attempts to compile without actually having the required file created then they will get an error. |
Again, everyone here should re-read Cristian's comment near the top of this issue, written Oct 5, 2015. Arduino has historically rejected this idea (in a variety of forms) not based on technical issues with its implementation, but based on the massive effective expansion of the API it would have, and the anticipated long-term effect that could have on the Arduino ecosystem. Focusing on the technical implementation details is missing the "big picture". |
Which is, that this is probably going to happen anyway (and as above with @stevemarple 's core already is) with or without Arduino officially endorsing it with a one-true-way (of having compile-time configuration passed into cores and libraries). I think it would be better with a one-true-way personally, rather than having each core doing their own thing. This ticket is still open, so right now it has not been rejected flatly as WONTFIX, I think it's reasonable to continue discussion at least until it is, and part of that is technical detail. |
Thanks to @matthijskooijman who pointed out the possibility in arduino/arduino-builder#15 (comment) With LTO turned on the ATTiny13 will now do a simple forever sleep in about 30 bytes.
So finally is there any way to do this ? |
@EtienneGameSeed it looks like you are missing a minus sign. |
Thanks, sorry it's a typo error that was in my message (I corrected it). |
Which board/IDE version/builder version are you targeting? I just tested that flag and it works as intended, but it also overrides the existing field (eg, if |
I'm using IDE 1.8.7 and TeensyDuino 1.44. Here's the corrected file : platform.txt |
Closing this as the discussion about the metadata (or configuration) file is going to take place in arduino-cli repo and in the mailing list |
can you leave the link here? |
@stevemarple , that sounds like a good idea! I've tried this for teensy 3.2 but no success sadly. I added the following lines to the
Then I added the file However when I compile via the Arduino IDE (version 2) I get an error, originating from the library file Any idea what could be going wrong? Am I supposed to select something from a menu maybe? If so, what menu? N.B. I realise this issue is closed, but wasn't sure where else to post this question. |
If we could have a global UserSettings.h file which is included at the top of the Arduino.h file we could:
This requires every file to see the UserSettings.h file, it needs to be included in the Arduino.h file and it needs to be placed in the .ino folder, and if not it should be created as an empty file. Also make sure if you delete it, an empty dummy will be added again.
Imported from: arduino/Arduino#3757
Also fixes (and maybe more): arduino/Arduino#3717 arduino/Arduino#3635
The text was updated successfully, but these errors were encountered: