auto compile generated visual studio files without adding to project - c++

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.

Related

Compile auto generated files without adding them to vcxproj

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?

Visual Studio custom build-generated file included by a .cpp

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.

How do you compile and run a project in Visual Studio when you have multiple source and header files involved in the same project?

I mostly worked with linux env, new to visual studio. (If you are in Linux, you would use the make utility...) How do you compile and run a project in Visual Studio when you have multiple source and header files involved in the same project? I have main.cpp, and few other source and corresponding header files, and when i built the project, I couldn't see an output although the project compiled fine and 'exited gracefully'. How do I tell Visual Studio that these files are part of the project?
To do that:
Select Project -->
Add Existing Item....
You should be looking in the same directory where you saved the project/solution.
Highlight the .h and .cpp files: date.cpp, date.h and main.cpp
Select "Add" to add the files to the project.
Result: Once I added the 'main.cpp' and other files in the project, it works fine and I am able to view the output.
References:
1 [http://www.cs.uregina.ca/Links/class-info/210/Lab1_VCIntro/]

CMake and Visual Studio resource 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.

Automatically add files to be compiled in visual studio

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.