CMake学習入門
CMake学習入門
コンフィギュレーション CMakeList.txt構成 構成cmakeバージョン要件 配置工事 実行可能ファイル を追加 note:cmakeファイル大文字小文字を区別しない バージョン番号設定、 を使用ヘッダファイル に連絡します.
note:CMakeがこのヘッダファイルを構成する場合、'@Tutorial_VERSION_MAJOR@"と"@Tutorial_VERSION_MINOR@"の値はCMakeListsになる.txtファイルの値の置換
ライブラリを追加は が存在する.最上位ディレクトリの を追加する.依存を追加オプション リンクディレクトリ を調整する.工事で を追加する必要がある.
コンフィギュレーション
cmake_minimum_required(VERSION 2.6)
project(Tutorial)
add_executable(Tutorial tutorial.cxx)
set()
関数# The version number
set(Tutorial_VERSION_MAJOR 1)
set(Tutorial_VERSION_MINOR 0)
# configure a header file to pass some of the CMake settings to the source code
configure_file(
"${PROJECT_SOURCE_DIR}/TutorialConfig.h.in"
"${PROJECT_BINARY_DIR}/TuturialConfig.h"
)
# add the binary tree to the search path for include files so that we will find TutorialConfig.h
include_directories("${PROJECT_BINARY_DIR}")
.in
ファイルを追加し、エンジニアリングファイルとcmakelistのファイル//the configured options and settings for Tutorial
#define Tutorial_VERSION_MAJOR @Tutorial_VERSION_MAJOR@
#define Tutorial_VERSION_MINOR @Tutorial_VERSION_MINOR@
note:CMakeがこのヘッダファイルを構成する場合、'@Tutorial_VERSION_MAJOR@"と"@Tutorial_VERSION_MINOR@"の値はCMakeListsになる.txtファイルの値の置換
ライブラリを追加
add_library()
関数によって実現されるMathFunctions
のファイルの下に、mysqrt.cxx
add_library(MathFunctions mysqrt.cxx)
cmakelist.txt
にリンクディレクトリinclude_directories ("${PROJECT_SOURCE_DIR}/MathFunctions")
add_subdirectory (MathFunctions)
# add the executable
add_executable (Tutorial tutorial.cxx)
target_link_libraries (Tutorial MathFunctions)
# should we use our own math functions?
option (USE_MYMATH
"Use tutorial provided math implementation" ON)
# add the MathFunctions library?
#
if (USE_MYMATH)
include_directories ("${PROJECT_SOURCE_DIR}/MathFunctions")
add_subdirectory (MathFunctions)
set (EXTRA_LIBS ${EXTRA_LIBS} MathFunctions)
endif (USE_MYMATH)
# add the executable
add_executable (Tutorial tutorial.cxx)
target_link_libraries (Tutorial ${EXTRA_LIBS})
USE_MYMATH
を使用するためには、.in
ファイルに次のコマンド#cmakedefine USE_MYMATH