| 1 |
# Copyright (C) 2013-2018 Brazil |
| 2 |
# Copyright (C) 2019-2025 Sutou Kouhei <[email protected]> |
| 3 |
# |
| 4 |
# This library is free software; you can redistribute it and/or |
| 5 |
# modify it under the terms of the GNU Lesser General Public |
| 6 |
# License as published by the Free Software Foundation; either |
| 7 |
# version 2.1 of the License, or (at your option) any later version. |
| 8 |
# |
| 9 |
# This library is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
# Lesser General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU Lesser General Public |
| 15 |
# License along with this library; if not, write to the Free Software |
| 16 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 |
|
| 18 |
if(GRN_WITH_MRUBY) |
| 19 |
set(MRUBY_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../mruby-source") |
| 20 |
|
| 21 |
read_file_list("${CMAKE_CURRENT_SOURCE_DIR}/sources.am" MRUBY_SOURCES) |
| 22 |
string(REGEX REPLACE "\\.\\./" "${CMAKE_CURRENT_SOURCE_DIR}/../" |
| 23 |
MRUBY_SOURCES "${MRUBY_SOURCES}") |
| 24 |
|
| 25 |
read_file_list("${CMAKE_CURRENT_SOURCE_DIR}/built_sources.am" |
| 26 |
MRUBY_BUILT_SOURCES) |
| 27 |
set_source_files_properties( |
| 28 |
${CMAKE_CURRENT_SOURCE_DIR}/mrbgems/mruby-file-stat/src/file-stat.c |
| 29 |
PROPERTIES INCLUDE_DIRECTORIES ${CMAKE_CURRENT_BINARY_DIR}/mrbgems/mruby-file-stat/src) |
| 30 |
set(mruby_pre_build_timestamp |
| 31 |
"${CMAKE_CURRENT_SOURCE_DIR}/mruby_build.timestamp") |
| 32 |
if(EXISTS "${mruby_pre_build_timestamp}") |
| 33 |
set(MRUBY_LEGAL_FILE "${CMAKE_CURRENT_SOURCE_DIR}/LEGAL") |
| 34 |
string(REGEX REPLACE "([^;]+)" "${CMAKE_CURRENT_SOURCE_DIR}/\\1" |
| 35 |
MRUBY_BUILT_SOURCES "${MRUBY_BUILT_SOURCES}") |
| 36 |
else() |
| 37 |
set(mruby_build_timestamp |
| 38 |
"${CMAKE_CURRENT_BINARY_DIR}/mruby_build.timestamp") |
| 39 |
if(NOT EXISTS "${mruby_build_timestamp}") |
| 40 |
set(MRUBY_BUILD_COMMAND) |
| 41 |
if(MSVC) |
| 42 |
list(APPEND MRUBY_BUILD_COMMAND |
| 43 |
${CMAKE_COMMAND} |
| 44 |
-E |
| 45 |
env |
| 46 |
"CC=\"${CMAKE_C_COMPILER}\"" |
| 47 |
"CXX=\"${CMAKE_CXX_COMPILER}\"" |
| 48 |
"MRUBY_VC=yes") |
| 49 |
endif() |
| 50 |
list(APPEND MRUBY_BUILD_COMMAND |
| 51 |
"${RUBY}" |
| 52 |
"${CMAKE_CURRENT_SOURCE_DIR}/mruby_build.rb" |
| 53 |
"${CMAKE_CURRENT_SOURCE_DIR}/build_config.rb" |
| 54 |
"${MRUBY_SOURCE_DIR}" |
| 55 |
"${CMAKE_CURRENT_BINARY_DIR}/../mruby-build" |
| 56 |
"${CMAKE_CURRENT_SOURCE_DIR}/../onigmo-source" |
| 57 |
"${mruby_build_timestamp}" |
| 58 |
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" |
| 59 |
RESULT_VARIABLE MRUBY_BUILD_RESULT) |
| 60 |
execute_process(COMMAND ${MRUBY_BUILD_COMMAND}) |
| 61 |
if(NOT MRUBY_BUILD_RESULT EQUAL "0") |
| 62 |
message(FATAL_ERROR "Failed to build mruby files") |
| 63 |
endif() |
| 64 |
endif() |
| 65 |
set(MRUBY_LEGAL_FILE "${CMAKE_CURRENT_BINARY_DIR}/LEGAL") |
| 66 |
string(REGEX REPLACE "([^;]+)" "${CMAKE_CURRENT_BINARY_DIR}/\\1" |
| 67 |
MRUBY_BUILT_SOURCES "${MRUBY_BUILT_SOURCES}") |
| 68 |
endif() |
| 69 |
if(HAVE_SYS_SYSMACROS_H) |
| 70 |
set(MRUBY_FILE_STAT_CONFIG_H_CONTENT "#define HAVE_SYS_SYSMACROS_H 1") |
| 71 |
else() |
| 72 |
set(MRUBY_FILE_STAT_CONFIG_H_CONTENT "") |
| 73 |
endif() |
| 74 |
file(WRITE |
| 75 |
"${CMAKE_CURRENT_BINARY_DIR}/mrbgems/mruby-file-stat/src/config.h" |
| 76 |
"${MRUBY_FILE_STAT_CONFIG_H_CONTENT}") |
| 77 |
|
| 78 |
set(MRUBY_ALL_SOURCES |
| 79 |
${MRUBY_SOURCES} |
| 80 |
${MRUBY_BUILT_SOURCES} |
| 81 |
"${CMAKE_CURRENT_BINARY_DIR}/mrbgems/mruby-file-stat/src/config.h" |
| 82 |
) |
| 83 |
add_library(mruby_headers INTERFACE) |
| 84 |
target_include_directories(mruby_headers INTERFACE |
| 85 |
"${MRUBY_SOURCE_DIR}/include") |
| 86 |
add_library(mruby STATIC ${MRUBY_ALL_SOURCES}) |
| 87 |
target_include_directories(mruby |
| 88 |
PUBLIC |
| 89 |
"${MRUBY_SOURCE_DIR}/include" |
| 90 |
PRIVATE |
| 91 |
# For build from repository |
| 92 |
"${CMAKE_CURRENT_BINARY_DIR}/mruby-include" |
| 93 |
# For build from archive |
| 94 |
"${CMAKE_CURRENT_SOURCE_DIR}/../mruby-include" |
| 95 |
"${MRUBY_SOURCE_DIR}/src" |
| 96 |
"${MRUBY_SOURCE_DIR}/mrbgems/mruby-compiler/core" |
| 97 |
"${MRUBY_SOURCE_DIR}/mrbgems/mruby-io/include" |
| 98 |
"${MRUBY_SOURCE_DIR}/mrbgems/mruby-time/include" |
| 99 |
"${CMAKE_CURRENT_SOURCE_DIR}/../onigmo-source" |
| 100 |
) |
| 101 |
target_compile_definitions(mruby PUBLIC "MRB_INT64" "HAVE_ONIGMO_H") |
| 102 |
if(NOT EXISTS "${CMAKE_CURRENT_BINARY_DIR}/mruby-include" AND |
| 103 |
NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/../mruby-include") |
| 104 |
target_compile_definitions(mruby PUBLIC "MRB_NO_PRESYM") |
| 105 |
endif() |
| 106 |
if(WIN32) |
| 107 |
target_compile_definitions(mruby PRIVATE "MRB_BUILD_AS_DLL" "MRB_CORE") |
| 108 |
target_link_libraries(mruby PUBLIC ws2_32.lib) |
| 109 |
endif() |
| 110 |
set_target_properties( |
| 111 |
mruby |
| 112 |
PROPERTIES |
| 113 |
POSITION_INDEPENDENT_CODE ON) |
| 114 |
|
| 115 |
set(MRUBY_C_COMPILE_FLAGS "${GRN_C_COMPILE_FLAGS}") |
| 116 |
if(GRN_C_COMPILER_GNU_LIKE) |
| 117 |
string(APPEND MRUBY_C_COMPILE_FLAGS " -Wno-bad-function-cast") |
| 118 |
string(APPEND MRUBY_C_COMPILE_FLAGS " -Wno-float-equal") |
| 119 |
string(APPEND MRUBY_C_COMPILE_FLAGS " -Wno-missing-field-initializers") |
| 120 |
string(APPEND MRUBY_C_COMPILE_FLAGS " -Wno-sign-compare") |
| 121 |
string(APPEND MRUBY_C_COMPILE_FLAGS " -Wno-type-limits") |
| 122 |
elseif(MSVC) |
| 123 |
# 'token' : signed/unsigned mismatch |
| 124 |
# https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4018 |
| 125 |
string(APPEND MRUBY_C_COMPILE_FLAGS " /wd4018") |
| 126 |
# formal parameter 'number' different from declaration |
| 127 |
# https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4028 |
| 128 |
string(APPEND MRUBY_C_COMPILE_FLAGS " /wd4028") |
| 129 |
# 'argument' : conversion from 'type1' to 'type2', possible loss of data |
| 130 |
# https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4244 |
| 131 |
string(APPEND MRUBY_C_COMPILE_FLAGS " /wd4244") |
| 132 |
# 'var' : conversion from 'size_t' to 'type', possible loss of data |
| 133 |
# https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4267 |
| 134 |
string(APPEND MRUBY_C_COMPILE_FLAGS " /wd4267") |
| 135 |
# 'function' : inconsistent DLL linkage |
| 136 |
# https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4273 |
| 137 |
string(APPEND MRUBY_C_COMPILE_FLAGS " /wd4273") |
| 138 |
# Your code uses a function, class member, variable, or typedef |
| 139 |
# that's marked deprecated. |
| 140 |
# https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-3-c4996 |
| 141 |
string(APPEND MRUBY_C_COMPILE_FLAGS " /wd4996") |
| 142 |
endif() |
| 143 |
set_source_files_properties(${MRUBY_ALL_SOURCES} |
| 144 |
PROPERTIES |
| 145 |
COMPILE_FLAGS "${MRUBY_C_COMPILE_FLAGS}") |
| 146 |
|
| 147 |
install(FILES |
| 148 |
"${MRUBY_LEGAL_FILE}" |
| 149 |
"${MRUBY_SOURCE_DIR}/AUTHORS" |
| 150 |
"${MRUBY_SOURCE_DIR}/README.md" |
| 151 |
"${MRUBY_SOURCE_DIR}/LICENSE" |
| 152 |
DESTINATION "${GRN_DATA_DIR}/mruby") |
| 153 |
endif() |