diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9e3d7cc45..fb75682c3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -26,6 +26,12 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DDEBUG=1")
# TODO: Clang Analyzer, Tidy ...
+if(${BUILD_SHARED_LIBS})
+ set(NATIVESCRIPT_LIBRARY_TYPE SHARED)
+else()
+ set(NATIVESCRIPT_LIBRARY_TYPE STATIC)
+endif()
+
add_subdirectory(src/NativeScript)
add_subdirectory(examples/Gameraww)
add_subdirectory(examples/BlankApp)
diff --git a/build/build.sh b/build/build.sh
index 93e71c463..25fcb3ded 100755
--- a/build/build.sh
+++ b/build/build.sh
@@ -30,3 +30,20 @@ cp \
$NATIVESCRIPT_DIR/TNSRuntime.h \
$NATIVESCRIPT_DIR/TNSRuntime+Inspector.h \
$WORKSPACE/dist/NativeScript/include
+
+cmake .. -DCMAKE_OSX_SYSROOT=iphonesimulator $CMAKE_FLAGS -DBUILD_SHARED_LIBS=YES
+cmake --build . --config Release --target NativeScript
+
+cmake .. -DCMAKE_OSX_SYSROOT=iphoneos $CMAKE_FLAGS -DBUILD_SHARED_LIBS=YES
+cmake --build . --config Release --target NativeScript
+
+echo "Packaging NativeScript-Shared..."
+mkdir -p $WORKSPACE/dist/NativeScriptEmbedded/Release
+cp -r $WORKSPACE/cmake-build/src/NativeScript/Release-iphoneos/NativeScript.framework $WORKSPACE/dist/NativeScriptEmbedded/Release
+
+mkdir -p $WORKSPACE/dist/NativeScriptEmbedded/Debug
+cp -r $WORKSPACE/dist/NativeScriptEmbedded/Release/NativeScript.framework $WORKSPACE/dist/NativeScriptEmbedded/Debug
+rm $WORKSPACE/dist/NativeScriptEmbedded/Debug/NativeScript.framework/NativeScript
+lipo -create -output $WORKSPACE/dist/NativeScriptEmbedded/Debug/NativeScript.framework/NativeScript \
+ $WORKSPACE/cmake-build/src/NativeScript/Release-iphonesimulator/NativeScript.framework/NativeScript \
+ $WORKSPACE/cmake-build/src/NativeScript/Release-iphoneos/NativeScript.framework/NativeScript
diff --git a/examples/TodayExtension/Info.plist b/examples/TodayExtension/Info.plist
new file mode 100644
index 000000000..3c32743fc
--- /dev/null
+++ b/examples/TodayExtension/Info.plist
@@ -0,0 +1,33 @@
+
+
+
+
+ CFBundleDevelopmentRegion
+ en
+ CFBundleDisplayName
+ TodayExtension
+ CFBundleExecutable
+ $(EXECUTABLE_NAME)
+ CFBundleIdentifier
+ org.nativescript.$(PRODUCT_NAME:rfc1034identifier)
+ CFBundleInfoDictionaryVersion
+ 6.0
+ CFBundleName
+ $(PRODUCT_NAME)
+ CFBundlePackageType
+ XPC!
+ CFBundleShortVersionString
+ 1.0
+ CFBundleSignature
+ ????
+ CFBundleVersion
+ 1
+ NSExtension
+
+ NSExtensionPointIdentifier
+ com.apple.widget-extension
+ NSExtensionPrincipalClass
+ TNSTodayExtension
+
+
+
diff --git a/examples/TodayExtension/app/bootstrap.js b/examples/TodayExtension/app/bootstrap.js
new file mode 100644
index 000000000..1efb797c4
--- /dev/null
+++ b/examples/TodayExtension/app/bootstrap.js
@@ -0,0 +1,17 @@
+UIViewController.extend({
+ loadView: function() {
+ this.view = new UIView(CGRectMake(0, 0, 320, 200));
+ },
+ viewDidLoad: function() {
+ UIViewController.prototype.viewDidLoad.apply(this, arguments);
+ this.preferredContentSize = CGSizeMake(0, 200);
+
+ var label = new UILabel(CGRectMake(0, 0, 250, 60));
+ label.text = "Hello, World!";
+ label.textColor = UIColor.whiteColor();
+
+ this.view.addSubview(label);
+ }
+}, {
+ name: "TNSTodayExtension"
+});
diff --git a/examples/TodayExtension/main.m b/examples/TodayExtension/main.m
new file mode 100644
index 000000000..19fc98db8
--- /dev/null
+++ b/examples/TodayExtension/main.m
@@ -0,0 +1,21 @@
+//
+// main.m
+// TodayExtension
+//
+// Created by Jason Zhekov on 5/7/15.
+// Copyright (c) 2015 Telerik. All rights reserved.
+//
+
+#import
+#import
+
+static TNSRuntime* runtime;
+
+// TODO: The order between this constructor and MetadataFile constructor is random
+__attribute__((constructor))
+static void initRuntime() {
+ runtime = [[TNSRuntime alloc] initWithApplicationPath:[NSBundle mainBundle].bundlePath];
+ TNSRuntimeInspector.logsToSystemConsole = YES;
+
+ [runtime executeModule:@"./"];
+}
diff --git a/src/NativeScript/CMakeLists.txt b/src/NativeScript/CMakeLists.txt
index 6cb41c0f0..be619bad8 100644
--- a/src/NativeScript/CMakeLists.txt
+++ b/src/NativeScript/CMakeLists.txt
@@ -162,13 +162,36 @@ set_target_properties(NativeScript PROPERTIES
-Werror -Wall -Wextra -Wcast-align -Wformat-security -Wmissing-format-attribute -Wpointer-arith -Wundef -Wwrite-strings
-Wno-shorten-64-to-32 -Wno-bool-conversion -Wno-unused-parameter
"
- STATIC_LIBRARY_FLAGS "
- -lJavaScriptCore -L\"${WEBKIT_DIR}/lib\"
- -lffi -L\"${LIBFFI_DIR}/lib\"
- "
- XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN YES
+ XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET "7.0"
)
+if(${NATIVESCRIPT_LIBRARY_TYPE} STREQUAL "STATIC")
+ set_target_properties(NativeScript PROPERTIES
+ STATIC_LIBRARY_FLAGS "
+ -lJavaScriptCore -L\"${WEBKIT_DIR}/lib\"
+ -lffi -L\"${LIBFFI_DIR}/lib\"
+ "
+ XCODE_ATTRIBUTE_GCC_SYMBOLS_PRIVATE_EXTERN YES
+ )
+elseif(${NATIVESCRIPT_LIBRARY_TYPE} STREQUAL "SHARED")
+ set_target_properties(NativeScript PROPERTIES
+ FRAMEWORK TRUE
+ FRAMEWORK_VERSION "1.0" # TODO
+ PUBLIC_HEADER "NativeScript.h;TNSRuntime.h;TNSRuntime+Inspector.h" # TODO
+ INSTALL_NAME_DIR "@executable_path/Frameworks"
+ XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer"
+ MACOSX_FRAMEWORK_IDENTIFIER "org.nativescript.NativeScript"
+ )
+ target_link_libraries(NativeScript
+ -lJavaScriptCore -L"${WEBKIT_DIR}/lib"
+ -lffi -L"${LIBFFI_DIR}/lib"
+ "-framework UIKit"
+ libicucore.dylib
+ libz.dylib
+ libc++.dylib
+ )
+endif()
+
include(EmbedResourceInHeader)
foreach(_jsfile ${JSFILES})
EmbedResourceInHeader(NativeScript ${_jsfile})
diff --git a/src/NativeScript/Metadata/MetaFile.mm b/src/NativeScript/Metadata/MetaFile.mm
index f38bbd786..7ee04a704 100644
--- a/src/NativeScript/Metadata/MetaFile.mm
+++ b/src/NativeScript/Metadata/MetaFile.mm
@@ -9,6 +9,7 @@
#include "MetaFile.h"
#include
#include
+#include
namespace Metadata {
@@ -17,6 +18,10 @@
void* loadFile(const char* filePath) {
const char* path = [[[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:[NSString stringWithUTF8String:filePath]] UTF8String];
int fd = open(path, O_RDONLY);
+ if (fd == -1) {
+ perror("Could not load metadata file");
+ exit(1);
+ }
struct stat fileStat;
fstat(fd, &fileStat);
void* file = mmap(NULL, (size_t)fileStat.st_size, PROT_READ, MAP_PRIVATE, fd, 0);