Skip to content

Commit 3565448

Browse files
committed
support for cmake
1 parent fa94048 commit 3565448

File tree

3 files changed

+183
-48
lines changed

3 files changed

+183
-48
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
src/mecab/src/config.h
2+
13
# Created by https://www.gitignore.io
24

35
### CMake ###

src/CMakeLists.txt

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
#
2+
# CMake configuration for open_jtalk
3+
#
4+
# adapted from https://gist.github.com/hkrn/889259/266e798f48a49d041d7f1e41a579d878134f1fca
5+
cmake_minimum_required(VERSION 2.6)
6+
7+
# set library version
8+
set(OPEN_JTALK_VERSION 1.10)
9+
set(PACKAGE "open_jtalk")
10+
set(PACKAGE_BUGREPORT "https://github.com/r9y9/open_jtalk/")
11+
set(PACKAGE_NAME "open_jtalk")
12+
set(PACKAGE_URL "")
13+
set(PACKAGE_VERSION ${OPEN_JTALK_VERSION})
14+
set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
15+
16+
# build configuration
17+
project(open_jtalk)
18+
aux_source_directory(jpcommon libjpcommon_source)
19+
aux_source_directory(mecab/src libmecab_source)
20+
aux_source_directory(mecab2njd libmecab2njd_source)
21+
aux_source_directory(njd libnjd_source)
22+
aux_source_directory(njd2jpcommon libnjd2jpcommon_source)
23+
aux_source_directory(njd_set_accent_phrase libnjd_set_accent_phrase_source)
24+
aux_source_directory(njd_set_accent_type libnjd_set_accent_type_source)
25+
aux_source_directory(njd_set_digit libnjd_set_digit_source)
26+
aux_source_directory(njd_set_long_vowel libnjd_set_long_vowel_source)
27+
aux_source_directory(njd_set_pronunciation libnjd_set_pronunciation_source)
28+
aux_source_directory(njd_set_unvoiced_vowel libnjd_set_unvoiced_vowel_source)
29+
aux_source_directory(text2mecab libtext2mecab_source)
30+
include_directories(jpcommon mecab/src mecab2njd njd njd2jpcommon njd_set_accent_phrase
31+
njd_set_accent_type njd_set_digit njd_set_long_vowel
32+
njd_set_pronunciation njd_set_unvoiced_vowel text2mecab)
33+
34+
add_library(open_jtalk ${libjpcommon_source} ${libmecab_source} ${libmecab2njd_source}
35+
${libnjd_source} ${libnjd2jpcommon_source}
36+
${libnjd_set_accent_phrase_source} ${libnjd_set_accent_type_source}
37+
${libnjd_set_digit_source} ${libnjd_set_long_vowel_source}
38+
${libnjd_set_pronunciation_source} ${libnjd_set_unvoiced_vowel_source}
39+
${libtext2mecab_source})
40+
set_target_properties(open_jtalk PROPERTIES VERSION ${OPEN_JTALK_VERSION})
41+
set_target_properties(open_jtalk PROPERTIES SO_VERSION ${OPEN_JTALK_VERSION})
42+
43+
# generate mecab/config.h
44+
include(CheckIncludeFiles)
45+
include(CheckFunctionExists)
46+
include(CheckLibraryExists)
47+
include(CheckTypeSize)
48+
check_include_files(ctype.h HAVE_CTYPE_H)
49+
check_include_files(dirent.h HAVE_DIRENT_H)
50+
check_include_files(fcntl.h HAVE_FCNTL_H)
51+
check_include_files(inttypes.h HAVE_INTTYPES_H)
52+
check_include_files(io.h HAVE_IO_H)
53+
check_include_files(memory.h HAVE_MEMORY_H)
54+
check_include_files(setjmp.h HAVE_SETJMP_H)
55+
check_include_files(stdint.h HAVE_STDINT_H)
56+
check_include_files(stdlib.h HAVE_STDLIB_H)
57+
check_include_files(strings.h HAVE_STRINGS_H)
58+
check_include_files(string.h HAVE_STRING_H)
59+
check_include_files(sys/mman.h HAVE_SYS_MMAN_H)
60+
check_include_files(sys/stat.h HAVE_SYS_STAT_H)
61+
check_include_files(sys/times.h HAVE_SYS_TIMES_H)
62+
check_include_files(sys/types.h HAVE_SYS_TYPES_H)
63+
check_include_files(unistd.h HAVE_UNISTD_H)
64+
check_function_exists(getenv HAVE_GETENV)
65+
check_function_exists(getpagesize HAVE_GETPAGESIZE)
66+
check_function_exists(mmap HAVE_MMAP)
67+
check_function_exists(opendir HAVE_OPENDIR)
68+
check_function_exists(setjmp HAVE_SETJMP)
69+
check_function_exists(sqrt HAVE_SQRT)
70+
check_function_exists(strstr HAVE_STRSTR)
71+
check_library_exists(iconv iconv_open "" ICONV_CONST)
72+
check_library_exists(m sqrt "" HAVE_LIBM)
73+
check_type_size(char SIZEOF_CHAR)
74+
check_type_size(int SIZEOF_INT)
75+
check_type_size(long SIZEOF_LONG)
76+
check_type_size("long long" SIZEOF_LONG_LONG)
77+
check_type_size(short SIZEOF_SHORT)
78+
check_type_size(size_t SIZEOF_SIZE_T)
79+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/mecab/config.h.in ${CMAKE_CURRENT_SOURCE_DIR}/mecab/src/config.h)
80+
add_definitions(-DHAVE_CONFIG_H
81+
-DDIC_VERSION=102
82+
-DMECAB_DEFAULT_RC="dummy"
83+
-DMECAB_WITHOUT_SHARE_DIC
84+
-DPACKAGE="open_jtalk"
85+
-DVERSION="${OPEN_JTALK_VERSION}")
86+
87+
# whether build as a shared library or not
88+
option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
89+
if(BUILD_SHARED_LIBS)
90+
set(LIB_TYPE SHARED)
91+
else()
92+
set(LIB_TYPE STATIC)
93+
endif()
94+
95+
# find HTSEngine
96+
find_path(HTS_ENGINE_INCLUDE_DIR HTS_engine.h)
97+
find_library(HTS_ENGINE_LIB HTSEngine)
98+
if(HTS_ENGINE_INCLUDE_DIR AND HTS_ENGINE_LIB)
99+
target_link_libraries(open_jtalk ${HTS_ENGINE_LIB})
100+
include_directories(open_jtalk ${HTS_ENGINE_INCLUDE_DIR})
101+
else()
102+
message(FATAL_ERROR "Required HTSEngine not found")
103+
endif()
104+
105+
# configuration for charset
106+
#option(CHARSET "Encoding set for mecab" "eucjp")
107+
set(CHARSET "utf8")
108+
109+
if(${CHARSET} STREQUAL "sjis")
110+
add_definitions(-DCHARSET_SHIFT_JIS -DMECAB_CHARSET=sjis)
111+
foreach(flag CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
112+
set(${flag} "${${flag}} -finput-charset=cp932 -fexec-charset=cp932")
113+
endforeach()
114+
elseif(${CHARSET} STREQUAL "eucjp")
115+
add_definitions(-DCHARSET_EUC_JP -DMECAB_CHARSET=euc-jp)
116+
elseif(${CHARSET} STREQUAL "utf8")
117+
add_definitions(-DCHARSET_UTF_8 -DMECAB_CHARSET=utf-8 -DMECAB_UTF8_USE_ONLY)
118+
foreach(flag CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
119+
set(${flag} "${${flag}} -finput-charset=UTF-8 -fexec-charset=UTF-8")
120+
endforeach()
121+
else()
122+
message(FATAL_ERROR "Encoding ${CHARSET} not recognized. You can set sjis/eucjp/utf8")
123+
endif()
124+
125+
# installation
126+
if(NOT MSVC)
127+
install(TARGETS open_jtalk DESTINATION lib)
128+
install(FILES jpcommon/jpcommon.h mecab/src/mecab.h mecab2njd/mecab2njd.h njd/njd.h njd2jpcommon/njd2jpcommon.h
129+
njd_set_accent_phrase/njd_set_accent_phrase.h njd_set_accent_type/njd_set_accent_type.h
130+
njd_set_digit/njd_set_digit.h njd_set_long_vowel/njd_set_long_vowel.h njd_set_pronunciation/njd_set_pronunciation.h
131+
njd_set_unvoiced_vowel/njd_set_unvoiced_vowel.h text2mecab/text2mecab.h
132+
DESTINATION include/open_jtalk)
133+
endif()

src/mecab/config.h.in

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,139 @@
11
/* mecab/config.h.in. Generated from configure.ac by autoheader. */
22

33
/* Define if building universal (internal helper macro) */
4-
#undef AC_APPLE_UNIVERSAL_BUILD
4+
#cmakedefine AC_APPLE_UNIVERSAL_BUILD @AC_APPLE_UNIVERSAL_BUILD@
55

66
/* Define to 1 if you have the <ctype.h> header file. */
7-
#undef HAVE_CTYPE_H
7+
#cmakedefine HAVE_CTYPE_H @HAVE_CTYPE_H@
88

99
/* Define to 1 if you have the <dirent.h> header file. */
10-
#undef HAVE_DIRENT_H
10+
#cmakedefine HAVE_DIRENT_H @HAVE_DIRENT_H@
1111

1212
/* Define to 1 if you have the <fcntl.h> header file. */
13-
#undef HAVE_FCNTL_H
13+
#cmakedefine HAVE_FCNTL_H @HAVE_FCNTL_H@
1414

1515
/* Define to 1 if you have the `getenv' function. */
16-
#undef HAVE_GETENV
16+
#cmakedefine HAVE_GETENV @HAVE_GETENV@
1717

1818
/* Define to 1 if you have the `getpagesize' function. */
19-
#undef HAVE_GETPAGESIZE
19+
#cmakedefine HAVE_GETPAGESIZE @HAVE_GETPAGESIZE@
2020

2121
/* Define to 1 if you have the `iconv_open' library(-liconv). */
22-
#undef HAVE_ICONV
22+
#cmakedefine HAVE_ICONV @HAVE_ICONV@
2323

2424
/* Define to 1 if you have the <inttypes.h> header file. */
25-
#undef HAVE_INTTYPES_H
25+
#cmakedefine HAVE_INTTYPES_H @HAVE_INTTYPES_H@
2626

2727
/* Define to 1 if you have the <io.h> header file. */
28-
#undef HAVE_IO_H
28+
#cmakedefine HAVE_IO_H @HAVE_IO_H@
2929

3030
/* Define to 1 if you have the `m' library (-lm). */
31-
#undef HAVE_LIBM
31+
#cmakedefine HAVE_LIBM @HAVE_LIBM@
3232

3333
/* Define to 1 if you have the `winmm' library (-lwinmm). */
34-
#undef HAVE_LIBWINMM
34+
#cmakedefine HAVE_LIBWINMM @HAVE_LIBWINMM@
3535

3636
/* Define to 1 if you have the <memory.h> header file. */
37-
#undef HAVE_MEMORY_H
37+
#cmakedefine HAVE_MEMORY_H @HAVE_MEMORY_H@
3838

3939
/* Define to 1 if you have a working `mmap' system call. */
40-
#undef HAVE_MMAP
40+
#cmakedefine HAVE_MMAP @HAVE_MMAP@
4141

4242
/* Define to 1 if you have the `opendir' function. */
43-
#undef HAVE_OPENDIR
43+
#cmakedefine HAVE_OPENDIR @HAVE_OPENDIR@
4444

4545
/* Define to 1 if you have the `setjmp' function. */
46-
#undef HAVE_SETJMP
46+
#cmakedefine HAVE_SETJMP @HAVE_SETJMP@
4747

4848
/* Define to 1 if you have the <setjmp.h> header file. */
49-
#undef HAVE_SETJMP_H
49+
#cmakedefine HAVE_SETJMP_H @HAVE_SETJMP_H@
5050

5151
/* Define to 1 if you have the `sqrt' function. */
52-
#undef HAVE_SQRT
52+
#cmakedefine HAVE_SQRT @HAVE_SQRT@
5353

5454
/* Define to 1 if you have the <stdint.h> header file. */
55-
#undef HAVE_STDINT_H
55+
#cmakedefine HAVE_STDINT_H @HAVE_STDINT_H@
5656

5757
/* Define to 1 if you have the <stdlib.h> header file. */
58-
#undef HAVE_STDLIB_H
58+
#cmakedefine HAVE_STDLIB_H @HAVE_STDLIB_H@
5959

6060
/* Define to 1 if you have the <strings.h> header file. */
61-
#undef HAVE_STRINGS_H
61+
#cmakedefine HAVE_STRINGS_H @HAVE_STRINGS_H@
6262

6363
/* Define to 1 if you have the <string.h> header file. */
64-
#undef HAVE_STRING_H
64+
#cmakedefine HAVE_STRING_H @HAVE_STRING_H@
6565

6666
/* Define to 1 if you have the `strstr' function. */
67-
#undef HAVE_STRSTR
67+
#cmakedefine HAVE_STRSTR @HAVE_STRSTR@
6868

6969
/* Define to 1 if you have the <sys/mman.h> header file. */
70-
#undef HAVE_SYS_MMAN_H
70+
#cmakedefine HAVE_SYS_MMAN_H @HAVE_SYS_MMAN_H@
7171

7272
/* Define to 1 if you have the <sys/param.h> header file. */
73-
#undef HAVE_SYS_PARAM_H
73+
#cmakedefine HAVE_SYS_PARAM_H @HAVE_SYS_PARAM_H@
7474

7575
/* Define to 1 if you have the <sys/stat.h> header file. */
76-
#undef HAVE_SYS_STAT_H
76+
#cmakedefine HAVE_SYS_STAT_H @HAVE_SYS_STAT_H@
7777

7878
/* Define to 1 if you have the <sys/times.h> header file. */
79-
#undef HAVE_SYS_TIMES_H
79+
#cmakedefine HAVE_SYS_TIMES_H @HAVE_SYS_TIMES_H@
8080

8181
/* Define to 1 if you have the <sys/types.h> header file. */
82-
#undef HAVE_SYS_TYPES_H
82+
#cmakedefine HAVE_SYS_TYPES_H @HAVE_SYS_TYPES_H@
8383

8484
/* Define to 1 if you have the <unistd.h> header file. */
85-
#undef HAVE_UNISTD_H
85+
#cmakedefine HAVE_UNISTD_H @HAVE_UNISTD_H@
8686

8787
/* Define to 1 if you have the <windows.h> header file. */
88-
#undef HAVE_WINDOWS_H
88+
#cmakedefine HAVE_WINDOWS_H @HAVE_WINDOWS_H@
8989

9090
/* Define to 1 if you have the `iconv_open' library(-liconv). */
91-
#undef ICONV_CONST
91+
#cmakedefine ICONV_CONST @ICONV_CONST@
9292

9393
/* Name of package */
94-
#undef PACKAGE
94+
#cmakedefine PACKAGE "@PACKAGE@"
9595

9696
/* Define to the address where bug reports for this package should be sent. */
97-
#undef PACKAGE_BUGREPORT
97+
#cmakedefine PACKAGE_BUGREPORT "@PACKAGE_BUGREPORT@"
9898

9999
/* Define to the full name of this package. */
100-
#undef PACKAGE_NAME
100+
#cmakedefine PACKAGE_NAME "@PACKAGE_NAME@"
101101

102102
/* Define to the full name and version of this package. */
103-
#undef PACKAGE_STRING
103+
#cmakedefine PACKAGE_STRING "@PACKAGE_STRING@"
104104

105105
/* Define to the one symbol short name of this package. */
106-
#undef PACKAGE_TARNAME
106+
#cmakedefine PACKAGE_TARNAME "@PACKAGE_TARNAME@"
107107

108108
/* Define to the home page for this package. */
109-
#undef PACKAGE_URL
109+
#cmakedefine PACKAGE_URL "@PACKAGE_URL@"
110110

111111
/* Define to the version of this package. */
112-
#undef PACKAGE_VERSION
112+
#cmakedefine PACKAGE_VERSION "@PACKAGE_VERSION@"
113113

114114
/* The size of `char', as computed by sizeof. */
115-
#undef SIZEOF_CHAR
115+
#cmakedefine SIZEOF_CHAR @SIZEOF_CHAR@
116116

117117
/* The size of `int', as computed by sizeof. */
118-
#undef SIZEOF_INT
118+
#cmakedefine SIZEOF_INT @SIZEOF_INT@
119119

120120
/* The size of `long', as computed by sizeof. */
121-
#undef SIZEOF_LONG
121+
#cmakedefine SIZEOF_LONG @SIZEOF_LONG@
122122

123123
/* The size of `long long', as computed by sizeof. */
124-
#undef SIZEOF_LONG_LONG
124+
#cmakedefine SIZEOF_LONG_LONG @SIZEOF_LONG_LONG@
125125

126126
/* The size of `short', as computed by sizeof. */
127-
#undef SIZEOF_SHORT
127+
#cmakedefine SIZEOF_SHORT @SIZEOF_SHORT@
128128

129129
/* The size of `size_t', as computed by sizeof. */
130-
#undef SIZEOF_SIZE_T
130+
#cmakedefine SIZEOF_SIZE_T @SIZEOF_SIZE_T@
131131

132132
/* Define to 1 if you have the ANSI C header files. */
133-
#undef STDC_HEADERS
133+
#cmakedefine STDC_HEADERS @STDC_HEADERS@
134134

135135
/* Version number of package */
136-
#undef VERSION
136+
#cmakedefine VERSION @VERSION@
137137

138138
/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most
139139
significant byte first (like Motorola and SPARC, unlike Intel). */
@@ -148,10 +148,10 @@
148148
#endif
149149

150150
/* Define to empty if `const' does not conform to ANSI C. */
151-
#undef const
151+
#cmakedefine const @const@
152152

153153
/* Define to `long int' if <sys/types.h> does not define. */
154-
#undef off_t
154+
#cmakedefine off_t @off_t@
155155

156156
/* Define to `unsigned int' if <sys/types.h> does not define. */
157-
#undef size_t
157+
#cmakedefine size_t @size_t@

0 commit comments

Comments
 (0)