summaryrefslogtreecommitdiffstats
path: root/CMakeLists.txt
blob: be6dc11c484f870df07f2263a18294719788e7ad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
## 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 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 https://github.com/libpinyin/libpinyin)
set (PACKAGE_BUGREPORT https://github.com/libpinyin/libpinyin/issues)
set (LIBPINYIN_VERSION_MAJOR 0)
set (LIBPINYIN_VERSION_MINOR 7)
set (LIBPINYIN_VERSION_REVISION 0)
set (LIBPINYIN_BINARY_VERSION 2.0)

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}
)

set (VERSION ${LIBPINYIN_VERSION})

######## 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)
check_function_exists(mmap HAVE_MMAP)

include(CheckTypeSize)
check_type_size(size_t SIZE_OF_SIZE_T)

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
find_package(GLIB2 REQUIRED)

# DBM: BerkeleyDB
find_package(BerkeleyDB)
if (DB_FOUND)
  include_directories ( ${DB_INCLUDE_DIR} )
  SET (LIBS ${LIBS} ${DB_LIBRARIES})
  SET (HAVE_BERKELEY_DB 1)
  SET (CMAKE_CXX_LINK_EXECUTABLE
    "${CMAKE_CXX_LINK_EXECUTABLE} ${LIBS}")
endif (DB_FOUND)

if (NOT HAVE_BERKELEY_DB)
  # DBM: Kyoto Cabinet
  find_package(KyotoCabinet)
  if (KyotoCabinet_FOUND)
    include_directories ( ${KyotoCabinet_INCLUDE_PATH} )
    SET (LIBS ${LIBS} ${KyotoCabinet_LIBRARY})
    SET (HAVE_KYOTO_CABINET 1)
    SET (CMAKE_CXX_LINK_EXECUTABLE
      "${CMAKE_CXX_LINK_EXECUTABLE} ${LIBS}")
  endif (KyotoCabinet_FOUND)
endif (NOT HAVE_BERKELEY_DB)


######## 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

set (prefix ${DIR_PREFIX})
set (exec_prefix ${DIR_PREFIX})
set (libdir ${DIR_LIBRARY})
set (includedir ${DIR_INCLUDE})
set (datadir ${DIR_SHARE})

configure_file(
    libpinyin.pc.in
    libpinyin.pc
    @ONLY
)

configure_file(
  config.h.cmake
  config.h
  @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}/
    ${PROJECT_SOURCE_DIR}/src
    ${PROJECT_SOURCE_DIR}/src/include
    ${PROJECT_SOURCE_DIR}/src/storage
    ${PROJECT_SOURCE_DIR}/src/lookup
    ${PROJECT_SOURCE_DIR}/utils
    ${PROJECT_SOURCE_DIR}/tests
)

######## Subdirectories

add_subdirectory(src)
add_subdirectory(tests)
add_subdirectory(utils)
add_subdirectory(data)