| 1 |
# Copyright(C) 2015-2018 Kouhei Sutou <[email protected]> |
| 2 |
# |
| 3 |
# This library is free software; you can redistribute it and/or |
| 4 |
# modify it under the terms of the GNU Lesser General Public |
| 5 |
# License as published by the Free Software Foundation; either |
| 6 |
# version 2.1 of the License, or (at your option) any later version. |
| 7 |
# |
| 8 |
# This library 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 GNU |
| 11 |
# Lesser General Public License for more details. |
| 12 |
# |
| 13 |
# You should have received a copy of the GNU Lesser General Public |
| 14 |
# License along with this library; if not, write to the Free Software |
| 15 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 16 |
|
| 17 |
if(GRN_WITH_ONIGMO) |
| 18 |
set(ONIGMO_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../onigmo-source") |
| 19 |
set(ONIGMO_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/../onigmo-source") |
| 20 |
|
| 21 |
include(CheckTypeSize) |
| 22 |
|
| 23 |
macro(ac_check_sizeof type) |
| 24 |
string(TOUPPER "${type}" output_variable_base_name) |
| 25 |
string(REPLACE "*" "P" |
| 26 |
output_variable_base_name |
| 27 |
"${output_variable_base_name}") |
| 28 |
string(REPLACE " " "_" |
| 29 |
output_variable_base_name |
| 30 |
"${output_variable_base_name}") |
| 31 |
set(output_variable_name "ONIG_SIZEOF_${output_variable_base_name}") |
| 32 |
check_type_size(${type} ${output_variable_name}) |
| 33 |
if(HAVE_${output_variable_name}) |
| 34 |
add_definitions( |
| 35 |
-DSIZEOF_${output_variable_base_name}=${${output_variable_name}} |
| 36 |
) |
| 37 |
endif() |
| 38 |
endmacro() |
| 39 |
|
| 40 |
ac_check_sizeof(short) |
| 41 |
ac_check_sizeof(int) |
| 42 |
ac_check_sizeof(long) |
| 43 |
ac_check_sizeof("void*") |
| 44 |
ac_check_sizeof("long long") |
| 45 |
|
| 46 |
add_definitions(-DHAVE_STDARG_H) |
| 47 |
add_definitions(-DHAVE_STDINT_H) |
| 48 |
add_definitions(-DHAVE_STDLIB_H) |
| 49 |
add_definitions(-DHAVE_STRING_H) |
| 50 |
add_definitions(-DHAVE_SYS_TYPES_H) |
| 51 |
|
| 52 |
add_definitions(-DSTDC_HEADERS) |
| 53 |
|
| 54 |
if(MSVC) |
| 55 |
add_definitions(-Dinline=__inline) |
| 56 |
add_definitions(-D_CRT_SECURE_NO_WARNINGS) |
| 57 |
else() |
| 58 |
add_definitions(-DHAVE_INTTYPES_H) |
| 59 |
endif() |
| 60 |
|
| 61 |
check_cflag("-Wno-missing-field-initializers") |
| 62 |
|
| 63 |
include_directories( |
| 64 |
BEFORE |
| 65 |
${ONIGMO_BINARY_DIR} |
| 66 |
${ONIGMO_SOURCE_DIR} |
| 67 |
${ONIGMO_SOURCE_DIR}/enc/unicode |
| 68 |
) |
| 69 |
|
| 70 |
set(ONIGMO_SOURCES |
| 71 |
"${ONIGMO_SOURCE_DIR}/regint.h" |
| 72 |
"${ONIGMO_SOURCE_DIR}/regparse.h" |
| 73 |
"${ONIGMO_SOURCE_DIR}/regenc.h" |
| 74 |
"${ONIGMO_SOURCE_DIR}/st.h" |
| 75 |
"${ONIGMO_SOURCE_DIR}/regerror.c" |
| 76 |
"${ONIGMO_SOURCE_DIR}/regparse.c" |
| 77 |
"${ONIGMO_SOURCE_DIR}/regext.c" |
| 78 |
"${ONIGMO_SOURCE_DIR}/regcomp.c" |
| 79 |
"${ONIGMO_SOURCE_DIR}/regexec.c" |
| 80 |
"${ONIGMO_SOURCE_DIR}/reggnu.c" |
| 81 |
"${ONIGMO_SOURCE_DIR}/regenc.c" |
| 82 |
"${ONIGMO_SOURCE_DIR}/regsyntax.c" |
| 83 |
"${ONIGMO_SOURCE_DIR}/regtrav.c" |
| 84 |
"${ONIGMO_SOURCE_DIR}/regversion.c" |
| 85 |
"${ONIGMO_SOURCE_DIR}/st.c" |
| 86 |
"${ONIGMO_SOURCE_DIR}/regposix.c" |
| 87 |
"${ONIGMO_SOURCE_DIR}/regposerr.c" |
| 88 |
"${ONIGMO_SOURCE_DIR}/enc/unicode.c" |
| 89 |
"${ONIGMO_SOURCE_DIR}/enc/ascii.c" |
| 90 |
"${ONIGMO_SOURCE_DIR}/enc/utf_8.c" |
| 91 |
"${ONIGMO_SOURCE_DIR}/enc/utf_16be.c" |
| 92 |
"${ONIGMO_SOURCE_DIR}/enc/utf_16le.c" |
| 93 |
"${ONIGMO_SOURCE_DIR}/enc/utf_32be.c" |
| 94 |
"${ONIGMO_SOURCE_DIR}/enc/utf_32le.c" |
| 95 |
"${ONIGMO_SOURCE_DIR}/enc/unicode/casefold.h" |
| 96 |
"${ONIGMO_SOURCE_DIR}/enc/unicode/name2ctype.h" |
| 97 |
"${ONIGMO_SOURCE_DIR}/enc/euc_jp.c" |
| 98 |
"${ONIGMO_SOURCE_DIR}/enc/shift_jis.c" |
| 99 |
"${ONIGMO_SOURCE_DIR}/enc/windows_31j.c" |
| 100 |
"${ONIGMO_SOURCE_DIR}/enc/jis/props.h" |
| 101 |
# "${ONIGMO_SOURCE_DIR}/enc/jis/props.kwd" |
| 102 |
"${ONIGMO_SOURCE_DIR}/enc/iso_8859.h" |
| 103 |
"${ONIGMO_SOURCE_DIR}/enc/iso_8859_1.c" |
| 104 |
"${ONIGMO_SOURCE_DIR}/enc/iso_8859_2.c" |
| 105 |
"${ONIGMO_SOURCE_DIR}/enc/iso_8859_3.c" |
| 106 |
"${ONIGMO_SOURCE_DIR}/enc/iso_8859_4.c" |
| 107 |
"${ONIGMO_SOURCE_DIR}/enc/iso_8859_5.c" |
| 108 |
"${ONIGMO_SOURCE_DIR}/enc/iso_8859_6.c" |
| 109 |
"${ONIGMO_SOURCE_DIR}/enc/iso_8859_7.c" |
| 110 |
"${ONIGMO_SOURCE_DIR}/enc/iso_8859_8.c" |
| 111 |
"${ONIGMO_SOURCE_DIR}/enc/iso_8859_9.c" |
| 112 |
"${ONIGMO_SOURCE_DIR}/enc/iso_8859_10.c" |
| 113 |
"${ONIGMO_SOURCE_DIR}/enc/iso_8859_11.c" |
| 114 |
"${ONIGMO_SOURCE_DIR}/enc/iso_8859_13.c" |
| 115 |
"${ONIGMO_SOURCE_DIR}/enc/iso_8859_14.c" |
| 116 |
"${ONIGMO_SOURCE_DIR}/enc/iso_8859_15.c" |
| 117 |
"${ONIGMO_SOURCE_DIR}/enc/iso_8859_16.c" |
| 118 |
"${ONIGMO_SOURCE_DIR}/enc/euc_tw.c" |
| 119 |
"${ONIGMO_SOURCE_DIR}/enc/euc_kr.c" |
| 120 |
"${ONIGMO_SOURCE_DIR}/enc/big5.c" |
| 121 |
"${ONIGMO_SOURCE_DIR}/enc/gb18030.c" |
| 122 |
"${ONIGMO_SOURCE_DIR}/enc/koi8_r.c" |
| 123 |
"${ONIGMO_SOURCE_DIR}/enc/koi8_u.c" |
| 124 |
"${ONIGMO_SOURCE_DIR}/enc/windows_1250.c" |
| 125 |
"${ONIGMO_SOURCE_DIR}/enc/windows_1251.c" |
| 126 |
"${ONIGMO_SOURCE_DIR}/enc/windows_1252.c" |
| 127 |
"${ONIGMO_SOURCE_DIR}/enc/windows_1253.c" |
| 128 |
"${ONIGMO_SOURCE_DIR}/enc/windows_1254.c" |
| 129 |
"${ONIGMO_SOURCE_DIR}/enc/windows_1257.c" |
| 130 |
) |
| 131 |
|
| 132 |
set(ONIGMO_C_COMPILE_FLAGS "${GRN_C_COMPILE_FLAGS}") |
| 133 |
if(CMAKE_C_COMPILER_ID STREQUAL "Clang") |
| 134 |
# st_hash_type::hash doesn't have prototype of arguments. |
| 135 |
# It's not supported in C23. |
| 136 |
# TODO: We should fix Onigmo. |
| 137 |
string(APPEND ONIGMO_C_COMPILE_FLAGS " -Wno-deprecated-non-prototype") |
| 138 |
endif() |
| 139 |
|
| 140 |
add_library(onigmo STATIC ${ONIGMO_SOURCES}) |
| 141 |
set_source_files_properties(${ONIGMO_SOURCES} |
| 142 |
PROPERTIES |
| 143 |
COMPILE_FLAGS "${ONIGMO_C_COMPILE_FLAGS}") |
| 144 |
set_target_properties( |
| 145 |
onigmo |
| 146 |
PROPERTIES |
| 147 |
POSITION_INDEPENDENT_CODE ON) |
| 148 |
target_include_directories(onigmo INTERFACE "${ONIGMO_SOURCE_DIR}") |
| 149 |
target_compile_definitions(onigmo PUBLIC "ONIG_EXTERN=extern") |
| 150 |
|
| 151 |
configure_file(config.h.cmake "${ONIGMO_BINARY_DIR}/config.h") |
| 152 |
|
| 153 |
install(FILES |
| 154 |
"${ONIGMO_SOURCE_DIR}/AUTHORS" |
| 155 |
"${ONIGMO_SOURCE_DIR}/COPYING" |
| 156 |
"${ONIGMO_SOURCE_DIR}/HISTORY" |
| 157 |
"${ONIGMO_SOURCE_DIR}/README" |
| 158 |
DESTINATION "${GRN_DATA_DIR}/onigmo") |
| 159 |
endif() |