Skip to content

Commit

Permalink
Merge pull request #31 from Hanjp-IM/develop
Browse files Browse the repository at this point in the history
Migrate to GObject from C++
  • Loading branch information
onting authored Oct 5, 2021
2 parents 0188bfb + 6c0cdd7 commit a21f5f1
Show file tree
Hide file tree
Showing 25 changed files with 1,703 additions and 701 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CMake

on: [push]
on: [push, pull_request]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
Expand All @@ -17,10 +17,14 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Install libhangul-dev
- name: Update Submodules
shell: bash
run: git submodule init && git submodule update

- name: Install Dependencies
working-directory: ${{github.workspace}}
shell: bash
run: sudo apt update && sudo apt install libhangul-dev
run: sudo apt update && sudo apt install libhangul-dev libglib2.0-dev

- name: Create Build Environment
# Some projects don't allow in-source building, so create a separate build directory
Expand All @@ -44,7 +48,7 @@ jobs:
run: cmake --build . --config $BUILD_TYPE

- name: Test
working-directory: ${{github.workspace}}/build
working-directory: ${{github.workspace}}/build/test
shell: bash
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "libhangul"]
path = libhangul
url = https://github.com/libhangul/libhangul.git
46 changes: 22 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,30 +1,28 @@
cmake_minimum_required(VERSION 3.14)
project(libhanjp)

set(hangul_USE_STATIC_LIBS OFF)
set(GObject_USE_STATIC_LIBS OFF)

find_package(PkgConfig REQUIRED)
pkg_check_modules(hangul libhangul REQUIRED)
add_library(hanjp automata.cpp inputcontext.cpp keyboard.cpp)
target_include_directories(hanjp PUBLIC ${hangul_INCLUDE_DIRS})
target_link_libraries(hanjp ${hangul_LIBRARIES})

set(CMAKE_CXX_STANDARD 11)
include(GenerateExportHeader)

include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip
find_package(PkgConfig REQUIRED)
pkg_check_modules(GObject REQUIRED gobject-2.0)
add_library(hanjp hanjpautomata.c hanjpinputcontext.c hanjpkeyboard.c
${PROJECT_SOURCE_DIR}/libhangul/hangul/hangulctype.c
${PROJECT_SOURCE_DIR}/libhangul/hangul/hangulkeyboard.c
)

# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)

enable_testing()

add_executable(testing testing.cpp)
target_link_libraries(testing PUBLIC hanjp gtest_main)

include(GoogleTest)
gtest_discover_tests(testing)
target_include_directories(hanjp PUBLIC ${GObject_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/libhangul/hangul)
target_link_libraries(hanjp ${GObject_LIBRARIES})
generate_export_header(hanjp)

add_subdirectory(test)

install(TARGETS hanjp DESTINATION lib)
install(FILES
hanjp.h
hanjpautomata.h
hanjpkeyboard.h
hanjpinputcontext.h
hanjpunicode.h
DESTINATION include
)
27 changes: 25 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
C++ Migration work for libhanjp
It is a library implemented for Hanjp input method engines.
It is designed on GObject type system, so that it is easily portable to many platforms.
You can use GObject Introspection for cross-language interoperability.

Why migrate?: because it is difficult to write OOP style code on C(It is ugly)

## How can we build?
```
git clone --recurse-submodules https://github.com/Hanjp-IM/libhanjp.git
cd libhanjp
mkdir build
cd build
cmake ..
make
```

## Dependencies
Currently, the library depends on two packages.
```
glib-2.0
libhangul
```
How can we install above?
```
# On ubuntu
sudo apt update && sudo apt install libglib2.0-dev libhangul-dev
```
Loading

0 comments on commit a21f5f1

Please sign in to comment.