Good techniques to use Makefiles in VisualStudio?

后端 未结 11 1032
迷失自我
迷失自我 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).

提交回复
热议问题