1
1

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 1 year has passed since last update.

【ROS】2分でCMakeを更新する方法【Ubuntu】

Last updated at Posted at 2022-11-07

こちらに【新記事】 apt install で入れる方法があります。
https://qiita.com/sunrise_lover/items/810977fede4b979c382b

本ページでは、バイナリファイルを直接叩く方法を紹介しています。
が、基本的には新記事の方法が推奨です。


apt版 CMakeが古すぎて、新機能が使えない

まずターミナルで
$ cmake --version
と打ってバージョンを確認しましょう。

3.10と出た人はきっとUbuntu公式サーバーのcmakeをaptインストールした人です。
残念ながら、もうUbuntu公式サーバーはcmakeを更新しなくなりました…。なぜなんだ

以下の手順に従えば、catkin_makeやcatkin buildから呼び出されるcmakeのバージョンを更新できます。
aptの依存関係も保持するので、aptで入れたrosパッケージの依存関係も壊れません。

$ cd ~

$ mkdir cmake  #ホーム下にcmakeディレクトリを作成します

$ wget https://github.com/Kitware/CMake/releases/download/v3.24.3/cmake-3.24.3-linux-x86_64.sh # 自動スクリプトを公式サイトからダウンロード

$ chmod +x cmake-3.24.3-linux-x86_64.sh # 実行権限を付与

$ sudo mv cmake-3.24.3-linux-x86_64.sh /opt/ # optに移動

$ cd /opt

$ sudo ./cmake-3.24.3-linux-x86_64.sh # スクリプト実行。途中で2回yesを入力

$ cd cmake-3.24.3-linux-x86_64/ # /opt/に新しくcmakeのディレクトリが作成されており、binaryデータまでダウンロードが完了している

$ sudo ln -s /opt/cmake-3.24.3-linux-x86_64/bin/* /usr/local/bin/ # リンカを生成してcmakeコマンドの実行参照を差し替える

$ cmake --version # バージョンが上がっていれば成功!

Ubuntu公式はCMakeの更新をサボっている。

残念ながらapt install cmakeはver3.10以降更新されていません…。

しかしtarget_link_directoriesなどCMakeの新機能が入ったCMakeLists.txtをcmakeするには、どうしても最新版cmakeが必要…
非常に悩ましいですね。

よくある記事では$ apt purge (or remove) cmakeしています。
これがROSユーザーにとって極めて問題で、catkin build がcmakeに依存している以上、結構マズい事態になります。
aptの依存関係を保持するためには古いcmakeを保持する必要があります。

今回はリンカによる差し替えで、古いCMakeも残ります。
上の方法で手動更新すれば、皆さんのROS環境は壊れません。

リンカをuser/local/binに置く

Linuxではusr/binよりもusr/localの方が優先度が高く、先に探しに行くので、これだけで新しいcmakeを読むように差し替えれます。

1
1
0

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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?