上野家のホームページ
ナーマル,マリン,ココ
[
新規
|
一覧
|
検索
|
最新
|
ヘルプ
]
開発/cmake
をテンプレートにして作成
資料室
開発/cmake をテンプレートにして作成
[
差分
|
バックアップ
|
リロード
]
[ ]
開始行:
* CMake
CMakeは,ソフトウェアのビルドの自動化ツール。
WindowsではVisual Studioを使って,LinuxなんかだとMakeなど...
例えば,OpenGLやOpenCVなどを利用するプログラムをコンパイ...
CMakeはこの煩雑な設定作業を手助けしてくれるツール。簡単な...
詳細は,~
- [[公式サイトのチュートリアル>https://cmake.org/cmake/he...
- [[OpenCVのCMakeチュートリアル>http://opencv.jp/cmake/cm...
なんかを読みましょう。
** Windowsマシンにインストール
cmake for Windowsは,Windowsで動作するcmake。これをインス...
[[公式サイト>https://cmake.org/download/]]から,最新版のW...
ダウンロードした.msiファイルをダブルクリックして実行すれ...
- ようこそ画面でNextをクリック~
- ライセンス条項の確認のチェックをして,Next~
- Add CMake to the system PATH for all usersをチェックし...
- インストールディレクトリを入力してNext~
インストールディレクトリは, C:\WinApl\CMake\ とかにする。~
- Installをクリック~
- Finishをクリック~
これでインストールされます。
コマンドプロンプトを起動して,
D:\home\ueno> cmake --version
cmake version 3.11.4
CMake suite maintained and supported by Kitware (kitware...
と表示されればOK。
* CMakeを使ってみる
適当なディレクトリで以下のようなソースコードを作成する。~
''hello.c''
#code(c){{
#include <stdio.h>
int main(void)
{
printf("Hello!\n");
return 0;
}
}}
''CMakeの設定ファイルは,CMakeLists.txtという名前にする。...
以下は最低限必要なCMakeLists.txt。
cmake_minimum_required(VERSION 2.8)
project(hello C)
add_executable(hello hello.c)
最初の行は,このCMakeLists.txtを使うのに必要なCMakeのバー...
GNU Autoconfでも似たような設定(AC_PREREQ)がある。でも,...
次の行の''project''は,プロジェクト名と使用する言語を設定...
3行目の''add_executable''は,実行ファイルの作成を指示する...
複数ソースファイルがある場合は, add_executable(hello hel...
ライブラリを作成する場合は,''add_library''を使う。
3行目だけでも一応動作はするがいろいろワーニングメッセージ...
CMakeを実行する場合は,
> cmake [オプション] パス
とする。この時,パスのディレクトリにあるCMakeLists.txtが...
CMakeは,ConfigureとGenerateという過程が実行される。~
Configureは,CMakeLists.txtからビルドに必要な情報を収集す...
Generateは,Configureで集めた情報を使ってMakefileやプロジ...
** CMakeによるビルド
上記CMakeLists.txtをhelloに置いて,buildディレクトリを作...
''GCC''を使ってコンパイル出来るように,''Makefileを作成す...
引数はディレクトリ名だが,すでにhello\buildにいるので引数...
> mkdir build
> cd build
> cmake -G "Unix Makefiles" ..
-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
-- Check for working C compiler: D:/MinGW/bin/gcc.exe
-- Check for working C compiler: D:/MinGW/bin/gcc.exe --...
-- 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: D:/MinGW/bin/c++.exe
-- Check for working CXX compiler: D:/MinGW/bin/c++.exe ...
-- 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: D:/home/ueno/soft/c...
どんなファイルが作成されたか見てみる。
> ls
CMakeCache.txt CMakeFiles CMakeLists.txt Makefile cm...
Makefileが生成されているので,後はmakeでコンパイル出来る。
> make
Scanning dependencies of target hello
[ 50%] Building C object CMakeFiles/hello.dir/hello.c.obj
[100%] Linking C executable hello.exe
[100%] Built target hello
実行ファイルhello.exeが出来ているので,実行してみる。
> hello
Hello!
makeコマンドでビルドしたが,''cmakeでビルドする場合は,''
> cmake --build .
と,します。''.''の意味は,Generateで作成したディレクトリ...
''GENERATORオプションを使用しない場合はデフォルトのシステ...
> mkdir buildvs
> cd buildvs
> cmake ..
-- Building for: Visual Studio 15 2017
-- Selecting Windows SDK version 10.0.17763.0 to target ...
-- The C compiler identification is MSVC 19.16.27026.1
-- The CXX compiler identification is MSVC 19.16.27026.1
-- Check for working C compiler: C:/Program Files (x86)/...
-- Check for working C compiler: C:/Program Files (x86)/...
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86...
-- Check for working CXX compiler: C:/Program Files (x86...
-- 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: D:/home/ueno/soft/c...
作成されたファイルは,
> ls
ALL_BUILD.vcxproj CMakeCache.txt CMakeLists.tx...
ALL_BUILD.vcxproj.filters CMakeFiles Project.sln ...
が出来ている。~
Visual Studioのソリューションファイルが出来ているので,こ...
コンパイルしてみる。
> cmake --build . --config release
これで,releaseディレクトリにhello.exeが出来ているので,...
> release\hello
Hello!
終了行:
* CMake
CMakeは,ソフトウェアのビルドの自動化ツール。
WindowsではVisual Studioを使って,LinuxなんかだとMakeなど...
例えば,OpenGLやOpenCVなどを利用するプログラムをコンパイ...
CMakeはこの煩雑な設定作業を手助けしてくれるツール。簡単な...
詳細は,~
- [[公式サイトのチュートリアル>https://cmake.org/cmake/he...
- [[OpenCVのCMakeチュートリアル>http://opencv.jp/cmake/cm...
なんかを読みましょう。
** Windowsマシンにインストール
cmake for Windowsは,Windowsで動作するcmake。これをインス...
[[公式サイト>https://cmake.org/download/]]から,最新版のW...
ダウンロードした.msiファイルをダブルクリックして実行すれ...
- ようこそ画面でNextをクリック~
- ライセンス条項の確認のチェックをして,Next~
- Add CMake to the system PATH for all usersをチェックし...
- インストールディレクトリを入力してNext~
インストールディレクトリは, C:\WinApl\CMake\ とかにする。~
- Installをクリック~
- Finishをクリック~
これでインストールされます。
コマンドプロンプトを起動して,
D:\home\ueno> cmake --version
cmake version 3.11.4
CMake suite maintained and supported by Kitware (kitware...
と表示されればOK。
* CMakeを使ってみる
適当なディレクトリで以下のようなソースコードを作成する。~
''hello.c''
#code(c){{
#include <stdio.h>
int main(void)
{
printf("Hello!\n");
return 0;
}
}}
''CMakeの設定ファイルは,CMakeLists.txtという名前にする。...
以下は最低限必要なCMakeLists.txt。
cmake_minimum_required(VERSION 2.8)
project(hello C)
add_executable(hello hello.c)
最初の行は,このCMakeLists.txtを使うのに必要なCMakeのバー...
GNU Autoconfでも似たような設定(AC_PREREQ)がある。でも,...
次の行の''project''は,プロジェクト名と使用する言語を設定...
3行目の''add_executable''は,実行ファイルの作成を指示する...
複数ソースファイルがある場合は, add_executable(hello hel...
ライブラリを作成する場合は,''add_library''を使う。
3行目だけでも一応動作はするがいろいろワーニングメッセージ...
CMakeを実行する場合は,
> cmake [オプション] パス
とする。この時,パスのディレクトリにあるCMakeLists.txtが...
CMakeは,ConfigureとGenerateという過程が実行される。~
Configureは,CMakeLists.txtからビルドに必要な情報を収集す...
Generateは,Configureで集めた情報を使ってMakefileやプロジ...
** CMakeによるビルド
上記CMakeLists.txtをhelloに置いて,buildディレクトリを作...
''GCC''を使ってコンパイル出来るように,''Makefileを作成す...
引数はディレクトリ名だが,すでにhello\buildにいるので引数...
> mkdir build
> cd build
> cmake -G "Unix Makefiles" ..
-- The C compiler identification is GNU 6.3.0
-- The CXX compiler identification is GNU 6.3.0
-- Check for working C compiler: D:/MinGW/bin/gcc.exe
-- Check for working C compiler: D:/MinGW/bin/gcc.exe --...
-- 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: D:/MinGW/bin/c++.exe
-- Check for working CXX compiler: D:/MinGW/bin/c++.exe ...
-- 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: D:/home/ueno/soft/c...
どんなファイルが作成されたか見てみる。
> ls
CMakeCache.txt CMakeFiles CMakeLists.txt Makefile cm...
Makefileが生成されているので,後はmakeでコンパイル出来る。
> make
Scanning dependencies of target hello
[ 50%] Building C object CMakeFiles/hello.dir/hello.c.obj
[100%] Linking C executable hello.exe
[100%] Built target hello
実行ファイルhello.exeが出来ているので,実行してみる。
> hello
Hello!
makeコマンドでビルドしたが,''cmakeでビルドする場合は,''
> cmake --build .
と,します。''.''の意味は,Generateで作成したディレクトリ...
''GENERATORオプションを使用しない場合はデフォルトのシステ...
> mkdir buildvs
> cd buildvs
> cmake ..
-- Building for: Visual Studio 15 2017
-- Selecting Windows SDK version 10.0.17763.0 to target ...
-- The C compiler identification is MSVC 19.16.27026.1
-- The CXX compiler identification is MSVC 19.16.27026.1
-- Check for working C compiler: C:/Program Files (x86)/...
-- Check for working C compiler: C:/Program Files (x86)/...
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86...
-- Check for working CXX compiler: C:/Program Files (x86...
-- 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: D:/home/ueno/soft/c...
作成されたファイルは,
> ls
ALL_BUILD.vcxproj CMakeCache.txt CMakeLists.tx...
ALL_BUILD.vcxproj.filters CMakeFiles Project.sln ...
が出来ている。~
Visual Studioのソリューションファイルが出来ているので,こ...
コンパイルしてみる。
> cmake --build . --config release
これで,releaseディレクトリにhello.exeが出来ているので,...
> release\hello
Hello!
ページ名:
Counter: 0, today: 0, yesterday: 0
Copyright©2008 Yuji Ueno All Rights Reserved.
ログイン
ユーザ名:
パスワード:
IDとパスワードを記憶
パスワード紛失
メインメニュー
ホーム
でぶlog
資料室
最新ページ一覧
全ページ一覧
ヘルプ
フォーラム
お問い合わせ