简体   繁体   中英

visual studio custom build step to generate headers

I have a project with headers that is normally generate as needed with command line interface. But i want to add this generation step to visual studio 2015 (toolset v141, c++) as a custom build step. So i did it and it actually works but it generates them to late. Indeed, if the files do not existe yet, it fails building the project with error "cannot include file myHeader.h".

i added the custom build step by adding project properties -> Custom Build Step -> general:

  • Command line: the command to generate header file (it works)
  • Outputs: $(ProjectDir)generated-header;%(Outputs)
  • Execute Before: PreBuildEvent

Ouputs is actually not needed as the command line generates the files and automatically place them in the rigth folder. but it does not work if i do not specify an output folder.

Execute Before might be where my probleme is. But i don't know which option to add. this one seems good yet.

EDIT something weird is that it sometimes succeed to create it before the build but if i delete them and build again. They are not generated anymore and the project does not build.

EDIT2 actually it works only if i modify the project properties as it forces to regenerate all the requirements. Otherwise, if i build as usual, it skip the custom buld step because visual studio think that it is up to date.

It seems that i solved it. I made a custom build step to generate my files but it is said here

Custom Buil Step

Custom Build Steps are included as part of the intelligence that drives incremental build using the “Additional Dependencies” and “Outputs” properties. If a file in your “Additional Dependencies” property is touched, then your Custom Build Step will be considered out of date and will build with your next build

Build Events

Nothing much changed here since VS2008. These three events (Pre-build, Pre-link, and Post-build) fire during the course of a normal build and allow you to execute arbitrary project-level commands.

I thus create a Build event and my files are now generated any time and before checking for include files.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM