Permalink
Browse files

Add cmake scripts.

  • Loading branch information...
BYVoid authored and epico committed Aug 11, 2011
1 parent bd70f3f commit c47a095c10f6104fefb7d0406b7f4076ed47f16c
View
@@ -0,0 +1,141 @@
+## Copyright (C) 2011 BYVoid
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2, or (at your option)
+## any later version.
+##
+## This program 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 General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+######## Project settings
+cmake_minimum_required(VERSION 2.8)
+set (PACKAGE_NAME libpinyin)
+project (${PACKAGE_NAME} CXX C)
+enable_testing()
+
+######## Package information
+set (PACKAGE_URL http://http://code.google.com/p/libpinyin)
+set (PACKAGE_BUGREPORT http://code.google.com/p/libpinyin/issues/entry)
+set (LIBPINYIN_VERSION_MAJOR 0)
+set (LIBPINYIN_VERSION_MINOR 2)
+set (LIBPINYIN_VERSION_REVISION 99)
+set (LIBPINYIN_BINARY_VERSION 0.3)
+
+if (CMAKE_BUILD_TYPE MATCHES Debug)
+ set (version_suffix .Debug)
+endif (CMAKE_BUILD_TYPE MATCHES Debug)
+
+set (
+ LIBPINYIN_VERSION
+ ${LIBPINYIN_VERSION_MAJOR}.${LIBPINYIN_VERSION_MINOR}.${LIBPINYIN_VERSION_REVISION}${version_suffix}
+)
+
+######## Validation
+
+include(CheckIncludeFileCXX)
+check_include_file_cxx(locale.h HAVE_LOCALE_H)
+check_include_file_cxx(libintl.h HAVE_LIBINTL_H)
+check_include_file_cxx(stdlib.h HAVE_STDLIB_H)
+check_include_file_cxx(string.h HAVE_STRING_H)
+check_include_file_cxx(sys/time.h HAVE_SYS_TIME_H)
+check_include_file_cxx(unistd.h HAVE_UNISTD_H)
+
+include(CheckFunctionExists)
+check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
+check_function_exists(malloc HAVE_MALLOC)
+check_function_exists(memcmp HAVE_MEMCMP)
+check_function_exists(memmove HAVE_MEMMOVE)
+check_function_exists(memset HAVE_MEMSET)
+check_function_exists(realloc HAVE_REALLOC)
+check_function_exists(setlocale HAVE_SETLOCALE)
+check_function_exists(stat HAVE_STAT)
+
+include(CheckTypeSize)
+check_type_size(size_t SIZE_OF_SIZE_T)
+
+set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
+find_package(GLIB2 REQUIRED)
+find_package(BerkeleyDB REQUIRED)
+
+######## Windows
+
+if (WIN32)
+ set(CMAKE_SHARED_LIBRARY_PREFIX ${CMAKE_INSTALL_PREFIX})
+ set(CMAKE_STATIC_LIBRARY_PREFIX ${CMAKE_INSTALL_PREFIX})
+endif (WIN32)
+
+######## Directory
+
+set (DIR_PREFIX ${CMAKE_INSTALL_PREFIX})
+set (DIR_LIBRARY ${DIR_PREFIX}/${CMAKE_SHARED_LIBRARY_PREFIX})
+set (DIR_LIBRARY_STATIC ${DIR_PREFIX}/${CMAKE_STATIC_LIBRARY_PREFIX})
+set (DIR_INCLUDE ${DIR_PREFIX}/include)
+set (DIR_SHARE ${DIR_PREFIX}/share)
+set (DIR_BIN ${DIR_PREFIX}/bin)
+set (DIR_ETC ${DIR_PREFIX}/etc)
+
+if (DEFINED CMAKE_INSTALL_LIBDIR)
+ set (DIR_LIBRARY ${CMAKE_INSTALL_LIBDIR})
+ set (DIR_LIBRARY_STATIC ${CMAKE_INSTALL_LIBDIR})
+endif (DEFINED CMAKE_INSTALL_LIBDIR)
+
+if (DEFINED SHARE_INSTALL_PREFIX)
+ set (DIR_SHARE ${SHARE_INSTALL_PREFIX})
+endif (DEFINED SHARE_INSTALL_PREFIX)
+
+if (DEFINED INCLUDE_INSTALL_DIR)
+ set (DIR_INCLUDE ${INCLUDE_INSTALL_DIR})
+endif (DEFINED INCLUDE_INSTALL_DIR)
+
+if (DEFINED SYSCONF_INSTALL_DIR)
+ set (DIR_ETC ${SYSCONF_INSTALL_DIR})
+endif (DEFINED SYSCONF_INSTALL_DIR)
+
+set (DIR_SHARE_LIBPINYIN ${DIR_SHARE}/libpinyin)
+set (DIR_INCLUDE_LIBPINYIN ${DIR_INCLUDE}/libpinyin-${LIBPINYIN_BINARY_VERSION})
+
+######## Configuration
+
+configure_file(
+ libpinyin.pc.in
+ libpinyin.pc
+ @ONLY
+)
+
+install(
+ FILES
+ ${CMAKE_BINARY_DIR}/libpinyin.pc
+ DESTINATION
+ ${DIR_LIBRARY}/pkgconfig
+)
+
+######## Definition
+
+if (CMAKE_BUILD_TYPE MATCHES Debug)
+ add_definitions(
+ -O0
+ -g3
+ )
+endif (CMAKE_BUILD_TYPE MATCHES Debug)
+
+include_directories(
+ ${GLIB2_INCLUDE_DIR}
+ ${PROJECT_SOURCE_DIR}/src
+ ${PROJECT_SOURCE_DIR}/src/include
+ ${PROJECT_SOURCE_DIR}/src/storage
+ ${PROJECT_SOURCE_DIR}/src/lookup
+)
+
+######## Subdirectories
+
+add_subdirectory(data)
+add_subdirectory(src)
+add_subdirectory(tests)
+add_subdirectory(utils)
View
@@ -0,0 +1,25 @@
+# - Try to find Berkeley DB
+# Once done this will define
+#
+# BERKELEY_DB_FOUND - system has Berkeley DB
+# BERKELEY_DB_INCLUDE_DIR - the Berkeley DB include directory
+# BERKELEY_DB_LIBRARIES - Link these to use Berkeley DB
+# BERKELEY_DB_DEFINITIONS - Compiler switches required for using Berkeley DB
+
+# Copyright (c) 2006, Alexander Dymo, <adymo@kdevelop.org>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+FIND_PATH(BERKELEY_DB_INCLUDE_DIR db.h
+ /usr/include/db4
+ /usr/local/include/db4
+)
+
+FIND_LIBRARY(BERKELEY_DB_LIBRARIES NAMES db )
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(Berkeley "Could not find Berkeley DB >= 4.1" BERKELEY_DB_INCLUDE_DIR BERKELEY_DB_LIBRARIES)
+# show the BERKELEY_DB_INCLUDE_DIR and BERKELEY_DB_LIBRARIES variables only in the advanced view
+MARK_AS_ADVANCED(BERKELEY_DB_INCLUDE_DIR BERKELEY_DB_LIBRARIES )
+
View
@@ -0,0 +1,53 @@
+# - Try to find the GLIB2 libraries
+# Once done this will define
+#
+# GLIB2_FOUND - system has glib2
+# GLIB2_INCLUDE_DIR - the glib2 include directory
+# GLIB2_LIBRARIES - glib2 library
+
+# Copyright (c) 2008 Laurent Montel, <montel@kde.org>
+#
+# Redistribution and use is allowed according to the terms of the BSD license.
+# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
+
+
+if(GLIB2_INCLUDE_DIR AND GLIB2_LIBRARIES)
+ # Already in cache, be silent
+ set(GLIB2_FIND_QUIETLY TRUE)
+endif(GLIB2_INCLUDE_DIR AND GLIB2_LIBRARIES)
+
+find_package(PkgConfig)
+pkg_check_modules(PC_LibGLIB2 QUIET glib-2.0)
+
+find_path(GLIB2_MAIN_INCLUDE_DIR
+ NAMES glib.h
+ HINTS ${PC_LibGLIB2_INCLUDEDIR}
+ PATH_SUFFIXES glib-2.0)
+
+find_library(GLIB2_LIBRARY
+ NAMES glib-2.0
+ HINTS ${PC_LibGLIB2_LIBDIR}
+)
+
+set(GLIB2_LIBRARIES ${GLIB2_LIBRARY})
+
+# search the glibconfig.h include dir under the same root where the library is found
+get_filename_component(glib2LibDir "${GLIB2_LIBRARIES}" PATH)
+
+find_path(GLIB2_INTERNAL_INCLUDE_DIR glibconfig.h
+ PATH_SUFFIXES glib-2.0/include
+ HINTS ${PC_LibGLIB2_INCLUDEDIR} "${glib2LibDir}" ${CMAKE_SYSTEM_LIBRARY_PATH})
+
+set(GLIB2_INCLUDE_DIR "${GLIB2_MAIN_INCLUDE_DIR}")
+
+# not sure if this include dir is optional or required
+# for now it is optional
+if(GLIB2_INTERNAL_INCLUDE_DIR)
+ set(GLIB2_INCLUDE_DIR ${GLIB2_INCLUDE_DIR} "${GLIB2_INTERNAL_INCLUDE_DIR}")
+endif(GLIB2_INTERNAL_INCLUDE_DIR)
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(GLIB2 DEFAULT_MSG GLIB2_LIBRARIES GLIB2_MAIN_INCLUDE_DIR)
+
+mark_as_advanced(GLIB2_INCLUDE_DIR GLIB2_LIBRARIES)
+
View
@@ -0,0 +1,72 @@
+set(
+ BINARY_MODEL_DATA
+ gb_char.bin
+ gbk_char.bin
+ phrase_index.bin
+ pinyin_index.bin
+ bigram.db
+)
+
+set(
+ BINARY_MODEL_DATA_FILES
+ ${CMAKE_BINARY_DIR}/data/gb_char.bin
+ ${CMAKE_BINARY_DIR}/data/gbk_char.bin
+ ${CMAKE_BINARY_DIR}/data/phrase_index.bin
+ ${CMAKE_BINARY_DIR}/data/pinyin_index.bin
+ ${CMAKE_BINARY_DIR}/data/bigram.db
+)
+
+set(
+ gen_binary_files_BIN
+ ${CMAKE_BINARY_DIR}/utils/storage/gen_binary_files
+)
+
+set(
+ import_interpolation_BIN
+ ${CMAKE_BINARY_DIR}/utils/storage/import_interpolation
+)
+
+add_custom_target(
+ data
+ ALL
+ DEPENDS
+ ${BINARY_MODEL_DATA}
+)
+
+add_custom_command(
+ OUTPUT
+ gb_char.bin
+ gbk_char.bin
+ phrase_index.bin
+ pinyin_index.bin
+ COMMENT
+ "Building binary model data..."
+ COMMAND
+ ${gen_binary_files_BIN} --table-dir ${CMAKE_SOURCE_DIR}/data
+ DEPENDS
+ gen_binary_files
+)
+
+add_custom_command(
+ OUTPUT
+ bigram.db
+ COMMENT
+ "Building binary bigram data..."
+ COMMAND
+ ${import_interpolation_BIN} < ${CMAKE_SOURCE_DIR}/data/interpolation.text
+ DEPENDS
+ import_interpolation
+)
+
+install(
+ FILES
+ ${BINARY_MODEL_DATA_FILES}
+ DESTINATION
+ ${DIR_SHARE_LIBPINYIN}/data
+)
+
+set_directory_properties(
+ PROPERTIES
+ ADDITIONAL_MAKE_CLEAN_FILES
+ ${BINARY_MODEL_DATA_FILES}
+)
View
@@ -1,16 +1,16 @@
-prefix=@prefix@
-exec_prefix=@exec_prefix@
-libdir=@libdir@
-includedir=@includedir@
-datadir=@datadir@
-pkgdatadir=@datadir@/libpinyin
+prefix=@DIR_PREFIX@
+exec_prefix=${prefix}
+libdir=@DIR_LIBRARY@
+includedir=@DIR_INCLUDE@
+datadir=@DIR_SHARE@
+pkgdatadir=@DIR_SHARE@/libpinyin
-libpinyinincludedir=${includedir}/libpinyin-@LIBPINYIN_BINARY_VERSION@
libpinyin_binary_version=@LIBPINYIN_BINARY_VERSION@
+libpinyinincludedir=${includedir}/libpinyin-${libpinyin_binary_version}
Name: libpinyin
-Description: Library to deal with pinyin
-Version: @VERSION@
+Description: Library for intelligent conversion from Pinyin to Chinese characters
+Version: @LIBPINYIN_VERSION@
Requires: glib-2.0
Libs: -L${libdir} -lpinyin
-Cflags: -L${libpinyinincludedir}
+Cflags: -I${libpinyinincludedir}
View
@@ -0,0 +1,50 @@
+set(
+ LIBPINYIN_HEADERS
+ pinyin.h
+)
+
+set(
+ LIBPINYIN_SOURCES
+ pinyin.cpp
+)
+
+add_library(
+ libpinyin
+ SHARED
+ ${LIBPINYIN_SOURCES}
+)
+
+target_link_libraries(
+ libpinyin
+ libstorage
+ liblookup
+)
+
+set_target_properties(
+ libpinyin
+ PROPERTIES
+ OUTPUT_NAME
+ pinyin
+ VERSION
+ 0.0.0
+ SOVERSION
+ 0
+)
+
+install(
+ TARGETS
+ libpinyin
+ LIBRARY DESTINATION
+ ${DIR_LIBRARY}
+)
+
+install(
+ FILES
+ ${LIBPINYIN_HEADERS}
+ DESTINATION
+ ${DIR_INCLUDE_LIBPINYIN}
+)
+
+add_subdirectory(include)
+add_subdirectory(storage)
+add_subdirectory(lookup)
View
@@ -0,0 +1,13 @@
+set(
+ LIBPINYIN_INCLUDE_HEADERS
+ memory_chunk.h
+ novel_types.h
+ stl_lite.h
+)
+
+install(
+ FILES
+ ${LIBPINYIN_INCLUDE_HEADERS}
+ DESTINATION
+ ${DIR_INCLUDE_LIBPINYIN}
+)
Oops, something went wrong.

0 comments on commit c47a095

Please sign in to comment.