cmake and visual studio

2020-05-21 04:25发布

gcc 4.4.2 / Visual Studio C++ 2008

I have been using cmake on linux, without any problems.

Now I have ported by application to run on windows.

I generated the solution files using cmake -G "Visual Studio 9 2008 ../src"

However, I know that cmake only creates a Makefile that is used by the compiler to build your application.

I open my solution in Visual Studio, I press the F7 key to compile.

I am wondering does it actually use the Makefile that was generated by cmake? Or it is just compiling the application like any normal visual studio program?

Many thanks for any advice,

标签: cmake
3条回答
做自己的国王
2楼-- · 2020-05-21 04:45

CMake generates "real" .vcproj files, so Visual Studio will build your project like any normal Visual Studio project. There are no makefiles involved.

查看更多
forever°为你锁心
3楼-- · 2020-05-21 05:02

Cmake generates a Visual Studio Solution and Project file.

The solution contains at least three projects:

  • ALL_BUILD
  • YourProject
  • ZERO_CHECK

The solution is set up so that when you build your project (by build solution, or build project) "YourProject" will be built and then ZERO_CHECK will be built, causing cmake to run and check if anything has changed. If anything has changed, the solution and project file will be regenerated and Visual Studio will ask if you would like to reload.

The compilation of your program is done by Visual Studio, as it would if you set it up manually, but Visual Studio will run cmake, and thus check if anything has changed, and the project files should be regenerated.

查看更多
We Are One
4楼-- · 2020-05-21 05:03

From CMake website:

CMake is used to control the software compilation process using simple platform and compiler independent configuration files, and generate native makefiles and workspaces that can be used in the compiler environment of your choice.

The key is, it generates native makefiles and workspaces from the compiler independent configuration files (CMakeLists.txt files).

So the first step with CMake is to generate the native build files from the CMakeLists.txt, which isMakefiles on Linux and Visual Studio projects/solution on Windows. Then you compile/link as though the native build files were created from scratch.

When you edit a CMakeLists.txt, it means that the change has to be propagated to the native build scheme. This is done by explicitly running the CMake generator again or implicitly by the ZERO_CHECK project in the Visual Studio Solution.

CMake and Visual Studio has a simple example mapping CMake commands (which exist in CMakeLists.txt) to Visual Studio projects.

查看更多
登录 后发表回答