4
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

cmakeチートシート

Posted at

CMakeLists.txtの最小例

CMakeLists.txt
project(test)
cmake_minimum_required(VERSION 3.10)

find_package(Eigen3 REQUIRED)
add_executable(hoge a.cpp)
include_directories(${EIGEN3_INCLUDE_DIRS})
a.cpp
# include <Eigen/Core>
# include <iostream>

int main() {
  const Eigen::MatrixXd eye = Eigen::MatrixXd::Zero(2, 4);
  std::cout << eye << std::endl;
}

cmake --help-command-listすると,CMakeLists.txt内で使うコマンドの一覧が見れる.

out-of-source buildをcdせずに行う

cmake -Bbuild -H.
make -C build

find_package(XXX)XXXに書くべき文言を思い出したい場合

まずは,cmakeがデフォルトで持っているfind_packageの対象を探してみる.

cmake --help-module-list

これは/usr/share/cmake-3.10/Modulesを見ているっぽい.

自分でインストールしたパッケージのfind_package

pkg-config --list-all

で探せる.

pkg-configのHPは https://www.freedesktop.org/wiki/Software/pkg-config/ みたい.
探索PATHは

  • /usr/share/pkgconfig/
  • /usr/lib/x86_64-linux-gnu/pkgconfig

とかみたい.

pkg-configを使って見つける場合

CMakeLists.txt
project(test)
cmake_minimum_required(VERSION 3.10)

find_package(PkgConfig)
pkg_check_modules(EIGEN3 eigen3)
add_executable(hoge a.cpp)
include_directories(${EIGEN3_INCLUDE_DIRS})

Eigenは

  • /usr/lib/cmake/eigen3/Eigen3Config.cmake
  • /usr/share/pkgconfig/eigen3.pc

2つの探し方用のファイルがあるので,一番最初のようにfind_packageでも探せるし,pkg_check_modulesでも探せる.

4
7
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?