LoginSignup
20
23

More than 5 years have passed since last update.

CocoaPods でビルド設定を追加する

Posted at

たとえば OSS によっては、デフォルトでログをはくようになっていて、それを止めたければ

#define XX_ENABLE_XXX_LOGGING 0

みたいな定義を pch ファイルに追加するとか、ビルド設定の [Preprocessor Macros] に同様の定義を追加するとかしてね、という仕様になっているケースがあります。

ところがこれを CocoaPods 経由でやろうとすると、pch ファイルも、ビルド設定が含まれている .xcodeproj パッケージも、

pod install

で Pods フォルダに自動生成されるものなので、あらかじめそれらを編集しておくということができません。

となると pod install 後にビルド設定を追記する 必要があるわけですが、CocoaPods にちゃんとそういうしくみが用意されています。

post_install | CocoaPods Guides - Podfile Syntax Reference

たとえば上記の例で言うと、次のように Podfile に追記します。

post_install do |installer|

  POD_TARGET_NAME = "Pods-XXxxxx"

  # Search the build target
  classy_pods_target = installer.project.targets.find{ |target| target.name == POD_TARGET_NAME }
  unless classy_pods_target
    raise ::Pod::Informative, "Failed to find '" << POD_TARGET_NAME << "' target"
  end

  # Add the build setting
  classy_pods_target.build_configurations.each do |config|
    config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
    config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'XX_ENABLE_XXX_LOGGING = 0'
  end

end

参考記事:

20
23
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
20
23