update src/pinyin.cpp
[platform/upstream/libpinyin.git] / CMakeLists.txt
1 ## Copyright (C) 2011 BYVoid
2 ##
3 ## This program is free software; you can redistribute it and/or modify
4 ## it under the terms of the GNU General Public License as published by
5 ## the Free Software Foundation; either version 2, or (at your option)
6 ## any later version.
7 ##
8 ## This program is distributed in the hope that it will be useful,
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 ## GNU General Public License for more details.
12 ##
13 ## You should have received a copy of the GNU General Public License
14 ## along with this program; if not, write to the Free Software
15 ## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
16
17 ######## Project settings
18 cmake_minimum_required(VERSION 2.8)
19 set (PACKAGE_NAME libpinyin)
20 project (${PACKAGE_NAME} CXX C)
21 enable_testing()
22
23 ######## Package information
24 set (PACKAGE_URL https://github.com/libpinyin/libpinyin)
25 set (PACKAGE_BUGREPORT https://github.com/libpinyin/libpinyin/issues)
26 set (LIBPINYIN_VERSION_MAJOR 0)
27 set (LIBPINYIN_VERSION_MINOR 7)
28 set (LIBPINYIN_VERSION_REVISION 0)
29 set (LIBPINYIN_BINARY_VERSION 2.0)
30
31 if (CMAKE_BUILD_TYPE MATCHES Debug)
32     set (version_suffix .Debug)
33 endif (CMAKE_BUILD_TYPE MATCHES Debug)
34
35 set (
36     LIBPINYIN_VERSION
37     ${LIBPINYIN_VERSION_MAJOR}.${LIBPINYIN_VERSION_MINOR}.${LIBPINYIN_VERSION_REVISION}${version_suffix}
38 )
39
40 set (VERSION ${LIBPINYIN_VERSION})
41
42 ######## Validation
43
44 include(CheckIncludeFileCXX)
45 check_include_file_cxx(locale.h HAVE_LOCALE_H)
46 check_include_file_cxx(libintl.h HAVE_LIBINTL_H)
47 check_include_file_cxx(stdlib.h HAVE_STDLIB_H)
48 check_include_file_cxx(string.h HAVE_STRING_H)
49 check_include_file_cxx(sys/time.h HAVE_SYS_TIME_H)
50 check_include_file_cxx(unistd.h HAVE_UNISTD_H)
51
52 include(CheckFunctionExists)
53 check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
54 check_function_exists(malloc HAVE_MALLOC)
55 check_function_exists(memcmp HAVE_MEMCMP)
56 check_function_exists(memmove HAVE_MEMMOVE)
57 check_function_exists(memset HAVE_MEMSET)
58 check_function_exists(realloc HAVE_REALLOC)
59 check_function_exists(setlocale HAVE_SETLOCALE)
60 check_function_exists(stat HAVE_STAT)
61
62 include(CheckTypeSize)
63 check_type_size(size_t SIZE_OF_SIZE_T)
64
65 set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
66 find_package(GLIB2 REQUIRED)
67 find_package(BerkeleyDB REQUIRED)
68
69 ######## Windows
70
71 if (WIN32)
72     set(CMAKE_SHARED_LIBRARY_PREFIX ${CMAKE_INSTALL_PREFIX})
73     set(CMAKE_STATIC_LIBRARY_PREFIX ${CMAKE_INSTALL_PREFIX})
74 endif (WIN32)
75
76 ######## Directory
77
78 set (DIR_PREFIX ${CMAKE_INSTALL_PREFIX})
79 set (DIR_LIBRARY ${DIR_PREFIX}/${CMAKE_SHARED_LIBRARY_PREFIX})
80 set (DIR_LIBRARY_STATIC ${DIR_PREFIX}/${CMAKE_STATIC_LIBRARY_PREFIX})
81 set (DIR_INCLUDE ${DIR_PREFIX}/include)
82 set (DIR_SHARE ${DIR_PREFIX}/share)
83 set (DIR_BIN ${DIR_PREFIX}/bin)
84 set (DIR_ETC ${DIR_PREFIX}/etc)
85
86 if (DEFINED CMAKE_INSTALL_LIBDIR)
87     set (DIR_LIBRARY ${CMAKE_INSTALL_LIBDIR})
88     set (DIR_LIBRARY_STATIC ${CMAKE_INSTALL_LIBDIR})
89 endif (DEFINED CMAKE_INSTALL_LIBDIR)
90
91 if (DEFINED SHARE_INSTALL_PREFIX)
92     set (DIR_SHARE ${SHARE_INSTALL_PREFIX})
93 endif (DEFINED SHARE_INSTALL_PREFIX)
94
95 if (DEFINED INCLUDE_INSTALL_DIR)
96     set (DIR_INCLUDE ${INCLUDE_INSTALL_DIR})
97 endif (DEFINED INCLUDE_INSTALL_DIR)
98
99 if (DEFINED SYSCONF_INSTALL_DIR)
100     set (DIR_ETC ${SYSCONF_INSTALL_DIR})
101 endif (DEFINED SYSCONF_INSTALL_DIR)
102
103 set (DIR_SHARE_LIBPINYIN ${DIR_SHARE}/libpinyin)
104 set (DIR_INCLUDE_LIBPINYIN ${DIR_INCLUDE}/libpinyin-${LIBPINYIN_BINARY_VERSION})
105
106 ######## Configuration
107
108 set (prefix ${DIR_PREFIX})
109 set (exec_prefix ${DIR_PREFIX})
110 set (libdir ${DIR_LIBRARY})
111 set (includedir ${DIR_INCLUDE})
112 set (datadir ${DIR_SHARE})
113
114 configure_file(
115     libpinyin.pc.in
116     libpinyin.pc
117     @ONLY
118 )
119
120 install(
121     FILES
122         ${CMAKE_BINARY_DIR}/libpinyin.pc
123     DESTINATION
124         ${DIR_LIBRARY}/pkgconfig
125 )
126
127 ######## Definition
128
129 if (CMAKE_BUILD_TYPE MATCHES Debug)
130     add_definitions(
131         -O0
132         -g3
133     )
134 endif (CMAKE_BUILD_TYPE MATCHES Debug)
135
136 include_directories(
137     ${GLIB2_INCLUDE_DIR}
138     ${PROJECT_SOURCE_DIR}/src
139     ${PROJECT_SOURCE_DIR}/src/include
140     ${PROJECT_SOURCE_DIR}/src/storage
141     ${PROJECT_SOURCE_DIR}/src/lookup
142     ${PROJECT_SOURCE_DIR}/utils
143     ${PROJECT_SOURCE_DIR}/tests
144 )
145
146 ######## Subdirectories
147
148 add_subdirectory(src)
149 add_subdirectory(tests)
150 add_subdirectory(utils)
151 add_subdirectory(data)