title: CMakeLists.txt for an Objective C Project
body: <p>I am working on simply creating a hello world executable on OSX using Objective-C and CMake. I'm new to both so I'd appreciate any advice. I understand that CMake does not natively support building Objective-C. You must first add the </p>
  
  <pre><code>set(CMAKE_C_FLAGS "-x objective-c")
  </code></pre>
  
  <p>or </p>
  
  <pre><code>set(CMAKE_CXX_FLAGS "-x objective-c++")
  </code></pre>
  
  <p>for the Makefile to even be created. The part where I'm getting stuck is how to appropriately link the existing frameworks. I've followed both the instructions in this post as well as the tutorial it's based off of: <a href="https://stackoverflow.com/questions/12547624/cant-link-macos-frameworks-with-cmake">Can&#39;t link MacOS frameworks with CMake</a>
  I've also tried linking the libraries with:</p>
  
  <pre><code>set(CMAKE_EXE_LINKER_FLAGS "-framework fm1-framework fm2…")
  </code></pre>
  
  <p>I can now get a successful CMake generated Xcode project, but when I open the project, none of the frameworks I specified in the CMakeLists.txt file are in the 'resources' folder. Using this Xcode project, I can get the project to compile, but when I run the executable I get the error:</p>
  
  <p>"2014-01-06 18:02:35.859 HelloWorld[62641:303] No Info.plist file in application bundle or no NSPrincipalClass in the Info.plist file, exiting
  Program ended with exit code: 1"</p>
  
  <p>I also tried manually running the makefile made by CMake in the terminal and got many many warnings (during linking) all saying:</p>
  
  <blockquote>
    <p>CMakeFiles/HelloWorld.dir/AppDelegate.m.o:3:2252: warning: null character
         ignored [-Wnull-character]
     ...</p>
    
    <p>CMakeFiles/HelloWorld.dir/AppDelegate.m.o:3:2263: warning: null character
         ignored [-Wnull-character]
     ...</p>
  </blockquote>
  
  <p>And 7 errors (during linking):</p>
  
  <blockquote>
    <p>CMakeFiles/HelloWorld.dir/AppDelegate.m.o:1:1: error: expected unqualified-id
    </p>
    
    <p>CMakeFiles/HelloWorld.dir/AppDelegate.m.o:3:90: error: expected unqualified-id
     ...H&lt;89>uH&lt;89>U]fffff.&lt;84></p>
    
    <p>CMakeFiles/HelloWorld.dir/AppDelegate.m.o:3:121: error: extraneous closing brace
         ('}')
     ...}H&lt;89>uH&lt;8B>uH&lt;8B>=</p>
    
    <p>CMakeFiles/HelloWorld.dir/AppDelegate.m.o:3:122: error: expected unqualified-id
     ...H&lt;89>uH&lt;8B>uH&lt;8B>=</p>
    
    <p>CMakeFiles/HelloWorld.dir/AppDelegate.m.o:3:169: error: extraneous closing brace
         ('}')
     ...}H&lt;89>uH&lt;89>UH&lt;8B>uH&lt;8B>=</p>
    
    <p>CMakeFiles/HelloWorld.dir/AppDelegate.m.o:3:170: error: expected unqualified-id
     ...H&lt;89>uH&lt;89>UH&lt;8B>uH&lt;8B>=</p>
    
    <p>CMakeFiles/HelloWorld.dir/AppDelegate.m.o:3:2246: error: expected unqualified-id
     ...16@0:8</p>
  </blockquote>
  
  <p>Any ideas on what I'm during wrong? I've spent the better portion of the day looking for answers and the post I referenced had the most useful information, but it still didn't fix my problem. Is it because the original program is also written in Xcode? And somehow that's messing up the CMake?</p>
  
  <p>Here's the code for my HelloWorld app:</p>
  
  <pre><code>#import &lt;Cocoa/Cocoa.h&gt;
  
  int main(int argc, const char * argv[])
  {
      return NSApplicationMain(argc, argv);
  }
  </code></pre>
  
  <p>And the code for the CMakeLists.txt file:</p>
  
  <pre><code>cmake_minimum_required(VERSION 2.8)
  project(HelloWorld)
  
  set(src_files
     AppDelegate.h
     AppDelegate.m
     main.m
  )
  
  set(CMAKE_C_FLAGS "-x objective-c")
  set(CMAKE_CXX_FLAGS "-x objective-c++")
  set(CMAKE_EXE_LINKER_FLAGS "-framework Cocoa -framework AppKit -framework CoreData -     framework Foundation")
  
  add_executable(HelloWorld 
     ${src_files}
  )
  </code></pre>
  
  <p>Thanks in advance!</p>