I have a custom build rule on a data file which generates a header file. The custom build rule works fine (runs when the data is changed and does not run when it is not, as I would expect it to).
However, this generated header file is included by a .cpp file which is compiled using the default C++ compiler. When the header is generated and there are no changes in the .cpp itself, the build system will not compile it. I have to build twice, once to generate the header file and then once more for the build system to notice and rebuild the .cpp as well (the generated header has the current date/time so there are no problems there, it just seems that Visual Studio makes all the checks before starting the build).
Not a major issue but it gets annoying after a while. It is also error-prone. Is there a way to either expedite the custom build rule so that it would run before Visual Studio checks the dependences of the .cpp files or maybe to run the build twice? There may be several files using this custom build rule so using a pre-build step to build them all would get messy.
I'm using VS 2008 if that makes any difference. The custom build rule has the "Outputs" field correctly filled in so it has the information about the files the custom build generates.
Related
I've been trying to find a solution to my question using several methods, however with no luck at all.
The problem I have is that I want my Visual Studio 2015 C++ project (.vcxproj) to automatically include auto generated cpp files (from prebuild event) in the compilation process.
So far the main suggestion I found is to add files to my project that match the names of the auto generated files. However, this is not a scalable/reliable solution because new files can be generated depending on the input, which means I have to manually add newly generated files.
I've tried using MSBUILD targets based on the answer to this question, however that does not appear to work.
Is there any possible way to auto generate CPPs and have the project compile them without having to add them to the project?
I created a project in VS2013 that generates C++ source files, and I want it to also compile the generated files to a static-lib without having to add the generated files to the project.
Ideally I want something like a custom build command that compiles everything that resides in the directory holding the generated files, but works inside VS and is triggered anytime the project regenerates the files.
I am converting a C++ project created using Visual Studio 2005 to CMake and have stumbled upon a bit of a problem with resource files that are included in the project.
The project includes a .rc file, a bunch of .ico files and a .rc2 file.
The regular .rc file works fine in the generated project and uses the resource compiler. The .ico and .rc2 files however are causing problems when they are just being included, because in the generated project Visual Studio attempts to compile them using the C/C++ compiler.
I assume that these files are included by the .rc file, so it would probably work to just not include them in the CMakeLists.txt file, but since it is obviously possible to list them in the project (they are visible in the original project) I would like to do so, so that the user of the generated project can see that these files are being used.
What is the correct way to handle these extra VS resource files in CMake?
Try to set_source_files_properties(your.ico your.rc2 PROPERTIES LANGUAGE RC).
By default it shouldn't do anything with those files. The source file property LANGUAGE should be empty and thus the action for the file should be checked by the file type. Which shouldn't be anything since it's not something it should compile.
Check your CMakeLists.txt that is doesn't contain a set_source_files_properties command that would mess with that property.
If you want to do something with the files, here are two ways to do things:
With add_custom_target you can add them and run custom commands for them when you build the project. Granted that the files have changed.
With configure_file you can easily copy them to a build directory if needed. With the COPYONLY flag.
I am using Visual Studio 2010 to build an application in C++. I have a custom build event which creates additional headers and source files in a separate directory. How can I tell Visual Studio to include those generated files in its build queue. I don't necessarily need to add them to the project but I need to compile them like they are part of the project.
If the names of the files don't change, create a folder(filter) called generated and add those files to this folder(filter). If they don't exist VS won't complain when compiling, if they exist they will be included in the build.
I use this scheme when i have to use generated files.
I don't think it's possible (unless there's an add-on for that or something). But what you could do is to generate all those files and then add them to the project. After that in the custom build event specify them as outputs. That way VS will not try to build them before they are generated and will not complain that they are missing.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Visual studio keeps building everything
I have a project that includes an idl file that generates a .c file that is included in another file of the same project.
I build this project and all is fine, I then try to run the project and I am told the project is out of date and would I like to build it. If I select yes to build it the idl is compiled again.
Is there any way of stopping this without setting the VS project setting to never prompt me for a build?
Once you've built the .idl file once, open it's properties and enable "Exclude from Build".
If you update the file, you can build it manually by selecting the file in Solution Explorer and choosing "Compile" (the shortcut is Ctrl+F7 on my setup, but this may vary).
If you don't include the generated files in your version control system, a fresh checkout will also need to manually rebuild the .idl file. This case in particular can cause a lot of confusion - it may be worth including the generated files under version control.
Another option is to create a custom build tool (or pre-build event), which would compare the last modified date/time of the .idl file with the last modified date/time of the output files and then call MIDL if required. This is the behaviour that VS uses to determine whether or not to run CL, but it is not used for MIDL and, as far as I know, cannot be enabled in VC++ 2008 project files.