Skip to content

Commit

Permalink
Objc-runtime re-write (#181)
Browse files Browse the repository at this point in the history
* objc-runtime re-write

Cocoa version completely re-written in pure C.

Notes:
- No need to pass '-x', '-ObjC', or Cocoa framework flags to GCC anymore
- - Readme and various build files updated
- CoreGraphics.h needed for drawing windows
-Formatted with clang-format

* Made methods static for Go compatibility
  • Loading branch information
jslegendre authored and zserge committed Aug 17, 2018
1 parent 161f899 commit e94d679
Show file tree
Hide file tree
Showing 7 changed files with 403 additions and 261 deletions.
6 changes: 1 addition & 5 deletions CMakeLists.txt 100644 → 100755
Expand Up @@ -4,8 +4,7 @@ project(webview)

if(APPLE)
set(WEBVIEW_COMPILE_DEFS "-DWEBVIEW_COCOA=1")
set(WEBVIEW_COMPILE_OPTS "-ObjC")
set(WEBVIEW_LIBS "-framework Cocoa" "-framework WebKit")
set(WEBVIEW_LIBS "-framework WebKit")
elseif(WIN32)
set(WEBVIEW_COMPILE_DEFS "-DWEBVIEW_WINAPI=1")
set(WEBVIEW_LIBS "ole32 comctl32 oleaut32 uuid")
Expand All @@ -28,9 +27,6 @@ target_link_libraries(webview ${WEBVIEW_LIBS})
add_executable(webview_test WIN32 MACOSX_BUNDLE webview_test.cc)
set_target_properties(webview_test PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES CXX_EXTENSIONS NO)
find_package(Threads)
if(APPLE)
target_compile_options(webview_test PUBLIC "-ObjC++")
endif()
target_link_libraries(webview_test PRIVATE webview ${CMAKE_THREAD_LIBS_INIT})
enable_testing ()
add_test(NAME webview_test COMMAND webview_test)
2 changes: 1 addition & 1 deletion README.md 100644 → 100755
Expand Up @@ -208,7 +208,7 @@ Build it:
# Linux
$ cc main.c -DWEBVIEW_GTK=1 `pkg-config --cflags --libs gtk+-3.0 webkit2gtk-4.0` -o webview-example
# MacOS
$ cc main.c -DWEBVIEW_COCOA=1 -x objective-c -framework Cocoa -framework WebKit -o webview-example
$ cc main.c -DWEBVIEW_COCOA=1 -framework WebKit -o webview-example
# Windows (mingw)
$ cc main.c -DWEBVIEW_WINAPI=1 -lole32 -lcomctl32 -loleaut32 -luuid -mwindows -o webview-example.exe
```
Expand Down
3 changes: 0 additions & 3 deletions examples/minimal/CMakeLists.txt 100644 → 100755
Expand Up @@ -4,7 +4,4 @@ project(minimal)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../.. ${CMAKE_CURRENT_BINARY_DIR}/webview)
add_executable(minimal WIN32 MACOSX_BUNDLE main.c)
if (APPLE)
target_compile_options(minimal PRIVATE "-ObjC")
endif()
target_link_libraries(minimal PUBLIC webview)
4 changes: 2 additions & 2 deletions examples/minimal/Makefile
Expand Up @@ -11,8 +11,8 @@ else ifeq ($(shell uname -s),Linux)
WEBVIEW_CFLAGS := -DWEBVIEW_GTK=1 $(shell pkg-config --cflags gtk+-3.0 webkit2gtk-4.0)
WEBVIEW_LDFLAGS := $(shell pkg-config --libs gtk+-3.0 webkit2gtk-4.0)
else ifeq ($(shell uname -s),Darwin)
WEBVIEW_CFLAGS := -DWEBVIEW_COCOA=1 -x objective-c
WEBVIEW_LDFLAGS := -framework Cocoa -framework WebKit
WEBVIEW_CFLAGS := -DWEBVIEW_COCOA=1
WEBVIEW_LDFLAGS := -framework WebKit
endif

$(TARGET): main.c
Expand Down
3 changes: 0 additions & 3 deletions examples/timer-cxx/CMakeLists.txt 100644 → 100755
Expand Up @@ -6,9 +6,6 @@ set(CMAKE_CXX_STANDARD 11)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../.. ${CMAKE_CURRENT_BINARY_DIR}/webview)
add_executable(timer WIN32 MACOSX_BUNDLE main.cc)
if (APPLE)
set_source_files_properties(main.cc PROPERTIES COMPILE_FLAGS "-x objective-c++")
endif()

find_package(Threads REQUIRED)
target_link_libraries(timer PUBLIC webview ${CMAKE_THREAD_LIBS_INIT})
4 changes: 2 additions & 2 deletions webview.go 100644 → 100755
Expand Up @@ -17,8 +17,8 @@ package webview
#cgo windows CFLAGS: -DWEBVIEW_WINAPI=1
#cgo windows LDFLAGS: -lole32 -lcomctl32 -loleaut32 -luuid -lgdi32
#cgo darwin CFLAGS: -DWEBVIEW_COCOA=1 -x objective-c
#cgo darwin LDFLAGS: -framework Cocoa -framework WebKit
#cgo darwin CFLAGS: -DWEBVIEW_COCOA=1
#cgo darwin LDFLAGS: -framework WebKit
#include <stdlib.h>
#include <stdint.h>
Expand Down

0 comments on commit e94d679

Please sign in to comment.