Good techniques to use Makefiles in VisualStudio?

后端 未结 11 955
迷失自我
迷失自我 2021-01-05 23:12

I know the ideal way to build projects is without requiring IDE based project files, since it theoretically causes all sort of trouble with automation and what not. But I\'v

相关标签:
11条回答
  • 2021-01-05 23:35

    One possibility is to use CMake - you describe with a script how you project is to be built, and CMake generates the Visual Studio solution/project files for you.

    And if you need to build your project from the command line, or in a continuous integration tool, you use CMake to generate a Makefile for NMake.

    And if you project is a cross-platform one - you can run CMake to generate the makefiles for the toolchain of your choice.

    A simple CMake script looks like this:

    project(hello)
    add_executable(hello hello.cpp)
    

    Compare these two lines with a makefile or the way you setup a simple project in your favorite IDE.

    In a nutshell CMake does not only cross-platform-enables your project it also makes it cross-IDE. If you like to just test your project with eclipse or KDevelop, or codeblocks, just run CMake to generate the corresponding project files.

    Well, in practice it is no always so easy, but the CMake idea just rocks.

    For example, if you consider using CMake with Visual Studio there is some tweaking required to obtain the familiar VS project feeling, main obstacle is to organize your header and source files, but it is possible - check the CMake wiki (and by writting a short script you might even simplify this task).

    0 讨论(0)
  • 2021-01-05 23:36

    Take a look at MSBuild!

    • MSBuild can work with the sln/csproj files from VS, so for simple projects you can just call them directly.
    • if you need more control, wrap the projects in your own build process, add your own tasks etc. - it is very extensible!

    (I wanted to add a sample but this edior totally messed up the XML... sorry)

    0 讨论(0)
  • 2021-01-05 23:37

    Visual Studio since VS2005, uses "msbuild" to define and run builds. When you fiddle with project settings in the Visual Studio designer - let's say you turn XML doc generation on or off, or you add a new dependency, or you add a new project or Assembly reference - Visual Studio will update the .csproj (or .vbproj, etc) file, which is an msbuild file.

    Like Java's ant or Nant before it, msbuild uses an XML schema to describe the project and build. It is run from VS when you do a "F6" build, and you can also run it from the command line, without ever opening VS or running devenv.exe.

    So, use the VS tool for development and command-line msbuild for automated builds - same build, and same project structure.

    0 讨论(0)
  • 2021-01-05 23:41

    Why would you want to have project that "compiles on Windows that doesn't depend on the VisualStudio project"? You already have a solution file - you can just use it with console build.

    I'd advise you to use msbuild with conjunction with makefile, nant or even simple batch file if your build system is not as convoluted as ours...

    Is there something I'm missing?

    0 讨论(0)
  • 2021-01-05 23:44

    I haven't tried it myself yet, but Microsoft has a Make implementation called NMake which seems to have a Visual Studio integration:

    • NMake
    • Creating NMake Projects
    0 讨论(0)
提交回复
热议问题