| 1 |
# |
| 2 |
# Licensed to the Apache Software Foundation (ASF) under one |
| 3 |
# or more contributor license agreements. See the NOTICE file |
| 4 |
# distributed with this work for additional information |
| 5 |
# regarding copyright ownership. The ASF licenses this file |
| 6 |
# to you under the Apache License, Version 2.0 (the |
| 7 |
# "License"); you may not use this file except in compliance |
| 8 |
# with the License. You may obtain a copy of the License at |
| 9 |
# |
| 10 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
# |
| 12 |
# Unless required by applicable law or agreed to in writing, |
| 13 |
# software distributed under the License is distributed on an |
| 14 |
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 |
# KIND, either express or implied. See the License for the |
| 16 |
# specific language governing permissions and limitations |
| 17 |
# under the License. |
| 18 |
# |
| 19 |
|
| 20 |
set(src "${CMAKE_CURRENT_SOURCE_DIR}") |
| 21 |
set(bin "${CMAKE_CURRENT_BINARY_DIR}") |
| 22 |
set(c_lib_dir "$<TARGET_FILE_DIR:qpid-proton>") # Location of qpid-proton library |
| 23 |
|
| 24 |
## Build the swig library |
| 25 |
|
| 26 |
list(APPEND SWIG_MODULE_cproton-ruby_EXTRA_DEPS |
| 27 |
${CMAKE_SOURCE_DIR}/c/include/proton/cproton.i |
| 28 |
${PROTON_HEADERS} |
| 29 |
) |
| 30 |
|
| 31 |
set(CMAKE_SWIG_FLAGS "-DUINTPTR_SIZE=${CMAKE_SIZEOF_VOID_P}") |
| 32 |
# Put the generated source in a known place, we need to copy it for the gem. |
| 33 |
set(SWIG_OUTFILE_DIR "${CMAKE_CURRENT_BINARY_DIR}") |
| 34 |
|
| 35 |
include_directories(${PN_C_INCLUDE_DIR} ${RUBY_INCLUDE_PATH}) |
| 36 |
|
| 37 |
swig_add_library(cproton-ruby LANGUAGE ruby SOURCES cproton.i) |
| 38 |
swig_link_libraries(cproton-ruby ${BINDING_DEPS_FULL} ${RUBY_LIBRARY}) |
| 39 |
|
| 40 |
# Set version-dependent compile flags |
| 41 |
if (RUBY_VERSION VERSION_LESS 1.9.0) |
| 42 |
# Don't have blocking control API |
| 43 |
elseif(RUBY_VERSION VERSION_LESS 2.0.0) |
| 44 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DRUBY_USE_rb_thread_blocking_region") |
| 45 |
else() |
| 46 |
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DRUBY_USE_rb_thread_call_without_gvl") |
| 47 |
endif() |
| 48 |
|
| 49 |
# Remove -fvisibility=hidden, it causes an obscure failure in release builds. |
| 50 |
string(REGEX REPLACE "-fvisibility=[a-z]*" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}") |
| 51 |
|
| 52 |
set_target_properties(cproton-ruby |
| 53 |
PROPERTIES |
| 54 |
PREFIX "" |
| 55 |
OUTPUT_NAME "cproton" |
| 56 |
LINK_FLAGS "${CATCH_UNDEFINED}" ) |
| 57 |
|
| 58 |
## Make a gem |
| 59 |
|
| 60 |
file(GLOB_RECURSE RUBY_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.rb *.rdoc) |
| 61 |
|
| 62 |
find_program(GEM_EXE gem DOC "Program to build and install ruby gem packages") |
| 63 |
mark_as_advanced(GEM_EXE) |
| 64 |
if (GEM_EXE) |
| 65 |
set(GEM_FILE "${bin}/gem/qpid_proton-${PN_VERSION}.gem") |
| 66 |
# Copy source and generated files to the build tree so we can build the gem in one place |
| 67 |
# |
| 68 |
# NOTE: the gem does not need the cproton-ruby library, but it does need |
| 69 |
# cprotonRUBY_wrap.c which is generated as a side effect. We have to depend on |
| 70 |
# cproton-ruby as there's no parallel-safe way to generate only the C file. |
| 71 |
configure_file(${src}/qpid_proton.gemspec.in ${bin}/gem/qpid_proton.gemspec) |
| 72 |
add_custom_command( |
| 73 |
OUTPUT ${GEM_FILE} |
| 74 |
COMMAND ${CMAKE_COMMAND} -E copy_directory ${src} ${bin}/gem |
| 75 |
COMMAND ${CMAKE_COMMAND} -E copy_directory ${src}/examples/ ${bin}/gem/examples |
| 76 |
COMMAND ${CMAKE_COMMAND} -E copy ${bin}/cprotonRUBY_wrap.c ${bin}/gem/ext/cproton/cproton.c |
| 77 |
COMMAND ${GEM_EXE} build qpid_proton.gemspec |
| 78 |
WORKING_DIRECTORY ${bin}/gem |
| 79 |
DEPENDS ${bin}/gem/qpid_proton.gemspec ${RUBY_SRC} ${src}/LICENSE.txt |
| 80 |
cproton-ruby |
| 81 |
) |
| 82 |
|
| 83 |
add_custom_target(ruby-gem ALL DEPENDS ${GEM_FILE}) |
| 84 |
endif () |
| 85 |
|
| 86 |
## CMake-based install |
| 87 |
|
| 88 |
if (CHECK_SYSINSTALL_RUBY) |
| 89 |
execute_process(COMMAND ${RUBY_EXECUTABLE} |
| 90 |
-r rbconfig -e "print RbConfig::CONFIG['vendorarchdir'] || ''" |
| 91 |
RESULT_VARIABLE RESULT_RUBY_ARCHLIB_DIR |
| 92 |
OUTPUT_VARIABLE OUTPUT_RUBY_ARCHLIB_DIR) |
| 93 |
|
| 94 |
if(OUTPUT_RUBY_ARCHLIB_DIR STREQUAL "") |
| 95 |
execute_process(COMMAND ${RUBY_EXECUTABLE} |
| 96 |
-r rbconfig -e "print RbConfig::CONFIG['archdir'] || ''" |
| 97 |
RESULT_VARIABLE RESULT_RUBY_ARCHLIB_DIR |
| 98 |
OUTPUT_VARIABLE OUTPUT_RUBY_ARCHLIB_DIR) |
| 99 |
endif() |
| 100 |
|
| 101 |
set(RUBY_ARCHLIB_DIR_DEFAULT "${OUTPUT_RUBY_ARCHLIB_DIR}") |
| 102 |
else (CHECK_SYSINSTALL_RUBY) |
| 103 |
set (RUBY_ARCHLIB_DIR_DEFAULT ${BINDINGS_DIR}/ruby) |
| 104 |
endif (CHECK_SYSINSTALL_RUBY) |
| 105 |
|
| 106 |
if (NOT RUBY_ARCHLIB_DIR) |
| 107 |
set (RUBY_ARCHLIB_DIR ${RUBY_ARCHLIB_DIR_DEFAULT}) |
| 108 |
endif() |
| 109 |
|
| 110 |
install(TARGETS cproton-ruby DESTINATION ${RUBY_ARCHLIB_DIR} COMPONENT Ruby) |
| 111 |
install(DIRECTORY lib/ DESTINATION ${RUBY_ARCHLIB_DIR} COMPONENT Ruby) |
| 112 |
install(DIRECTORY examples/ |
| 113 |
DESTINATION "${PROTON_SHARE}/examples/ruby" |
| 114 |
COMPONENT Ruby |
| 115 |
USE_SOURCE_PERMISSIONS) |
| 116 |
## Tests |
| 117 |
|
| 118 |
to_native_path("${src}/lib;${src}/tests;${src}/spec;${bin};${c_lib_dir};$ENV{RUBYLIB}" RUBYLIB) |
| 119 |
to_native_path("${bin};${c_lib_dir};$ENV{PATH}" PATH) |
| 120 |
|
| 121 |
if (CMAKE_BUILD_TYPE MATCHES "Coverage") |
| 122 |
set(COVERAGE "COVERAGE=1") |
| 123 |
endif () |
| 124 |
|
| 125 |
execute_process(COMMAND ${RUBY_EXECUTABLE} -r minitest -e "" |
| 126 |
RESULT_VARIABLE result OUTPUT_QUIET ERROR_QUIET) |
| 127 |
if (result EQUAL 0) # Have minitest |
| 128 |
set(test_env |
| 129 |
"PATH=${PATH}" |
| 130 |
"RUBYLIB=${RUBYLIB}" |
| 131 |
"${COVERAGE}" |
| 132 |
"COVERAGE_DIR=${CMAKE_CURRENT_BINARY_DIR}/coverage" |
| 133 |
"SASLPASSWD=${CyrusSASL_Saslpasswd_EXECUTABLE}") |
| 134 |
|
| 135 |
macro(add_ruby_test script) |
| 136 |
get_filename_component(name ${script} NAME_WE) |
| 137 |
string(REPLACE "_" "-" name "ruby-${name}") |
| 138 |
pn_add_test( |
| 139 |
INTERPRETED |
| 140 |
NAME ${name} |
| 141 |
PREPEND_ENVIRONMENT ${test_env} |
| 142 |
COMMAND ${RUBY_EXECUTABLE} -r${CMAKE_CURRENT_SOURCE_DIR}/tests/collect_coverage.rb ${script} -v |
| 143 |
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} # simplecov doesn't report on code not under $CWD |
| 144 |
${ARGN}) |
| 145 |
endmacro() |
| 146 |
|
| 147 |
pn_add_test( |
| 148 |
INTERPRETED |
| 149 |
NAME ruby-example-test |
| 150 |
PREPEND_ENVIRONMENT ${test_env} |
| 151 |
COMMAND ${RUBY_EXECUTABLE} testme -v |
| 152 |
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/examples) |
| 153 |
|
| 154 |
file(GLOB TESTS tests/test_*.rb) |
| 155 |
file(GLOB SPECS spec/*_spec.rb) |
| 156 |
foreach(t ${TESTS} ${SPECS}) |
| 157 |
add_ruby_test(${t}) |
| 158 |
endforeach() |
| 159 |
else() |
| 160 |
# No minitest |
| 161 |
message(STATUS "Ruby tests will not run, minitest is not installed") |
| 162 |
endif() |
| 163 |
|
| 164 |
## Documentation |
| 165 |
|
| 166 |
find_program(YARD_EXE "yard") |
| 167 |
if (YARD_EXE) |
| 168 |
file(GLOB_RECURSE TEMPLATES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "doc/templates/**") |
| 169 |
add_custom_command( |
| 170 |
OUTPUT ${bin}/doc |
| 171 |
WORKING_DIRECTORY ${src} |
| 172 |
COMMAND ${YARD_EXE} -o ${bin}/doc -b ${bin}/.yardoc -p ${src}/doc/templates |
| 173 |
DEPENDS ${RUBY_SRC} ${TEMPLATES} .yardopts |
| 174 |
) |
| 175 |
add_custom_target(docs-ruby DEPENDS ${bin}/doc) |
| 176 |
add_dependencies (docs docs-ruby) |
| 177 |
install(DIRECTORY "${bin}/doc/" |
| 178 |
DESTINATION "${PROTON_SHARE}/docs/api-ruby" |
| 179 |
COMPONENT documentation |
| 180 |
OPTIONAL) |
| 181 |
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES doc) |
| 182 |
endif() |