summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChoe Hwanjin <choe.hwanjin@gmail.com>2021-08-01 19:56:17 +0900
committerChoe Hwanjin <choe.hwanjin@gmail.com>2021-09-20 19:32:59 +0900
commit7b2c1543196d98d32ba3a094687f059da70f3f45 (patch)
tree03fc2ea72c42b5f3ca84dc1d2112f3f072df4cfe
parent4c1efe85ab9ddb5f6ea3e69bdf24e9373d5c402a (diff)
downloadlibhangul-7b2c1543196d98d32ba3a094687f059da70f3f45.tar.gz
Add CMake build files
CMake로도 빌드할 수 있으면 좀더 편리하다.
-rw-r--r--CMakeLists.txt72
-rw-r--r--data/hanja/CMakeLists.txt26
-rw-r--r--data/keyboards/CMakeLists.txt119
-rw-r--r--hangul/CMakeLists.txt82
-rw-r--r--po/CMakeLists.txt66
-rw-r--r--test/CMakeLists.txt52
6 files changed, 417 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..28ab766
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,72 @@
+# libhangul
+# Copyright 2021 Choe Hwanjin
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+cmake_minimum_required(VERSION 3.0)
+
+project(libhangul
+ VERSION 0.1.0
+)
+
+set(LIBHANGUL_SOVERSION_MAJOR 1)
+set(LIBHANGUL_SOVERSION_MINOR 0)
+set(LIBHANGUL_SOVERSION_PATCH 1)
+
+option(ENABLE_EXTERNAL_KEYBOARDS
+ "enable external keyboard xml file loading feature"
+ ON
+)
+
+include(CTest)
+
+include(GNUInstallDirs)
+set(LIBHANGUL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/hangul-1.0")
+set(LIBHANGUL_LIBRARY_DIR "${CMAKE_INSTALL_LIBDIR}")
+
+add_subdirectory(hangul)
+add_subdirectory(data/hanja)
+add_subdirectory(data/keyboards)
+add_subdirectory(po)
+
+if(BUILD_TESTING)
+ add_subdirectory(test)
+endif()
+
+include(CMakePackageConfigHelpers)
+configure_package_config_file(hangul-config.cmake.in
+ "${CMAKE_CURRENT_BINARY_DIR}/hangul-config.cmake"
+ INSTALL_DESTINATION
+ "${CMAKE_INSTALL_LIBDIR}/cmake/hangul"
+ PATH_VARS
+ LIBHANGUL_INCLUDE_DIR
+ LIBHANGUL_LIBRARY_DIR
+)
+
+write_basic_package_version_file(
+ "${CMAKE_CURRENT_BINARY_DIR}/hangul-config-version.cmake"
+ COMPATIBILITY
+ AnyNewerVersion
+)
+
+install(
+ FILES
+ "${CMAKE_CURRENT_BINARY_DIR}/hangul-config.cmake"
+ "${CMAKE_CURRENT_BINARY_DIR}/hangul-config-version.cmake"
+ DESTINATION
+ "${CMAKE_INSTALL_LIBDIR}/cmake/hangul"
+ COMPONENT
+ dev
+)
diff --git a/data/hanja/CMakeLists.txt b/data/hanja/CMakeLists.txt
new file mode 100644
index 0000000..bdf8ad7
--- /dev/null
+++ b/data/hanja/CMakeLists.txt
@@ -0,0 +1,26 @@
+# libhangul
+# Copyright 2021 Choe Hwanjin
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+cmake_minimum_required(VERSION 3.0)
+
+install(
+ FILES
+ hanja.txt
+ mssymbol.txt
+ DESTINATION
+ "${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME}/hanja"
+)
diff --git a/data/keyboards/CMakeLists.txt b/data/keyboards/CMakeLists.txt
new file mode 100644
index 0000000..6c94c18
--- /dev/null
+++ b/data/keyboards/CMakeLists.txt
@@ -0,0 +1,119 @@
+# libhangul
+# Copyright 2021 Choe Hwanjin
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+cmake_minimum_required(VERSION 3.0)
+
+#include(GNUInstallDirs)
+include(FindGettext)
+
+set(keyboard_file_list
+ hangul-keyboard-2.xml
+ hangul-keyboard-2y.xml
+ hangul-keyboard-39.xml
+ hangul-keyboard-3f.xml
+ hangul-keyboard-32.xml
+ hangul-keyboard-3s.xml
+ hangul-keyboard-3y.xml
+ hangul-keyboard-ro.xml
+ hangul-keyboard-ahn.xml
+)
+
+add_custom_target(keyboard ALL
+ DEPENDS
+ ${keyboard_file_list}
+ hangul-combination-default.xml
+ hangul-combination-full.xml
+)
+
+set(MSGFMT_COMMAND env GETTEXTDATADIRS=\"${CMAKE_CURRENT_SOURCE_DIR}\" \"${GETTEXT_MSGFMT_EXECUTABLE}\")
+
+# generating keyboard translation rule
+foreach(i ${keyboard_file_list})
+ string(REGEX REPLACE "\\.xml$" "" keyboard_name "${i}")
+ add_custom_command(
+ OUTPUT
+ "${keyboard_name}.name.xml.in"
+ COMMAND
+ grep \"xml version=\" "${CMAKE_CURRENT_SOURCE_DIR}/${keyboard_name}.xml.template" > "${keyboard_name}.name.xml.in"
+ COMMAND
+ grep \"<hangul-keyboard\" "${CMAKE_CURRENT_SOURCE_DIR}/${keyboard_name}.xml.template" >> "${keyboard_name}.name.xml.in"
+ COMMAND
+ grep \"<name>\" "${CMAKE_CURRENT_SOURCE_DIR}/${keyboard_name}.xml.template" >> "${keyboard_name}.name.xml.in"
+ COMMAND
+ grep \"</hangul-keyboard\" "${CMAKE_CURRENT_SOURCE_DIR}/${keyboard_name}.xml.template" >> "${keyboard_name}.name.xml.in"
+ DEPENDS
+ "${keyboard_name}.xml.template"
+ )
+
+ add_custom_command(
+ OUTPUT
+ "${keyboard_name}.name.xml"
+ COMMAND
+ ${MSGFMT_COMMAND} --xml --template "${keyboard_name}.name.xml.in" -d "${CMAKE_SOURCE_DIR}/po" -o "${keyboard_name}.name.xml"
+ DEPENDS
+ "${CMAKE_CURRENT_BINARY_DIR}/${keyboard_name}.name.xml.in"
+ )
+
+ add_custom_command(
+ OUTPUT
+ "${keyboard_name}.xml"
+ COMMAND
+ sed -i -e '1 D'
+ -e '/^<hangul-keyboard/D'
+ -e '/^<\\/hangul-keyboard/D'
+ -e 's/^ *<name/ <name/' "${keyboard_name}.name.xml"
+ COMMAND
+ sed
+ -e '/<name>/r ${keyboard_name}.name.xml'
+ -e '/<name>/D'
+ "${CMAKE_CURRENT_SOURCE_DIR}/${keyboard_name}.xml.template" > "${keyboard_name}.xml"
+ DEPENDS
+ "${CMAKE_CURRENT_BINARY_DIR}/${keyboard_name}.name.xml"
+ "${keyboard_name}.xml.template"
+ )
+
+ install(
+ FILES "${CMAKE_CURRENT_BINARY_DIR}/${keyboard_name}.xml"
+ DESTINATION "${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME}/keyboards"
+ )
+endforeach()
+
+add_custom_command(
+ OUTPUT
+ hangul-combination-default.xml
+ COMMAND
+ "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/hangul-combination-default.xml" hangul-combination-default.xml
+ DEPENDS
+ "${CMAKE_CURRENT_SOURCE_DIR}/hangul-combination-default.xml"
+)
+
+add_custom_command(
+ OUTPUT
+ hangul-combination-full.xml
+ COMMAND
+ "${CMAKE_COMMAND}" -E copy "${CMAKE_CURRENT_SOURCE_DIR}/hangul-combination-full.xml" hangul-combination-full.xml
+ DEPENDS
+ "${CMAKE_CURRENT_SOURCE_DIR}/hangul-combination-full.xml"
+)
+
+install(
+ FILES
+ hangul-combination-default.xml
+ hangul-combination-full.xml
+ DESTINATION
+ "${CMAKE_INSTALL_DATADIR}/${CMAKE_PROJECT_NAME}/keyboards"
+)
diff --git a/hangul/CMakeLists.txt b/hangul/CMakeLists.txt
new file mode 100644
index 0000000..aa6e27e
--- /dev/null
+++ b/hangul/CMakeLists.txt
@@ -0,0 +1,82 @@
+# libhangul
+# Copyright 2021 Choe Hwanjin
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+cmake_minimum_required(VERSION 3.0)
+
+include(FindPkgConfig)
+include(FindEXPAT)
+include(GNUInstallDirs)
+
+option(ENABLE_EXTERNAL_KEYBOARDS
+ "enable external keyboard xml file loading feature"
+ ON
+)
+
+set(hangul_PUBLIC_HEADERS
+ hangul.h
+)
+
+set(hangul_PRIVATE_HEADERS
+ hangul-gettext.h
+ hangulkeyboard.h
+ hangulinternals.h
+ hanjacompatible.h
+)
+
+add_library(hangul SHARED
+ ${hangul_PUBLIC_HEADERS}
+ ${hangul_PRIVATE_HEADERS}
+ hangulctype.c
+ hangulinputcontext.c
+ hangulkeyboard.c
+ hanja.c
+)
+
+target_compile_definitions(hangul
+ PRIVATE -DLOCALEDIR=\"${CMAKE_INSTALL_FULL_LOCALEDIR}\"
+ PRIVATE -DLIBHANGUL_DEFAULT_HANJA_DIC=\"${CMAKE_INSTALL_FULL_DATADIR}/${CMAKE_PROJECT_NAME}/hanja/hanja.txt\"
+ PRIVATE -DLIBHANGUL_DATA_DIR=\"${CMAKE_INSTALL_FULL_DATADIR}/${CMAKE_PROJECT_NAME}\"
+ PRIVATE -DTOP_SRCDIR=\"${CMAKE_SOURCE_DIR}\"
+)
+
+if (ENABLE_EXTERNAL_KEYBOARDS)
+ target_compile_definitions(hangul
+ PRIVATE -DENABLE_EXTERNAL_KEYBOARDS=1
+ )
+
+ target_include_directories(hangul
+ PRIVATE ${EXPAT_INCLUDE_DIRS}
+ )
+
+ target_link_libraries(hangul LINK_PRIVATE
+ ${EXPAT_LIBRARIES}
+ )
+endif() # ENABLE_EXTERNAL_KEYBOARDS
+
+set_target_properties(hangul
+ PROPERTIES
+ VERSION "${LIBHANGUL_SOVERSION_MAJOR}.${LIBHANGUL_SOVERSION_MINOR}.${LIBHANGUL_SOVERSION_PATCH}"
+ SOVERSION "${LIBHANGUL_SOVERSION_MAJOR}"
+)
+
+install(TARGETS hangul
+ DESTINATION ${CMAKE_INSTALL_FULL_LIBDIR}
+)
+
+install(FILES ${hangul_PUBLIC_HEADERS}
+ DESTINATION ${CMAKE_INSTALL_FULL_INCLUDEDIR}/hangul-1.0
+)
diff --git a/po/CMakeLists.txt b/po/CMakeLists.txt
new file mode 100644
index 0000000..82e26d4
--- /dev/null
+++ b/po/CMakeLists.txt
@@ -0,0 +1,66 @@
+# libhangul
+# Copyright 2021 Choe Hwanjin
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+cmake_minimum_required(VERSION 3.0)
+
+include(FindGettext)
+include(GNUInstallDirs)
+
+file(READ LINGUAS LINGUAS)
+string(REPLACE "\n" ";" LINGUAS "${LINGUAS}")
+
+foreach(lang ${LINGUAS})
+ GETTEXT_PROCESS_PO_FILES(${lang} ALL
+ INSTALL_DESTINATION "${CMAKE_INSTALL_LOCALEDIR}"
+ PO_FILES ${lang}.po
+ )
+endforeach()
+
+find_program(XGETTEXT_EXECUTABLE xgettext)
+set(PACKAGE_NAME libhangul)
+set(DOMAIN libhangul)
+set(COPYRIGHT_HOLDER "Choe Hwanjin")
+set(MSGID_BUGS_ADDRESS "https://github.com/libhangul/libhangul")
+
+add_custom_target(update-po)
+
+add_custom_target(update-pot
+ COMMAND
+ ${XGETTEXT_EXECUTABLE}
+ --default-domain=${DOMAIN}
+ --directory="${CMAKE_SOURCE_DIR}"
+ --add-comments=TRANSLATORS:
+ --keyword=_
+ --keyword=N_
+ --files-from="${CMAKE_CURRENT_SOURCE_DIR}/POTFILES.in"
+ --copyright-holder="${COPYRIGHT_HOLDER}"
+ --package-name="${PACKAGE_NAME}"
+ --package-version="${PACKAGE_VERSION}"
+ --msgid-bugs-address="${MSGID_BUGS_ADDRESS}"
+ --output-dir="${CMAKE_CURRENT_SOURCE_DIR}"
+ --output=${DOMAIN}.pot
+)
+add_dependencies(update-po update-pot)
+
+foreach(lang ${LINGUAS})
+ add_custom_target(update-po-${lang}
+ COMMAND "${GETTEXT_MSGMERGE_EXECUTABLE}" --update --lang=${lang} ${lang}.po ${DOMAIN}.pot
+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
+ DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${DOMAIN}.pot"
+ )
+ add_dependencies(update-po update-po-${lang})
+endforeach()
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
new file mode 100644
index 0000000..433baf9
--- /dev/null
+++ b/test/CMakeLists.txt
@@ -0,0 +1,52 @@
+# libhangul
+# Copyright 2021 Choe Hwanjin
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+cmake_minimum_required(VERSION 3.0)
+
+include(FindPkgConfig)
+
+add_executable(test-hangul
+ hangul.c
+)
+target_compile_definitions(test-hangul PRIVATE
+ TEST_LIBHANGUL_KEYBOARD_PATH=\"${CMAKE_BINARY_DIR}/data/keyboards\"
+)
+target_link_libraries(test-hangul LINK_PRIVATE hangul)
+
+add_executable(test-hanja
+ hanja.c
+)
+
+target_link_libraries(test-hanja LINK_PRIVATE hangul)
+
+# unit test
+pkg_check_modules(CHECK REQUIRED check)
+
+add_executable(unittest
+ test.c
+)
+
+target_compile_definitions(unittest PRIVATE
+ TEST_LIBHANGUL_KEYBOARD_PATH=\"${CMAKE_BINARY_DIR}/data/keyboards\"
+ TEST_SOURCE_DIR=\"${CMAKE_CURRENT_SOURCE_DIR}\"
+)
+target_include_directories(unittest PRIVATE ${CHECK_INCLUDE_DIRS})
+target_link_libraries(unittest PRIVATE hangul ${CHECK_LDFLAGS})
+
+add_test(NAME unittest
+ COMMAND ./unittest
+)