summaryrefslogtreecommitdiffstats
path: root/CMakeLists.txt
blob: 94d4d94c480bca34f498ca63ee57dd2e23ff39fd (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
## 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 https://github.com/libpinyin/libpinyin)
set (PACKAGE_BUGREPORT https://github.com/libpinyin/libpinyin/issues)
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)