I am working on simply creating a hello world executable on macOS using Objective-C and CMake. I understand that CMake does not natively support building Objective-C. You must first add the
set(CMAKE_C_FLAGS "-x objective-c")
or
set(CMAKE_CXX_FLAGS "-x objective-c++")
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: Can't link MacOS frameworks with CMake I've also tried linking the libraries with:
set(CMAKE_EXE_LINKER_FLAGS "-framework fm1-framework fm2…")
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:
"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"
I also tried manually running the makefile made by CMake in the terminal and got many many warnings (during linking) all saying:
CMakeFiles/HelloWorld.dir/AppDelegate.m.o:3:2252: warning: null character
ignored [-Wnull-character]
...
CMakeFiles/HelloWorld.dir/AppDelegate.m.o:3:2263: warning: null character
ignored [-Wnull-character]
...
And 7 errors (during linking):
CMakeFiles/HelloWorld.dir/AppDelegate.m.o:1:1: error: expected unqualified-id <U+0007>
CMakeFiles/HelloWorld.dir/AppDelegate.m.o:3:90: error: expected unqualified-id ...H<89>uH<89>U]fffff.<U+000F><U+001F><84>
CMakeFiles/HelloWorld.dir/AppDelegate.m.o:3:121: error: extraneous closing brace ('}') ...}H<89>uH<8B>uH<8B>=
CMakeFiles/HelloWorld.dir/AppDelegate.m.o:3:122: error: expected unqualified-id ...H<89>uH<8B>uH<8B>=
CMakeFiles/HelloWorld.dir/AppDelegate.m.o:3:169: error: extraneous closing brace ('}') ...}H<89>uH<89>UH<8B>uH<8B>=
CMakeFiles/HelloWorld.dir/AppDelegate.m.o:3:170: error: expected unqualified-id ...H<89>uH<89>UH<8B>uH<8B>=
CMakeFiles/HelloWorld.dir/AppDelegate.m.o:3:2246: error: expected unqualified-id ...16@0:8
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?
Here's the code for my HelloWorld app:
#import <Cocoa/Cocoa.h>
int main(int argc, const char * argv[])
{
return NSApplicationMain(argc, argv);
}
And the code for the CMakeLists.txt file:
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}
)