DEBUG preprocessor macro not defined for CocoaPods targets

后端 未结 5 782
灰色年华
灰色年华 2020-12-29 07:01

I\'m having issues with a pod called DCIntrospect-ARC which should only work in DEBUG mode. It checks if the DEBUG macro is defined before running. However, it is not define

5条回答
  •  生来不讨喜
    2020-12-29 07:39

    Thanks to John I completed my custom Podfile script, which also changes the optimization level to zero and enables assertions.

    I've got multiple debug configurations (for ACC and PROD), so I needed to update several properties for debugging purposes.

    post_install do |installer|
      installer.pods_project.build_configurations.each do |config|
        if config.name.include?("Debug")
          # Set optimization level for project
          config.build_settings['GCC_OPTIMIZATION_LEVEL'] = '0'
    
          # Add DEBUG to custom configurations containing 'Debug'
          config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
          if !config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'].include? 'DEBUG=1'
            config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'DEBUG=1'
          end
        end
      end
    
      installer.pods_project.targets.each do |target|
        target.build_configurations.each do |config|
          if config.name.include?("Debug")
            # Set optimization level for target
            config.build_settings['GCC_OPTIMIZATION_LEVEL'] = '0'
            # Add DEBUG to custom configurations containing 'Debug'
            config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)']
            if !config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'].include? 'DEBUG=1'
              config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] << 'DEBUG=1'
            end
            # Enable assertions for target
            config.build_settings['ENABLE_NS_ASSERTIONS'] = 'YES'
    
            config.build_settings['OTHER_CFLAGS'] ||= ['$(inherited)']
            if config.build_settings['OTHER_CFLAGS'].include? '-DNS_BLOCK_ASSERTIONS=1'
              config.build_settings['OTHER_CFLAGS'].delete('-DNS_BLOCK_ASSERTIONS=1')
            end
          end
        end
      end
    end
    

提交回复
热议问题