I have a large project and it takes quite a lot of time to compile the whole thing. A small change in a header file will result in building the whole project again even though it doesn't affect most of the other components. Is there a way to use premake5 to build source files in the project to its own library file (preferably .lib files) without creating separate projects for all of them?
Thank You!
No, that is not possible. Premake is designed to generate projects that can work with a variety of different toolsets, and most (no?) IDEs support that workflow.
Related
I'm working at an organization with a product suite based on several hundred Visual Studio solutions (mostly C++). Some of these solutions generate libraries that are used by other solutions and there's also a common "include" folder containing headers that shared by multiple modules.
The issue is that the dependencies are not explicitly stated anywhere, and the build system resolves dependencies by specifying a linear build order that makes sure the dependent modules get built at the right time. This works well for the build system but leaves developers at a disadvantage when trying to work on components with many direct and indirect external dependencies. For example, I might want to edit one of the library projects or shared headers and then build all the affected modules without necessarily knowing ahead of time which ones are affected. Another use case involves building a module after doing a fresh pull from TFS and having the modules it depends on built first without having to build the entire system.
I am wondering if there is/are any tool(s) available that can automate dependency generation for building large projects. I have considered creating a few really big solutions that encapsulate the other solutions but that seems really awkward and clumsy. Also, I don't like the idea of having developers manually specify dependencies as it can error prone, especially with such a large code base. I worked with scons a few years ago and really liked the way it could parse source files and automatically discover all the dependencies dependencies. Is there anything available today that can do the same thing with Visual Studio solutions?
This is not a duplicate of Visual Studio: how to handle project dependencies right?
I need to emphasize the magnitude of the problem I am trying to solve. This is a very large existing code base. In the main directory there are several hundred sub-folders, each one containing one of more VS solutions (not projects). Each solution, in turn, contains one or more projects. As I said before, I'm not trying to establish dependencies among a few projects in a solution. The problem is much bigger than that. I'm trying to find a way to establish dependencies among the solutions themselves (several hundred of them). For example, one solution may contain some projects that generate libraries for security, others for communications, etc. There may be, for example, dozens of solutions that use the communications libraries. So essentially I'm trying to create a directed a cyclic graph with hundreds of nodes and potentially tens of thousands of edges.
You could use cmake (https://cmake.org/). With it, you can specify several libraries and apps to be built. Once configured, you can modify a project and the build will just update the dependent projects. Cmake also provides a visual studio generator, so that you can continue using that IDE.
A possible disavantage to you is that, to configure, you must explictly specify, for each project (library or executable), with what projects it must be linked and what folders it must include. There are ways to define some global includes and links, but the use will depends on your problem.
VS does track dependencies (by parsing source files). It doesn't make sense that something could automatically set dependencies of your VS projects, in any other build tools you'd still have to specify in some way that for linking project A.exe you need to use B.lib.
If you use newer VS versions you should simply add references to lib to your exe/dll projects. If you manually added project dependencies, most likely you should remove them all, especially make sure you don't make static lib projects dependent on each other. VS allows you to do that (for example, if build of one library generates some source files that another static lib uses), but in general these shouldn't have any dependencies and this allows VS to optimize builds by building them in parallel.
For example, commonly you could have some kind of Base.lib, then System.lib and Graphics.lib. All of these are user by your App.exe. System.lib uses code from Base.lib, Graphics.lib uses code from System.lib and Base.lib. So, naturally the dependency chain is clear and you go and set them in VS, and that's a mistake! In cases like this in VS you should make these 4 libs independent and only App.exe should be dependent on all these libs (e.g. it should have references to all of these). VS will figure out what is the the correct dependency of these projects.
Regarding Cmake case: it simply generates VS projects and solutions, if you use VS then cmake cannot do more than VS itself can.
I am using visual DSP for two different builds. I am using preprocessors to separate out code that is specific to each in shared files. I was planning to use the built-in preprocessor utility on the project files, but the project files specific to one build is not linked to another so this is not working. Is the only other simple way to preprocess the code in my build script?
Visual studio doesn't support native projects as it supports .NET projects. In the sense that when for example creating a static(.lib) library. Including of the static library, and the directory containing the headers, has to be done manually.
For one project this isn't some much of a problem. But if you're like me managing several projects. A lot of which are somewhat depenendend. It becomes a huge hassle to manage all of it.
I was wondering if there is any official 'microsoft approved' approach to this. And if not, what is the best way to deal with this situation. Supposing the following conditions occur:
several static libraries(.lib) projects. Which are included in several solutions
several dynamic libraries (.dll) projects. Which are included in several solutions
multiple applications using the same libraries(both dynamic and static), in one solution
My personal solution to the problem is as follows.
Every project generating a binary builds to:
$(SolutionDir)build\$(Configuration)\`
Every project generating a static library builds to:
$(SolutionDir)build\$(Configuration)\Libraries\
The intermediate directory for all projects is:
$(SolutionDir)build\$(ProjectName)\$(Configuration)\
And runs the following pre-build command:
Copy /Y "$(ProjectDir)*.h" + "$(ProjectDir)*.hpp" "$(SolutionDir)build\$(Configuration)\Libraries\"
Advantages of this system include:
All the project directories stay free of builds (useful when using source control). And all the binaries are in one place.
Setting additional include directories is never required when using outputs from other projects in the same solution. A dynamic library doesn't have to be added at all. And all that is required to include a static library is adding it to the Additional Dependencies field under:
Configuration Properties->Linker->Input
Drawbacks of this system include:
Since all the header files are copied, the risk exists of accidentally editing those. Which results in loss of work, when the copying occurs again.
Since the settings are per project, they have to be set for ever project
The libraries are built separately for every solution
I have a collection of C++ solutions. They all include a directory of common code. Not just #include, but they individually build common source files as well. Here's an example of the directory structure:
code/
Common/
ProjectA/
ProjectB/
So ProjectA and ProjectB both include files from Common. I have set the intermediate directory for both projects to be code/_build/Debug/Obj.
I had expected that if I built ProjectA first, then ProjectB would not need to rebuild the intermediate files from the Commonsource. This is not happening. ProjectB is rebuilding those object files, and if I build ProjectA again, it will rebuild them as well.
It's as if a conditional rebuild will be triggered if the object file was not built by the project which is currently compiling. Is this true?
I know I could just create a library out of the common code, but this is not an option.
It's as if a conditional rebuild will be triggered if the object file was not built by the project which is currently compiling. Is this true?
Yes. Each project maintains its own separate list of build files. Each project builds those files separately from every other object, because each project also maintains its own separate build options. Every project is separate from all others, even within the same solution.
The problem you describe has been encountered before. A long time ago in fact. The solution to it was, and remains, quite simple: create a third project which creates a static library of common code, which is linked by the other two projects. Indeed, static libraries exist for precisely this reason.
If circumstances forbid you from using the solution that was designed to solve this exact problem, then you have two choices:
change those circumstances so that you can use the solution.
accept the needlessly longer build times incurred by your situation.
I have an online repository with some .h and .cpp files that make up part of a project. I'm trying to check these out and use them in a new project, but am getting errors (C4627 and C1010). All the files have been added to the project (with Add>Existing Item...), and the subdirectories that contain these files have been added to the "Additional include directories" of the project.
Would I be better off having the entire project tree in the repository? My reason for not doing so is that my colleague and I are working on different parts of the code and so want to use different main methods to test things as we go, and I didn't see any need to be passing around any compiled code etc. since I assumed that given the .h and .cpp files (with the correct settings), visual studio would be able to compile the project.
What's the best way to make Visual Studio 2008 and TortoiseSVN work well together (without spending any money)?
Would I be better off having the entire project tree in the repository?
Most certainly yes. You should be able to check out and build without much effort. Creating a new project every time you want to build the source and having to configure it is way too much work.
My reason for not doing so is that my colleague and I are working on different parts of the code and so want to use different main methods to test things as we go, and I didn't see any need to be passing around any compiled code etc.
Ok, just put more than one project in the solution. There's no reason you can't have separate executable projects for separate tests.
I assumed that given the .h and .cpp files (with the correct settings), visual studio would be able to compile the project.
If all of the settings are the same, then, yes, it should compile fine, but why bother with the hassle when you don't have to?
Also AnkhSVN which isn't too bad and it's free. Also, lots of the windows it displays look like TFS (if you're familiar with it)
What's the best way to make Visual Studio 2008 and TortoiseSVN work well together (without spending any money)?
There are a bunch of programs that integrate SVN into Visual Studio. VisualSVN is one of them.
Apologies for the VisualSVN recommendation. We used to use it in an old project and I'm positive it was free then. Maybe they changed their license?