Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excluding source files from compilation in a CocoaPods library

I'm converting a library (Unrar4iOS) to work with CocoaPods, but I'm running into a compilation problem. Most of the source files are C++ files, some of which aren't added directly to the list of project "Compile Sources", but which do get compiled via an #include. When one of them gets compiled on its own, it fails, because it depends on the file that #includes it (sort of weird, I know).

In short, I need to get the file to download into the Pods directory, but then not include it in the library's target. As far as I can tell, the source_files podspec controls both simultaneously. Is there a way to achieve this purely on the library side, without resorting to some hooks in the client project's Podfile?

like image 293
Dov Avatar asked Oct 18 '25 08:10

Dov


1 Answers

I had to list out each file that needs to compile explicitly in the source_files property, and list the files that needed to get implicitly built in the preserve_paths property. Like so:

Pod::Spec.new do |s|
  s.name          = "UnrarKit"
  ...
  s.source_files = "Classes/*.{mm,m,h}",
                   "Libraries/unrar/*.hpp",
                   "Libraries/unrar/archive.cpp",
                   "Libraries/unrar/arcread.cpp",
                   "Libraries/unrar/cmddata.cpp",
                   ...
                     # These files are built implicitly as dependencies
  s.preserve_paths = "Libraries/unrar/arccmt.cpp",
                     "Libraries/unrar/coder.cpp",
                     "Libraries/unrar/log.cpp",
                     ...
like image 174
Dov Avatar answered Oct 20 '25 23:10

Dov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!