CMake学習入門


CMake学習入門
コンフィギュレーション
  • CMakeList.txt構成
  • 構成cmakeバージョン要件
  • 配置工事
  • 実行可能ファイル
  • を追加
  • note:cmakeファイル大文字小文字を区別しない
  • 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