-
-
Notifications
You must be signed in to change notification settings - Fork 617
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
Tokens in filters do not appear to work #1036
Comments
That is "correct", there is no token expansion happening for filters, and that is not something you can easily fix. The Either way... there is a very clear difference in the timing of execution of the filter function compared to anything that is happening within the filter block. Filter 'evaluates' immediately when you call it, the other functions simply store the data you give it, and are 'evaluated' during the baking process.. So, while it is not impossible to expand tokens inside of the filter function, it would be a a very expensive way of doing Tokens like |
Thanks for the explanation, I think I understand the reasons for immediately evaluating TLDRI have been able to enable some file-specific build options using Some ContextThe premake scripts I am in charge of here at my company use string concatenation, since in our current build of premake5, token support was new and relatively unknown at the time. I am having to update our premake executable and I figure now is a good time to resolve many outstanding deprecation issues. (we sill use So in the process of updating everything to use I could use string.format, but token expansion seems better since it does some checking on the token and seems to make relative paths in (all?) cases. I am cautiously optimistic about not having to manage those relative paths myself. Finally, when we first started using premake (back on the old industriousone forums), I had hacked in my own function to configure certain files to be compiled with the C++ compiler. My premake hacks are "functional" but limited in scope and not terribly flexible. I have since been able to make Basically I want to do something like this: premake.api.register { name = "src", kind = "directory", scope = "project" }
project "main"
src "src"
files { "%{prj.src}/**.cpp", "%{prj.src}/**.c" } -- this works
filter "files:%{prj.src}/module/file.c" } -- What this issue is about
compileas "C++" -- A future PR
project "plugin"
src "plugin/src"
files { "%{prj.src}/**.c" } -- works
filter { "files:%{prj.src}/dir/file.c" } -- What this issue is about
compileas "C++" -- A future PR |
I'm fairly certain you can use Also, |
** in filters do work, but for some reason that just seems like overkill. If that is going to be the case, I would argue that should be what premake generates for me by default in C++ projects. What do you think? But then I think the reverse would be true. At some point, someone is going to need a .c file to be compiled with the C compiler when used in a C++ project, so while blanket filter ** rules would fix my use case, I don't think its a one-size fits all solution. @samsinsane I'm not adding the |
The default behavior for visual studio is to depend on the file extension. So a .c file will be compiled as c and a .cpp or cxx as c++. The CompileAs tag is for file with a different extension than expected. Like, let's say .test for a file containing c code. On the makefile side, g++ can compile c code with I do not know how xcode handle all that. |
If you want all of your C files to compile as C++, you can just as easily specify I think that |
As @samsinsane said... filter "files:%{prj.src}/module/file.c" }
Since you registered The problem is maybe a little better highlighted in this example. project 'foobar'
filter { 'configurations:debug' }
src './debug'
filter { 'configurations:release' }
src './release'
filter { "files:%{prj.src}/module/file.c" } -- What this issue is about
compileas "C++"
|
So, I think if you wanted to make this work, you have to call the detoken function from here: https://github.com/premake/premake-core/blob/master/src/host/criteria_matches.c#L293 On both the 'word' and the 'filename' variables. |
Ah, that is a better example illustrating how things operate. I have edited the Tokens page with a link to your comment. I'll close this for now, since this does not appear to be a simple thing to refactor. |
If I add the following test case to
modules/vstudio/tests/cs2005/test_files.lua
:I get
I am happy to try and fix this, but I don't yet understand how/when the tokens are expanded, or if the current design of premake allows for this to happen. Any ideas?
The text was updated successfully, but these errors were encountered: