add libpinyin.spec.in
[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., 675 Mass Ave, Cambridge, MA 02139, 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 2)
28 set (LIBPINYIN_VERSION_REVISION 99)
29 set (LIBPINYIN_BINARY_VERSION 0.3)
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 ######## Validation
41
42 include(CheckIncludeFileCXX)
43 check_include_file_cxx(locale.h HAVE_LOCALE_H)
44 check_include_file_cxx(libintl.h HAVE_LIBINTL_H)
45 check_include_file_cxx(stdlib.h HAVE_STDLIB_H)
46 check_include_file_cxx(string.h HAVE_STRING_H)
47 check_include_file_cxx(sys/time.h HAVE_SYS_TIME_H)
48 check_include_file_cxx(unistd.h HAVE_UNISTD_H)
49
50 include(CheckFunctionExists)
51 check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
52 check_function_exists(malloc HAVE_MALLOC)
53 check_function_exists(memcmp HAVE_MEMCMP)
54 check_function_exists(memmove HAVE_MEMMOVE)
55 check_function_exists(memset HAVE_MEMSET)
56 check_function_exists(realloc HAVE_REALLOC)
57 check_function_exists(setlocale HAVE_SETLOCALE)
58 check_function_exists(stat HAVE_STAT)
59
60 include(CheckTypeSize)
61 check_type_size(size_t SIZE_OF_SIZE_T)
62
63 set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
64 find_package(GLIB2 REQUIRED)
65 find_package(BerkeleyDB REQUIRED)
66
67 ######## Windows
68
69 if (WIN32)
70     set(CMAKE_SHARED_LIBRARY_PREFIX ${CMAKE_INSTALL_PREFIX})
71     set(CMAKE_STATIC_LIBRARY_PREFIX ${CMAKE_INSTALL_PREFIX})
72 endif (WIN32)
73
74 ######## Directory
75
76 set (DIR_PREFIX ${CMAKE_INSTALL_PREFIX})
77 set (DIR_LIBRARY ${DIR_PREFIX}/${CMAKE_SHARED_LIBRARY_PREFIX})
78 set (DIR_LIBRARY_STATIC ${DIR_PREFIX}/${CMAKE_STATIC_LIBRARY_PREFIX})
79 set (DIR_INCLUDE ${DIR_PREFIX}/include)
80 set (DIR_SHARE ${DIR_PREFIX}/share)
81 set (DIR_BIN ${DIR_PREFIX}/bin)
82 set (DIR_ETC ${DIR_PREFIX}/etc)
83
84 if (DEFINED CMAKE_INSTALL_LIBDIR)
85     set (DIR_LIBRARY ${CMAKE_INSTALL_LIBDIR})
86     set (DIR_LIBRARY_STATIC ${CMAKE_INSTALL_LIBDIR})
87 endif (DEFINED CMAKE_INSTALL_LIBDIR)
88
89 if (DEFINED SHARE_INSTALL_PREFIX)
90     set (DIR_SHARE ${SHARE_INSTALL_PREFIX})
91 endif (DEFINED SHARE_INSTALL_PREFIX)
92
93 if (DEFINED INCLUDE_INSTALL_DIR)
94     set (DIR_INCLUDE ${INCLUDE_INSTALL_DIR})
95 endif (DEFINED INCLUDE_INSTALL_DIR)
96
97 if (DEFINED SYSCONF_INSTALL_DIR)
98     set (DIR_ETC ${SYSCONF_INSTALL_DIR})
99 endif (DEFINED SYSCONF_INSTALL_DIR)
100
101 set (DIR_SHARE_LIBPINYIN ${DIR_SHARE}/libpinyin)
102 set (DIR_INCLUDE_LIBPINYIN ${DIR_INCLUDE}/libpinyin-${LIBPINYIN_BINARY_VERSION})
103
104 ######## Configuration
105
106 configure_file(
107     libpinyin.pc.in
108     libpinyin.pc
109     @ONLY
110 )
111
112 install(
113     FILES
114         ${CMAKE_BINARY_DIR}/libpinyin.pc
115     DESTINATION
116         ${DIR_LIBRARY}/pkgconfig
117 )
118
119 ######## Definition
120
121 if (CMAKE_BUILD_TYPE MATCHES Debug)
122     add_definitions(
123         -O0
124         -g3
125     )
126 endif (CMAKE_BUILD_TYPE MATCHES Debug)
127
128 include_directories(
129     ${GLIB2_INCLUDE_DIR}
130     ${PROJECT_SOURCE_DIR}/src
131     ${PROJECT_SOURCE_DIR}/src/include
132     ${PROJECT_SOURCE_DIR}/src/storage
133     ${PROJECT_SOURCE_DIR}/src/lookup
134 )
135
136 ######## Subdirectories
137
138 add_subdirectory(data)
139 add_subdirectory(src)
140 add_subdirectory(tests)
141 add_subdirectory(utils)