ROS cmakelist解読(公式)
3210 ワード
ROSではcmakelistがC++とは異なり,少し記録されている.
まずは順番
cmakelist作成順序 Required CMake Version(cmake_minimum_required)//cmakeバージョン Package Name(project()/パッケージの名前は、プロジェクト名でもあり、その後、プロジェクト名を使用する必要がある場合に${PROJECT_NAME}で置き換えることができます.メリットは、プロジェクト名を変更する場合、ここの名前を変更するだけで、後続の名前が変更されることです. Find other CMake/Catkin packages needed for build(find_package()/依存パッケージを検索し、パッケージを見つけたエクスポートパス、ライブラリファイルなどを与えます. Enable Python module support (catkin_python_setup()) Message/Service/Action Generators(add_message_files(), add_service_files(), add_action_files()) Invoke message/service/action generation (generate_messages()) Specify package build info export (catkin_package()) Libraries/Executables to build (add_library()/add_executable()/target_link_libraries()) Tests to build (catkin_add_gtest()) Install rules (install())
上記の手順でcmakelistの作成を行わなければなりません.そうしないと、エラーが発生する可能性があります.
find_パッケージは変数名を返します
_: _FOUND - Set to true if the library is found, otherwise false _INCLUDE_DIRS or _INCLUDES - The include paths exported by the package _LIBRARIES or _LIBS - The libraries exported by the package _DEFINITIONS -
find_の使用package(catkin REQUIRE COMPONENTS pack_name)のメリットは、include paths、librariesなどにcatkin_を追加できることです接頭辞例えばcatkin_INCLUDE_DIRSは環境変数に加えて使いやすい.
元のものを使えば
nodelet_が生成されますINCLUDE_DIRS,nodelet_LIBRARIES等の環境変数
catkin_パッケージに関する情報
catkinが提供するCMakeマクロで、buildシステムに対してcatkinの情報を具体的に説明してpkg-configとCMakeファイルを生成する必要があります.
そしてcatkin_package()はadd_に書かなければなりませんlibrary()またはadd_executable()の前に、5つのオプションパラメータがあります. INCLUDE_DIRS - The exported include paths (i.e. cflags) for the package LIBRARIES - The exported libraries from the project CATKIN_DEPENDS - Other catkin projects that this project depends on DEPENDS - Non-catkin CMake projects that this project depends on. For a better understanding, see this explanation. CFG_EXTRAS - Additional configuration options
Include Paths and Library Paths Include Paths - Where can header files be found for the code (most common in C/C++) being built Library Paths - Where are libraries located that executable target build against? include_directories(,,...,)ここでfind_を使いますパッケージによって生成される環境変数またはその他のディレクトリ、例:include_directories(include${catkin_INCLUDE_DIRS})${catkin_INCLUDE_DIRS}は、上記で生成されたパス環境変数を意味し、最初の変数includeはinclude/ディレクトリの下にあるものもパスの一部を表す. link_Directories(,,...,)もパスを追加しますが、推奨しません.
Executable Targets
Library Targets(デフォルトでは共有ライブラリが作成されています)
target_link_libraries
リンクするライブラリを指定し、一般的にadd_に配置します.executable()の後、例:
まずは順番
cmakelist作成順序
上記の手順でcmakelistの作成を行わなければなりません.そうしないと、エラーが発生する可能性があります.
find_パッケージは変数名を返します
_:
find_の使用package(catkin REQUIRE COMPONENTS pack_name)のメリットは、include paths、librariesなどにcatkin_を追加できることです接頭辞例えばcatkin_INCLUDE_DIRSは環境変数に加えて使いやすい.
元のものを使えば
find_package(catkin REQUIRED COMPONENTS nodelet)
nodelet_が生成されますINCLUDE_DIRS,nodelet_LIBRARIES等の環境変数
catkin_パッケージに関する情報
catkinが提供するCMakeマクロで、buildシステムに対してcatkinの情報を具体的に説明してpkg-configとCMakeファイルを生成する必要があります.
そしてcatkin_package()はadd_に書かなければなりませんlibrary()またはadd_executable()の前に、5つのオプションパラメータがあります.
Include Paths and Library Paths
Executable Targets
add_executable(myProgram src/main.cpp src/some_file.cpp src/another_file.cpp)
Library Targets(デフォルトでは共有ライブラリが作成されています)
add_library(${PROJECT_NAME} ${${PROJECT_NAME}_SRCS})
target_link_libraries
リンクするライブラリを指定し、一般的にadd_に配置します.executable()の後、例:
add_executable(foo src/foo.cpp)
add_library(moo src/moo.cpp)
target_link_libraries(foo moo) -- This links foo against libmoo.so