I have a big C++ project and I need to do many steps in the building phase because I am building an application that is compatible with both 64 and 32, I have three projects:
proj1,Porj2,Proj3
and I need to do the following:
-
Exclude a cpp File from proj1 (32bit version)
-
Include a cpp file to proj1 (64bit version)
-
build proj1
-
build proj2
-
Execute output of proj2
-
Exclude a cpp File from proj3 (32bit version)
-
Include a cpp file to proj3 (64bit version)
-
Build proj3
-
Rename the exe that was built from proj3
-
Exclude a cpp File from proj1 (64bit version)
-
Include a cpp file to proj1 (32bit version)
still there are some other steps … I was doing that manually and its frustrating, I found the I need to use MSBUILD but is it used for building native code ? and how can I perfrom these tasks ?
-Excluding and Including cpp files into projects
-Building proj
In Visual Studio 2010 and later, C++ projects use MSBuild.
Rather than excluding or including files based on the configuration, it would be simpler to use a preprocessor directive to conditionally compile the contents of the file. E.g., wrap the entire contents of the file in:
And likewise with a macro for 64-bit builds. When using Visual C++, you can use the
_M_IX86and_M_X64predefined macros to detect whether you are compiling for x86 or x64, respectively.Alternatively, you could add a
Conditionproperty to theClCompileitem for the particular source file in the project file, and have it only included in the build when certain properties are set. I think that conditional compilation within the source file is a better option, though, unless you have complex rules that you need to use to determine whether to include a file or not.In your solution, you can set project dependencies to ensure that one project is built before another. Right-click the solution, select Properties, and browse to Common Properties -> Project Dependencies. Dependencies can also be specified in a project file.
You can execute the output of a build by using a post-build task. Right-click the project, select Properties, and browse to Configuration Properties -> Build Events. The Post-Build event can be used to execute a command when the build has completed.
Rather than renaming an executable after build, it’s easier to just have the build produce an executable with the right name. In the Project properties, under Configuration Properties -> General, the Target Name property can be used to set the name of the primary build output.