RealPath:
WebPath:
2017/02/12 02:24 (JST) 更新
MinGW on MSYS >>

CMake導入

Contents

概要

プログラムに Boost ライブラリ等をリンクさせる際に、手動で Makefile を書くのは割と大変。
CMake を導入すると Makefile 作成処理を自動化できて依存解決が少し楽になったりする。

CMake インストール

※PATH 追加もインストーラ側から行える。

設置確認

dos
> which cmake.exe
C:\Program Files\CMake\bin\cmake.exe

> cmake --version
cmake version 3.7.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).

簡単な CMakeLists.txt の動作確認

sample.cpp
#include <stdio.h>
int main()
{
    printf("hello\n");
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.7)

ADD_EXECUTABLE(Sample sample.cpp)
dos
> cmake -G "MSYS Makefiles"
-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is GNU 5.3.0
-- Check for working C compiler: C:/MinGW/bin/gcc.exe
-- Check for working C compiler: C:/MinGW/bin/gcc.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe
-- Check for working CXX compiler: C:/MinGW/bin/g++.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Projects/testproj

> make
Scanning dependencies of target Sample
[ 50%] Building CXX object CMakeFiles/Sample.dir/sample.cpp.obj
[100%] Linking CXX executable Sample.exe
[100%] Built target Sample

> Sample.exe
hello