How to pass AdditionalIncludeDirectories to pre-build step?

Sysprogs forums Forums VisualGDB How to pass AdditionalIncludeDirectories to pre-build step?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #26760
    UdoEberhardt
    Participant

    Hi,

    I’m running a .cmd script as pre-build step and pass a few build variables to it:

    Command: cmd.exe
    Arguments: /c pre-build.cmd "$(ToolchainDir)" "$(TargetDir)" "$(TargetFileNameWithoutExtension)" "$(ConfigurationName)" "%(AdditionalIncludeDirectories)"

    While this works fine for $(ConfigurationName) etc. it does not work for %(AdditionalIncludeDirectories). The variable does not get resolved.
    The script receives “%(AdditionalIncludeDirectories)” literally.

    How can I pass the include path specified in project properties to my script?

    Thanks,
    Udo

    #26778
    support
    Keymaster

    Hi,

    The AdditionalIncludeDirectories variable exists on the MSBuild level and is not generally passed to the VisualGDB level (to make things more complicated, it is not a global MSBuild variable, but a property of each individual ClCompile item).

    To work around it, you would need to create a custom MSBuild target, translate %(ClCompile.AdditionalIncludeDirectories) into a global variable (just placing <PropertyGroup> inside the custom target might work) and then use the <Exec> task to launch the custom tool. The rest of the variables you mentioned are available both on VisualGDB and MSBuild level, so they will work in this scenario as well.

    An easier alternative would be to create a basic property sheet defining the include directories (see the stm32.props file created by VisualGDB for embedded STM32 projects), referencing it from your project and parsing its contents from the custom tool. This will avoid complex MSBuild scripting and will still avoid having multiple redundant definitions of the include directories.

    #26832
    UdoEberhardt
    Participant

    Hi,

    Thanks for your comments. To implement your first suggestion, I roughly followed these instructions and redefined the BuildDependsOn property. This works. I can access %(ClCompile.AdditionalIncludeDirectories) and %(ClCompile.PreprocessorDefinitions) and use them in my custom prebuild target. There are still a couple of details to solve, e.g. transforming the semicolon-separated list of path items into a sequence of -I options for gcc.

    What I really want to achieve is preprocessing my linker script. I’m wondering if this wouldn’t be a nice feature for VGDB to support out of the box. I will open a separate topic to discuss this.

    Udo

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.