Windows CMake using the manual Part 1

Source: Internet
Author: User
Tags windows download

Wikipedia Introduction "CMake is an open-source cross-platform automation construction system that uses a configuration file to control the build process in a way similar to the UNIX make, except that the CMake configuration file is named CMakeLists.txt. CMake does not directly construct the final software, but rather produces standard constructs such as UNIX's makefile or windowsvisual C + + projects/workspaces, which are then used in a general constructive manner. This makes it possible for developers familiar with an integrated development environment (IDE) to build their software in a standard way, and the ability to use the native building systems of each platform is the difference between CMake and scons and other similar systems. ”

1. CMake Installation

https://cmake.org/download/, Windows download Cmake-3.5.2-win32-x86.msi

Post-Installation Interface

2. Hello World Example

Suppose you set up a folder E:\Playground\CMakeExamples\HelloWorld, there is a file below HelloWorld.cpp

#include <iostream>          int main () {   std::cout<< "Hello world!" <<std::endl;   return 0;}

Create a CMakeLists.txt file under the same folder

Cmake_minimum_required (VERSION 3.0)
Project (Hello)
Add_executable (Hello Helloworld.cpp)

    • The first line sets the required CMake minimum version number, which is generally set to the CMake version number you are currently using for easy follow-up maintenance.
    • The second line sets the project name
    • The third line, Add_executable, is the first parameter to generate the executable name, depending on the platform on which the hello.exe is generated, or HELLO.A or other format. The second parameter is a list of required source files.

Operating under the graphical interface:

In the where is the source code, fill in the CMakeLists.txt folder, note that the folder CMakeLists.txt is located, not the HelloWorld.cpp folder. The following example mentions the situation where the source file is not in the same directory as the cmakelists.

Where to build the binaries: can be any folder, keep the generated project files, here I choose to build under the build folder. After you have set up click Configure you need to select Project Builder, here I choose Visual Studio Win64

After clicking Finish

CMake automatically set various variables, regardless of the Red section, click Generate, under the Build folder will generate

Hello.sln,project was created, except for Hello.vcxproj and All_build.vcxproj and Zero_check.vcxproj.

The answer to the StackOverflow is

After some to searching, I found the answer at Https://cmake.org/pipermail/cmake/2008-November/025448.html:

Armin berres-11/22/2008, 3:12:41 PM

Zero_check'll rerun CMake. You can/should execute the after changing something on your CMake files.

All_build is simply a target which builds all and everything project in the active solution, I guess one can compare it to "Make all".

You can open Hello.sln, compile, and run with Visual Studio. Here we compile with MSBuild. If the command-line prompt MSBuild cannot find, add C:\Windows\Microsoft.NET\Framework64\v4.0.30319 to the system path variable first.

Under the build directory, run

MSBuild Hello.vcxproj

Run Debug\hello.exe to view the output.

If you want to compile into release, run

Msbuild/p:configuration=release hello.vcxproj

Windows CMake using the manual Part 1

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.