title: Swift Package Manager: add compile flag to a single file -fno-objc-arc
body: <p><strong>Overview</strong></p>
  <p>I'm porting an C++ / ObjC++ library to Swift Package Manager. The library targets common Apple platforms (iOS, macOS). Currently, the library can be built using <code>xcodebuild</code> and a static library target.</p>
  <p><strong>Question</strong></p>
  <p>Since the library contains C++ &lt;&gt; ObjC bridging code, it has <strong>one file</strong> compiled with the flag <code>-fno-objc-arc</code>. All of the other files are compiled with ARC. Is it possible to pass a flag telling SPM to also compile that file without ARC?</p>
  <p><strong>Screenshot</strong></p>
  <p><a href="https://i.stack.imgur.com/lPbq3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lPbq3.png" alt="screenshot" /></a></p>
  <p><strong>Package.swift</strong></p>
  <pre><code>// swift-tools-version:5.4
  // The swift-tools-version declares the minimum version of Swift required to build this package.
  
  import PackageDescription
  
  let package = Package(
      name: &quot;library_name&quot;,
      platforms: [
          .iOS(.v13)
      ],
      products: [
          .library(
              name: &quot;library_name&quot;,
              targets: [&quot;library_name&quot;]),
      ],
      dependencies: [
      ],
      targets: [
          .target(
              name: &quot;library_name&quot;,
              dependencies: [],
              path: &quot;./sources/&quot;,
              exclude: [
  
              ],
              sources:
                  [
                      &quot;sourcefile_noARC.mm&quot;,
                      &quot;sourcefile2.mm&quot;,
                      &quot;sourcefile3.cpp&quot;,
                  ],
              publicHeadersPath: &quot;SwiftPackage/headers/&quot;,
              cxxSettings: [
                  .headerSearchPath(&quot;./&quot;)
              ]
          ),
      ],
      cxxLanguageStandard: .cxx14
  )
  
  </code></pre>
  <p><strong>&quot;Unsafe Flags&quot;</strong></p>
  <p>I've tried using <a href="https://developer.apple.com/documentation/swift_packages/cxxsetting/3112675-unsafeflags" rel="nofollow noreferrer">unsafe flags</a> feature to pass the compile flag to the whole library:</p>
  <pre><code>.target(
              name: &quot;fs_helpers&quot;,
              dependencies: [],
              path: &quot;./sources/&quot;,
              exclude: [
  
              ],
              sources:
                  [
                      &quot;sourcefile_noARC.mm&quot;,
                      &quot;sourcefile2.mm&quot;,
                      &quot;sourcefile3.cpp&quot;,
                  ],
              publicHeadersPath: &quot;SwiftPackage/headers/&quot;,
              cxxSettings: [
                  .headerSearchPath(&quot;./&quot;),
                  .unsafeFlags([&quot;-fno-objc-arc&quot;]) // ADDING THE FLAG
              ]
          ),
  </code></pre>
  <p>However, this adds the flag to the whole library and not just to a single file as I want.</p>