Generate vs2010 project file with my source directories

In most of my C ++ projects, I want to use a different directory structure from the default directory structure in visual studio. i.e:

/project /build # put visual studio soluation and project files /src # only put the c++ header files and source files /bin # put the target executable files /debug /release /tmp /debug /release 

Every time I create solutaion in vs2010, I will configure these directories (e.g. OutputDirectory), but now I am really bored with that.

So, is there a tool for automatically creating vs2010-solution and project files according to my configuration file? And my only requirement is to install these directories.

+6
source share
2 answers

You can write such a tool yourself in C #, for example, look at the classes in the Microsoft.Build.Construction namespace, they are designed to create projects programmatically.

However, a simpler but more universal option uses the same property sheet in all your projects and sets all the directory paths you need. It also has a huge advantage in that it is reusable, so if you ever decide to change your output directories, all projects that link to your property sheet will be automatically affected. For instance:

 <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <MyMainDir>$(ProjectPath)\..\</MyMainDir> <OutDir>$(MyMainDir)\bin\$(ConfigurationName)</OutDir> <IntDir>$(MyMainDir)\tmp\$(ConfigurationName)</IntDir> </PropertyGroup> </Project> 

First you recognize your “main directory”, that is, the one called “project” in your question, and then set the output and intermediate directories on it and the name of the current ConfigurationName , which by default is Debug or Release .

Now it's just a matter of importing this property page into your project: go to View->Other Windows->Property Manager , right-click the project (s), select Add Existing property Sheet . Or you can manually add <Import Project=....> to the project file.

While you are on it, you can also add compiler / linker parameters to the property sheet so that all your projects use the same parameters. This will take some time, but will save you a lot of time in the future, since you do not have to change the same parameters in the project settings again and again.

+2
source

You can create a structure with the following CMakeList. The following assumes the file is in .../project/CMakeLists.txt :

 cmake_minimum_required(VERSION 2.8) #every top-level project should start with this command; replace the version with the minimum you want to target project(MyProjectName) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) # put .exe and .dll files here set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) # put .so files here (if you ever build on Linux) set(CMAKE_MODULE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) # put .dll and .so files for MODULE targets here set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib) # put .lib files here # Note that for multi-configuration generators (like VS), the configuration name will be appended to the above directories automatically # Now that the directories are set up, we can start defining targets add_executable(MyExe src/myExe.cpp) add_library(MyLib SHARED src/myDLL.cpp) target_link_libraries(MyExe MyLib) 

When invoking CMake, set the output directory .../project/build (for example, in the CMake GUI). If you work on the command line, follow these steps:

 > cd .../project/build > cmake .. -G "Visual Studio 10" 

Note that some generators (Eclipse) do not like it when the output directory is a subdirectory of the source directory. In this case, a slight restructuring of the catalog is recommended.

+5
source

All Articles