8

I have an issue with the definition of my podspec file for the framework I created. I have the following file structure:

/
|-- module1/<source files>
|-- module2/<source files>
...
|-- moduleN/<source files>
|-- core-api/
|    |-- module1/<header files>
|    |-- module2/<header files>
|    ...
|    +-- moduleN/<header files>
|-- framework.podspec
+-- framework.xcodeproj

In XCode I added $(SRCROOT)/core-api to the USER_HEADER_SEARCH_PATHS so that Xcode can find the public header files correctly.

My podspec file looks like this:

s.default_subspec = 'module1'

s.subspec 'module1' do |ss|
  ss.source_files               = "module1/**/*.{h,m}"
end

s.subspec 'module2' do |ss|
  ss.source_files               = "module2/**/*.{h,m}"
end

...

s.subspec 'moduleN' do |ss|
  ss.source_files               = "moduleN/**/*.{h,m}"
end

Currently, there are no directives which define the header location for the core-api. When I do pod lib lint I get errors that the corresponding core-api headers weren't found.

I was messing around with ss.header_dir, ss.header_mapping_dir, s.xcconfig with USER_HEADER_SEARCH_PATH, but none of them worked for me.

How do I define the location of the header files in a podspec file correctly?

EDIT1:

I re-created the spec file from scratch and found out, that it seems to be necessary to add the core-api header files in each sub spec.

My spec file looks now like this:

s.default_subspec = 'module1'

s.subspec 'module1' do |ss|
  ss.public_header_files        = "core-api/module1/*.h"
  ss.source_files               = "module1/**/*.{h,m}"
end

s.subspec 'module2' do |ss|
  ss.public_header_files        = "core-api/module1/*.h"
  ss.source_files               = "module2/**/*.{h,m}"
end

...

s.subspec 'moduleN' do |ss|
  ss.public_header_files        = "core-api/module1/*.h"
  ss.source_files               = "moduleN/**/*.{h,m}"
end

However, in this case the headers of the modules are only added, if I want to use the subspec. If I just want to use module1 and 2, the headers of the other modules are missing. The core-api headers folder must always be available to all modules in the framework. How do I do that?

Denis Loh
  • 2,194
  • 2
  • 24
  • 38

2 Answers2

3

https://stackoverflow.com/a/33359337/4063462

Correct podspec file should looks like this:

s.default_subspec = 'module1'

s.subspec 'module1' do |ss|
  ss.xcconfig = { 'USER_HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/core-api/module1/*.h"' }
  ss.source_files               = "module1/**/*.{h,m}"
end

s.subspec 'module2' do |ss|
  ss.xcconfig = { 'USER_HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/core-api/module1/*.h"' }
  ss.source_files               = "module2/**/*.{h,m}"
end

...

s.subspec 'moduleN' do |ss|
  ss.xcconfig = { 'USER_HEADER_SEARCH_PATHS' => '"${PODS_ROOT}/core-api/module1/*.h"' }
  ss.source_files               = "moduleN/**/*.{h,m}"
end
Community
  • 1
  • 1
Tong
  • 870
  • 10
  • 19
0

You can define a subspec as dependency of another subspec:

Pod::Spec.new do |s|
  s.name = 'RestKit'

  s.subspec 'Core' do |cs|
    cs.dependency 'RestKit/ObjectMapping'
    cs.dependency 'RestKit/Network'
    cs.dependency 'RestKit/CoreData'
  end

  s.subspec 'ObjectMapping' do |os|
  end
end

source: Podspec syntax reference

teriiehina
  • 4,741
  • 3
  • 41
  • 63