2
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 5 years have passed since last update.

CMakeのツールチェインで変数を扱う際の注意点

Posted at

たとえば、CMakeに対応したプロジェクトを持って来た際に、もとのCMakeLists.txtを弄らずに外部から変数(CMAKE_CXX_FLAGSなど)を与えたいとします。

cmake . -G "Generator" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake

みたいな。

そんな時に活躍するのがこのcmake-toolchainsの機能ですが、この時set()を用いて変数を設定する際に気をつける必要があります。

set(CMAKE_CXX_FLAGS_DEBUG “${CMAKE_CXX_FLAGS_DEBUG} /MTd”)

このままでは実際に反映されません。CACHE指定をつけましょう

set(CMAKE_CXX_FLAGS_DEBUG “${CMAKE_CXX_FLAGS_DEBUG} /MTd” CACHE STRING “description")

変数の設定がキャッシュされるのでちゃんと有効化されます。
最高ですね

2
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
2
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?