CMakeはCross platform Makeの略。各OSにあわせてslnファイルやmakefileを作れる。

参照:http://fseek.exblog.jp/5637217

*CMakeLists.txtの書き方 [#e5860485]
-cmake_minimum_required
 cmake_minimum_required(VERSION 2.8)
-プロジェクト名
 PROJECT(hoge)
--ここで指定した名前がVSだったらソリューション名になる(hoge.sln)
-インクルードディレクトリ
 include_directories("./include")
--インクルードディレクトリは複数かける
--Debug/Releaseでincludeディレクトリを切り分ける方法は無いっぽい?
-ソース/ヘッダファイルの指定
 file(GLOB foo_sources   "foo/*.cpp")
--fileコマンドを使う
--GLOBは正規表現みたいに複数のファイルをワイルドカードで指定できる
--正規表現よりもうちょい賢いことができるらしい
-CMakeLists.txtのデバッグ(?)
 message(STATUS ${foo_sources})
--みたいに使うと、CMakeのデバッグ画面にfoo_sources変数の中身がダンプされる
-Cudaを使うプロジェクト
 cuda_add_library(bar_cuda ${cuda_sources})
--ただし、この場合は、それ以前に
 find_package(CUDA QUIET REQUIRED)
--する必要がある
-ライブラリプロジェクト
 add_library(hoge ${hoge_sources})
-exe形式のプロジェクト
 add_executable
-ライブラリに依存する
 target_link_libraries(foo hogeLibrary)



*インストール [#y5bf72fa]
-http://www.cmake.org/からダウンロード。
-今回はバイナリ(ZIP版)の2.6.2を利用した
-展開して適当なフォルダにおく。
-とりあえずなのでPATHは通さずにおく

*使い方 [#t75e10ed]
-一緒にソースコードパッケージもダウンロードした。
-それにはExampleがついていたので、試してみた。
-基本的には ''cmake .'' でよい(ピリオドを忘れずに)

 C:\work\cmake-2.6.2>cd Example
 
 C:\work\cmake-2.6.2\Example>dir
 2008/09/24  14:46               500 CMakeLists.txt
 2008/11/14  15:37    <DIR>          Demo
 2008/11/14  15:37    <DIR>          Hello

 C:\work\cmake-2.6.2\Example>type CMakeLists.txt
 # The name of our project is "HELLO".  CMakeLists files in this project can
 # refer to the root source directory of the project as ${HELLO_SOURCE_DIR} and
 # to the root binary directory of the project as ${HELLO_BINARY_DIR}.
 project (HELLO)
 
 # Recurse into the "Hello" and "Demo" subdirectories.  This does not actually
 # cause another cmake executable to run.  The same process will walk through
 # the project's entire directory structure.
 add_subdirectory (Hello)
 add_subdirectory (Demo)

 C:\work\cmake-2.6.2\Example>..\..\cmake\bin\cmake.exe .
 -- Check for working C compiler: cl
 -- Check for working C compiler: cl -- works
 -- Detecting C compiler ABI info
 -- Detecting C compiler ABI info - done
 -- Check for working CXX compiler: cl
 -- Check for working CXX compiler: cl -- works
 -- Detecting CXX compiler ABI info
 -- Detecting CXX compiler ABI info - done
 CMake Warning (dev) in CMakeLists.txt:
   No cmake_minimum_required command is present.  A line of code such as
 
     cmake_minimum_required(VERSION 2.6)
 
   should be added at the top of the file.  The version specified may be lower
   if you wish to support older CMake versions for this project.  For more
   information run "cmake --help-policy CMP0000".
 This warning is for project developers.  Use -Wno-dev to suppress it.
 
 -- Configuring done
 -- Generating done
 -- Build files have been written to: C:/work/cmake-2.6.2/Example

-これでunixでいうところの./configureができたわけだ。

 C:\work\cmake-2.6.2\Example>dir
 2008/11/14  15:39            19,889 ALL_BUILD.vcproj
 2008/11/14  15:39            12,427 CMakeCache.txt
 2008/11/14  15:39    <DIR>          CMakeFiles
 2008/09/24  14:46               500 CMakeLists.txt
 2008/11/14  15:39             1,740 cmake_install.cmake
 2008/11/14  15:41    <DIR>          Demo
 2008/11/14  15:40    <DIR>          Hello
 2008/11/14  15:41           191,488 HELLO.ncb
 2008/11/14  15:39             4,289 HELLO.sln
 2008/11/14  15:39            18,292 ZERO_CHECK.vcproj

-このように、slnファイルが作られた。
-これをVS2005でコンパイルしたら動いた。
-これでcross platformで環境が用意できる。

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS