Automatically including source files into Visual Studio 15 - c++

Overview:
I am wanting to allow visual studio 15 to automatically add an existing source file after I generate them.
Full explanation:
I am currently generating a lot of new .h and .cpp files with other tools outside of the IDE using bat scripts and such but needing to use them within the IDE to integrate with the project. As such I would be great if there was a a way to allow VS to add these source files automatically after they are generated without having to add them manually.
The files are always generated into the same given folder path if that helps.

You could generate the project with a CMake script. When you run your batch file, you could have it re-invoke CMake to update the project with the new sources. If you are generating files, especially if you can't predict the names in advance, you will likely want to use the CMake's file(GLOB ...) command.

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?

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.

Source directories in Visual Studio 2010

I am using OF in my project and I want to use some add-ons but I have to add .cpp files to my project in order to compile them. I don't like it. Is there any option so I could specify a folder to scan for source files and compile every .cpp file it finds?
I thought it might be Source Directories in VC++ Directories section but it didn't work. Then I don't really get what it does.
If you want to compile sources using Visual Studio, you will have to add them to your project.
There is nothing wrong about adding external sources to your project in a nice filter.
You can also create a makefile to be used by Visual Studio which will list sources you need.
I'm not aware of an option that does what you ask for in VS. The Source directories configuration is used for locating source files that go along with libraries that you are using in your project. This way you can use the library in its binary format without the need to recompile it every time you rebuild your project, but you can also step into its code while debugging.

Can the list of C++ files in a Visual Studio project be dynamically filled?

I have a tool that generates most (but not all) files that need to be compiled in Visual Studio. The tool reads a configuration file and generates c++ files afterwards. This list can differ from one call to another when the configuration is altered.
I am wondering whether it would be possible to adapt the compiling process to my needs, which would be :
Launch the tool (not needed if configuration file has been modified)
Retrieve new list of C++ files to be compiled (ideally isolated in a folder inside the project)
Compile C++ files
EDIT: Having to close Visual Studio for this process to work is a no-go for me. The idea would be to have cpp files dynamically added as the first step of the compilation process.
Use a pre-build step to run your tool.
Also, create a file containing the list of includes and sources
This file name should be fixed (so that you don't have to change project properties or the vcproj file) -- add it to the project. E.g:
Project Properties > Command Line > Additional Options > #headerListingFile
You are not trying to integrate lex/yacc output with VS, are you?
Would CMake help? It's an automated project manager that generates Makefiles and VS projects for projects you define. Just add a source file, re-run CMake and you're done.
I think what you should do is create a custom makefile and use that for builds.
Please see this page for more information.