官方下載地址: https://cmake.org/download/nginx
選擇本身系統(Platform)對應的版本並下載
這裏咱們選擇Windows win64-x64 Installer: Installer tool has changed. Uninstall CMake 3.4 or lower first!c++
安裝時根據本身系統的安全設置,可能會出現以下對話框,不用擔憂,直接點擊 "運行(R)"sql
必須選擇贊成,不然不能進入下一步安全
這裏選擇本身習慣存放程序的路徑,咱們這裏採起默認值ruby
通過前面的操做終於把須要配置的都配置了,下面該程序本身幹活了bash
真正開始安裝的階段,這一階段比較耗時,徹底取決於電腦自身的配置高低,系統主要是解壓文件和寫磁盤app
恭喜你,終於將CMake安裝完成了ide
驗證CMake是否成功安裝,能夠調出CMD窗口,輸入cmake
,瞧瞧系統會給你說什麼,若是出現以下窗口,那麼恭喜你沒有任何問題。ui
那麼萬一出現的是以下內容呢spa
咱們通常有以下處理步驟和處理方法:
這裏給出64系統使用的mingw, https://sourceforge.net/projects/mingw-w64/
這裏實際上是下載的一個安裝器,具體的安裝是經過運行這個安裝器來引導安裝的
這裏須要作出對應的選擇,固然徹底默認沒有任何問題,咱們這裏採用默認,繼續安裝
這裏有坑,咱們先入坑, 繼續安裝
安裝器須要從網上下載所須要的文件,這一步耗時較長
同CMake的同樣,mingw安裝完後自動了設置環境變量,你也能夠經過運行其安裝目錄下的mingw-w64.bat
來進入運行環境
驗證mingw環境是否設置好,一樣新調出CMD窗口,輸入gcc
命令,出入以下信息則表示安裝沒有問題,不然請參照CMake配置環境變量的方式來解決。
咱們安裝完環境後來個實例運行下吧
1#include <stdio.h>
2int main()
3{
4 printf("hello\n");
5 return 0;
6}
1cmake_minimum_required(VERSION 3.0)
2project(Hello)
3set(SOURCE main.cpp)
4add_executable(${PROJECT_NAME} ${SOURCE})
1mkdir build
2cd build
3cmake -G"Unix Makefiles" ../
很不幸,這一步會出問題
1CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles". CMAKE_MAKE_PROGRAM is not set. You probably need to select a different build tool.
2CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
3CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
4-- Configuring incomplete, errors occurred!
5See also "D:/tmp/build/CMakeFiles/CMakeOutput.log".
意思就是不能生成Unix Makefiles,這是缺乏make程序形成的,
解決方法就是找到mingw安裝目錄下mingw32-make.exe拷貝一份並重命名爲make.exe
再運行cmake -G"Unix Makefiles" ../
1$ cmake -G"Unix Makefiles" ../
2-- The C compiler identification is GNU 7.2.0
3-- The CXX compiler identification is GNU 7.2.0
4-- Check for working C compiler: C:/Program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin/gcc.exe
5-- Check for working C compiler: C:/Program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin/gcc.exe -- works
6-- Detecting C compiler ABI info
7-- Detecting C compiler ABI info - done
8-- Detecting C compile features
9-- Detecting C compile features - done
10-- Check for working CXX compiler: C:/Program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin/c++.exe
11-- Check for working CXX compiler: C:/Program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin/c++.exe -- works
12-- Detecting CXX compiler ABI info
13-- Detecting CXX compiler ABI info - done
14-- Detecting CXX compile features
15-- Detecting CXX compile features - done
16-- Configuring done
17-- Generating done
18-- Build files have been written to: D:/tmp/build
這樣就對了
1make
什麼,又有問題
1$ make
2/usr/bin/sh: -c: line 0: syntax error near unexpected token `('
3/usr/bin/sh: -c: line 0: `C:/Program Files (x86)/mingw-w64/i686-7.2.0-posix-dwarf-rt_v5-rev1/mingw32/bin/make -f CMakeFiles/Makefile2 all'
4make: *** [Makefile:84: all] Error 1
還記得前面咱們安裝mingw時說的坑嗎,如今咱們須要填坑了,文件就是萬惡的C:/Program Files (x86)
,這也好辦,將mingw-w64
文件夾複製到一個正常的目錄吧,好比直接C:/mingw-w64
,而後須要修改環境變量
1$ make
2Scanning dependencies of target Hello
3[ 50%] Building CXX object CMakeFiles/Hello.dir/main.cpp.obj
4[100%] Linking CXX executable Hello.exe
5[100%] Built target Hello
1$ ./Hello.exe
2hello
好了,終於成功了