Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define header search path in cocoapods podspec file

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?

like image 773
Denis Loh Avatar asked Jan 15 '14 08:01

Denis Loh


1 Answers

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
like image 52
ERU Avatar answered Nov 12 '22 04:11

ERU