diff --git a/chapter16/CMakeLists.txt b/chapter16/CMakeLists.txt index 5717842..7d6a51d 100644 --- a/chapter16/CMakeLists.txt +++ b/chapter16/CMakeLists.txt @@ -9,7 +9,7 @@ project( VERSION 1.0 DESCRIPTION "Examples for chapter 16 of the CMake Best Practices book" - LANGUAGES CXX + LANGUAGES CXX OBJCXX ) # The examples in this chapter are apple specific diff --git a/chapter16/app_bundle_example/CMakeLists.txt b/chapter16/app_bundle_example/CMakeLists.txt index cd4b275..e24207f 100644 --- a/chapter16/app_bundle_example/CMakeLists.txt +++ b/chapter16/app_bundle_example/CMakeLists.txt @@ -6,7 +6,7 @@ project( VERSION 1.0 DESCRIPTION "A simple C++ project to demonstrate an apple ui" - LANGUAGES CXX + LANGUAGES CXX OBJCXX ) # Add the executable diff --git a/chapter16/app_bundle_storyboard/CMakeLists.txt b/chapter16/app_bundle_storyboard/CMakeLists.txt new file mode 100644 index 0000000..51cd1ab --- /dev/null +++ b/chapter16/app_bundle_storyboard/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.25) + +# Project name and version +project( + ch16_app_bundle_storyboard + VERSION 1.0 + DESCRIPTION + "A simple C++ project to demonstrate an apple ui" + LANGUAGES CXX OBJCXX +) + +set(resource_files + ${CMAKE_CURRENT_SOURCE_DIR}/storyboards/Main.storyboard +) + +# Add the executable +add_executable(ch16_app_bundle_storyboard MACOSX_BUNDLE src/main.mm) +target_sources(ch16_app_bundle_storyboard PRIVATE ${resource_files}) + +set_source_files_properties(${resource_files} PROPERTIES MACOSX_PACKAGE_LOCATION Resources) diff --git a/chapter16/app_bundle_storyboard/src/main.mm b/chapter16/app_bundle_storyboard/src/main.mm new file mode 100644 index 0000000..8638e55 --- /dev/null +++ b/chapter16/app_bundle_storyboard/src/main.mm @@ -0,0 +1,55 @@ +#import + +// AppDelegate Interface +@interface AppDelegate : UIResponder + +@property(strong, nonatomic) UIWindow *window; + +@end + +// ViewController Interface +@interface ViewController : UIViewController + +@end + +// ViewController Implementation +@implementation ViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + // Additional setup if needed + UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(50, 200, 300, 50)]; + label.text = @"Hello, World!"; + label.textAlignment = NSTextAlignmentCenter; + [self.view addSubview:label]; +} + +@end + +// AppDelegate Implementation +@implementation AppDelegate + +- (BOOL)application:(UIApplication *)application + didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + + UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" + bundle:nil]; + ViewController *viewController = + [storyboard instantiateViewControllerWithIdentifier:@"ViewController"]; + + self.window.rootViewController = viewController; + [self.window makeKeyAndVisible]; + + return YES; +} + +@end + +// Main +int main(int argc, char *argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, + NSStringFromClass([AppDelegate class])); + } +} diff --git a/chapter16/app_bundle_storyboard/storyboard/main.storyboard b/chapter16/app_bundle_storyboard/storyboard/main.storyboard new file mode 100644 index 0000000..865b36b --- /dev/null +++ b/chapter16/app_bundle_storyboard/storyboard/main.storyboard @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/chapter16/hello_world_apple/CMakeLists.txt b/chapter16/hello_world_apple/CMakeLists.txt index 4bb0888..3e110cb 100644 --- a/chapter16/hello_world_apple/CMakeLists.txt +++ b/chapter16/hello_world_apple/CMakeLists.txt @@ -6,7 +6,7 @@ project( VERSION 1.0 DESCRIPTION "A simple C++ project to demonstrate an apple ui" - LANGUAGES CXX + LANGUAGES CXX OBJCXX ) # set some global XCode properties