cmake: add mruby support, fix tests dir

mruby is always invoked now (mirrors the autotools behavior). It could
be optimized though to only trigger the mruby build when the static
library is missing.

Also fix typo in NGHTTP2_TESTS_DIR macro definition (detected when
invoking the Ninja generator).
This commit is contained in:
Peter Wu 2016-02-15 23:14:27 +01:00
parent 474ecc4b47
commit f407f7f406
3 changed files with 46 additions and 31 deletions

View File

@ -295,7 +295,9 @@ if(ENABLE_EXAMPLES OR ENABLE_APP OR ENABLE_HPACK_TOOLS OR ENABLE_ASIO_LIB)
# mruby (for src/nghttpx) # mruby (for src/nghttpx)
if(WITH_MRUBY) if(WITH_MRUBY)
set(HAVE_MRUBY 1) set(HAVE_MRUBY 1)
# XXX add -lmruby and -lm libs set(MRUBY_LIBRARY
"${CMAKE_BINARY_DIR}/third-party/mruby/build/lib/${CMAKE_STATIC_LIBRARY_PREFIX}mruby${CMAKE_STATIC_LIBRARY_SUFFIX}"
)
else() else()
set(HAVE_MRUBY 0) set(HAVE_MRUBY 0)
endif() endif()

View File

@ -131,15 +131,7 @@ if(ENABLE_APP)
) )
if(HAVE_MRUBY) if(HAVE_MRUBY)
target_include_directories(nghttpx PRIVATE target_link_libraries(nghttpx mruby-lib)
"${CMAKE_SOURCE_DIR}/third-party/mruby/include"
# ${LIBMRUBY_CFLAGS}
)
target_link_libraries(nghttpx
# nghttpx_LDADD += -L${top_builddir}/third-party/mruby/build/lib
# XXX find_library or other absolute path?
# ${LIBMRUBY_LIBS}
)
endif() endif()
if(HAVE_NEVERBLEED) if(HAVE_NEVERBLEED)
@ -170,16 +162,12 @@ if(ENABLE_APP)
) )
target_include_directories(nghttpx-unittest PRIVATE ${CUNIT_INCLUDE_DIRS}) target_include_directories(nghttpx-unittest PRIVATE ${CUNIT_INCLUDE_DIRS})
target_compile_definitions(nghttpx-unittest target_compile_definitions(nghttpx-unittest
PRIVATE "-DNGHTTP2_TESTS_DIR=\"$(CMAKE_SOURCE_DIR)/tests\"" PRIVATE "-DNGHTTP2_TESTS_DIR=\"${CMAKE_SOURCE_DIR}/tests\""
) )
target_link_libraries(nghttpx-unittest nghttpx ${CUNIT_LIBRARIES}) target_link_libraries(nghttpx-unittest nghttpx ${CUNIT_LIBRARIES})
# if HAVE_MRUBY if(HAVE_MRUBY)
# nghttpx_unittest_CPPFLAGS += target_link_libraries(nghttpx-unittest mruby-lib)
# -I${top_srcdir}/third-party/mruby/include @LIBMRUBY_CFLAGS@ endif()
# nghttpx_unittest_LDADD +=
# -L${top_builddir}/third-party/mruby/build/lib @LIBMRUBY_LIBS@
# endif # HAVE_MRUBY
#
if(HAVE_NEVERBLEED) if(HAVE_NEVERBLEED)
target_link_libraries(nghttpx-unittest neverbleed) target_link_libraries(nghttpx-unittest neverbleed)
endif() endif()

View File

@ -17,22 +17,47 @@ if(ENABLE_THIRD_PARTY)
endif() endif()
if(HAVE_MRUBY) if(HAVE_MRUBY)
## EXTRA_DIST = build_config.rb mruby/* # EXTRA_DIST = build_config.rb mruby/*
#.PHONY: all-local clean mruby set(MRUBY_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/mruby/build")
set(MRUBY_LIBRARY
"${CMAKE_STATIC_LIBRARY_PREFIX}mruby${CMAKE_STATIC_LIBRARY_SUFFIX}"
)
#mruby: # The mruby build needs some env vars. Alternatively, look at cmake -P
# MRUBY_CONFIG="${srcdir}/build_config.rb" \ if(CMAKE_VERSION VERSION_LESS "3.1")
# BUILD_DIR="${abs_builddir}/mruby/build" \ # XXX works only for Unixes?
# INSTALL_DIR="${abs_builddir}/mruby/build/install/bin" \ set(ENV_COMMAND env)
# CC="${CC}" CXX="${CXX}" LD="${LD}" \ else()
# CFLAGS="${CPPFLAGS} ${CFLAGS}" CXXFLAGS="${CPPFLAGS} ${CXXFLAGS}" \ set(ENV_COMMAND ${CMAKE_COMMAND} -E env)
# LDFLAGS="${LDFLAGS}" \ endif()
# "${srcdir}/mruby/minirake" -f "${srcdir}/mruby/Rakefile" # Required for the Ninja generator. For older CMake, you first have to
# invoke 'ninja mruby' before building dependents.
if(CMAKE_VERSION VERSION_LESS "3.2")
set(_byproducts)
else()
set(_byproducts BYPRODUCTS "mruby/build/lib/${MRUBY_LIBRARY}")
endif()
add_custom_target(mruby
COMMAND ${ENV_COMMAND}
"MRUBY_CONFIG=${CMAKE_CURRENT_SOURCE_DIR}/build_config.rb"
"BUILD_DIR=${MRUBY_BUILD_DIR}"
"INSTALL_DIR=${MRUBY_BUILD_DIR}/install/bin"
"CC=${CMAKE_C_COMPILER}" "CXX=${CMAKE_CXX_COMPILER}"
"${CMAKE_CURRENT_SOURCE_DIR}/mruby/minirake"
-f "${CMAKE_CURRENT_SOURCE_DIR}/mruby/Rakefile"
${_byproducts}
VERBATIM
)
#all-local: mruby # Make the mruby library available to others in this project without them
# having to worry about include dirs and the mruby location.
add_library(mruby-lib STATIC IMPORTED GLOBAL)
set_target_properties(mruby-lib PROPERTIES
IMPORTED_LOCATION "${MRUBY_BUILD_DIR}/lib/${MRUBY_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/mruby/include"
)
#clean-local: # XXX clean ${CMAKE_CURRENT_BINARY_DIR}/mruby/build
# -rm -rf "${abs_builddir}/mruby/build"
endif() endif()
endif() endif()