Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio : compile list of modules on each platform and configuration

I am working on a huge C++ project, targeting many platforms with several configurations for each platform.

Because of the long compilation time, build the entire project on every platform to test if a change compile successfully, isn't an option.

What I usually do, is compile the single cpp modules I modified on different combination of platform/configuration. I'd like to automate this process, either using a script, a VS extension, whatever, I am open to evaluate different options.

What I need exactly is taking a list of cpp files and compile each file, for each platform and each configuration (basically iterating through all combination of the configuration manager).

Is this possible? any good suggestion on how to approach the problem?


EDIT:

I am aware that this is way far to be a perfect solution, and will spot only a subset of errors. I will still have to face linking errors, compiler errors on other cpp units depended on a modified header, and so on..

I also, don't have any chance to modify the current build system, or project generation.

I am mostly interested in a local solution, to reduce the amount of possible issues and facing the huge building time process.


EDIT2

We have a build system. This has to be considered a pre-build system optimization, for my personal workflow.

Reasons:

Triggering a build system job requires time. It will be the final step, but instead of spending hours waiting, and maybe discover later that a given compiler on a given platform for a specific configuration raise an error, it would be much more efficient to anticipate those findings as much as possible.

Current manual workflow:

  1. Open each cpp file I modified
  2. Compile each cpp file as a single unit (not building the project. On VS Build-> Compile)
  3. Change Platform and/or configuration and re-do point 2 again.

This is the manual workflow I'd like to optimize.

like image 748
Heisenbug Avatar asked Feb 05 '17 18:02

Heisenbug


People also ask

How do I compile in Visual Studio?

Open Visual Studio. Go to File > Open > Folder… and open the MuseScore checkout folder. Visual Studio will automatically begin to generate a CMake cache, which will include the Visual Studio solution and project files.

How do I change from x86 to x64 in Visual Studio?

From the BUILD menu in Visual Studio, select Configuration Manager. From the Active solution platform drop-down list, select New. The New Solution Platform dialog displays. In the Type or select new platform combination box, select x64.

Does Visual Studio support modules?

As of Visual Studio 2022 version 17.1, C++20 standard modules are fully implemented in the Microsoft C++ compiler. You can use the modules feature to create single-partition modules and to import the Standard Library modules provided by Microsoft.


1 Answers

I would suggest that you "simply" write a script to do this (using Python for instance, which is very powerful for this kind of this)

You could:

  • Parse the .sln file to extract the list of configurations, platforms ( GlobalSection(SolutionConfigurationPlatforms) entry) and projects (Project entry)
  • If needed, you can parse every project to find the list of source files (that's easier than parsing the .sln, as vcxproj files are in xml). Look for ClCompile xml nodes to extract the list of .cpp files.
  • Then you can identify which projects needs some files to be recompiled (getting list of modified files as script input parameter or based on timestamp checking)

Finally, to rebuild, you have two options:

  • Call "msbuild " to recompile the whole project (vcxproj) (for instance msbuild project.vcxproj /p:Configuration=Debug;TargetFrameworkVersion=v3.5)
  • You could also recompile a single file (cl simple.cpp). To do so, you need to know what are the cl build options to be sure you compile the file exactly the same way as Visual Studio would. If you earlier did a full build of the solution (it could be a rquirement for your script to work), then you should be able to find that from Visual Studio logs (within the target folder). In my solutions, I can find for every project (vcxproj file) a build log per configuration (in %OUTPUT_DIR%\lib\%libname%\%libname%.dir\%configuration%\%libname%.tlog\CL.command.1.tlog), this file reports the exact cl arguments that were used to compile every file of the project. Then you can manually invoke cl command and this should end up recompiling the file the same way Visual Studio would do it.

Additionnaly, you could add a project in your Visual Studio solution that would fire this script as a custom command.

Such a script should be able to identify which projects has to be rebuilt and rebuild them.

like image 100
jpo38 Avatar answered Sep 28 '22 15:09

jpo38