Help us understand the problem. What is going on with this article?

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

More than 5 years have passed since last update.

たとえば 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

参考記事:

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした