2024-12-05 03:26 AM
Hi,
I'm struggling to do something that should apparently be relatively simple. I want to import a different touchgfx.props file to the .vcxproject depending on a variable. Now, you might wonder why I want to do that, so let me explain quickly the reason before jumping to my problem. I want my touchgfx project to support two different screen resolutions, which touchgfx designer doesn't allow by default. My idea is therefore to have two different touchgfx designer projects configured each with a different resolution and with different 'asset folders' that compile to the same VS project.
So far so good, I've managed to do that and everything works fine. Now, I'd like to add a precompiler definition to the project based on which resolution I use cuz I might need to do some specific things on the child views based on the resolutions.
I figured some 'precompiler definitions' are imported from a file called touchgfx-sdl2.props located in the /generated/simulator/msvs file, and that the .vcxproject allows conditions, therefore I thought it would be quite easy, as I could just create two different .prop files with a different precompiler definition and import one or the other based on a variable… And here comes my problem… I don't know how to import this variable to the .vcx project?
I thought at first the easiest would just be to create and set an environment variable in a batch file but for some reason, .vcxproject doesn't recognize environment variables? (even though VS documentation says it does). None of those works:
<Import Project="..\..\generated\simulator\msvs\touchgfx_sdl2.props" Condition="exists('$(MY_ENVIRONMENT_VAR)')"/>
<Import Project="..\..\generated\simulator\msvs\touchgfx_sdl2-2.props" Condition="'$(MY_ENVIRONMENT_VARIABLE)'=='true'"/>
And yes, the variable exists and is set correctly… So it kind of forced me to consider another approach… Which is passing directly an argument to the msbuild command with /:p and just use it in the .vxcproject. But where is the msbuild command actually called?
I'm not too familiar with makefiles nor with build tools and I'm getting a bit lost here as I haven't found this command called once… But in order to build the VS application, this command must be called somewhere right?
Touchgfx allows to pass a post generate command and a post generate target command. What is the difference between the two? In which order are they called?
The default post generate command is this one:
touchgfx update_project --project-file=simulator/msvs/Application.vcxproj
Why can't I pass an argument to this command? If I remove the command, my project won't update obviously, so I can't even call a.bat file to set the environment variable as I wanted to… Touchgfx_update_project is a command that's only understood by the touchgfx designer, right?
Touchgfx documentation on this is really scarce and not well explained tbh. If I remove the post generate target command (which is by default touchgfx update_project, which seems to me so similar to the post generate command), what happens?
Also, as of now, I've only been talking about VS but I'd like to do something similar with the IAR project and I don't even know where to start with this one…
Thanks in advance for any help. Hope I've made myself clear!
2024-12-08 11:26 PM
No one in the touchgfx team can help me?
2024-12-10 12:40 AM - edited 2024-12-10 12:40 AM
Hello @GMeur ,
You should be able to do it with your env var solution, are sure your environment variable is set correctly ? I was able to use env var in vcxproj. Also your solution works only if you build/run your project from VS. In the designer, it's done via gcc so you'll have to modify other files.
* post generate command = after generation for the simulator
* post generate target command = after generation for a board
The command touchgfx update_project --project-file=simulator/msvs/Application.vcxproj is internal so touchgfx, so it's not supposed have additional args
Update project is just one command, which is used by post generate target command. It updates the application.vcxproj according to your modification. But for some more complex project you can do pipes or chain custom commands.
for example you could do : touchgfx update_project --project-file=simulator/msvs/Application.vcxproj && myscript.bat
Best regards,
2024-12-10 06:11 AM
Thanks for your answer!
Can you show me the lines you added in the .vcxproj to do it then? I'm sure my environment variable exists and is set well because I can read it through the cmd.
Yeah, it's fine as I only build and run my project through VS.
Oh wow, I didn't know you could chain commands like that. It's exactly what I was looking for. Thanks.
Would be great if the documentation on this could be augmented because I couldn't find much about this in the doc.
Regards,
Guillaume.
2024-12-12 02:13 AM
Hi @GMeur ,
You are welcome, I just add it to all the env var, but maybe if you just created it restart VS,
And in vcxproject file :
I hope it helps,