diff --git a/CMakeLists.txt b/CMakeLists.txt index 938f0c2b..58882726 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -295,7 +295,9 @@ if(ENABLE_EXAMPLES OR ENABLE_APP OR ENABLE_HPACK_TOOLS OR ENABLE_ASIO_LIB) # mruby (for src/nghttpx) if(WITH_MRUBY) 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() set(HAVE_MRUBY 0) endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f5a97a20..47d8124a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -131,15 +131,7 @@ if(ENABLE_APP) ) if(HAVE_MRUBY) - target_include_directories(nghttpx PRIVATE - "${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} - ) + target_link_libraries(nghttpx mruby-lib) endif() if(HAVE_NEVERBLEED) @@ -170,16 +162,12 @@ if(ENABLE_APP) ) target_include_directories(nghttpx-unittest PRIVATE ${CUNIT_INCLUDE_DIRS}) 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}) - # if HAVE_MRUBY - # nghttpx_unittest_CPPFLAGS += - # -I${top_srcdir}/third-party/mruby/include @LIBMRUBY_CFLAGS@ - # nghttpx_unittest_LDADD += - # -L${top_builddir}/third-party/mruby/build/lib @LIBMRUBY_LIBS@ - # endif # HAVE_MRUBY - # + if(HAVE_MRUBY) + target_link_libraries(nghttpx-unittest mruby-lib) + endif() if(HAVE_NEVERBLEED) target_link_libraries(nghttpx-unittest neverbleed) endif() diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index f90a5ee0..de5243a1 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -17,22 +17,47 @@ if(ENABLE_THIRD_PARTY) endif() 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: - # MRUBY_CONFIG="${srcdir}/build_config.rb" \ - # BUILD_DIR="${abs_builddir}/mruby/build" \ - # INSTALL_DIR="${abs_builddir}/mruby/build/install/bin" \ - # CC="${CC}" CXX="${CXX}" LD="${LD}" \ - # CFLAGS="${CPPFLAGS} ${CFLAGS}" CXXFLAGS="${CPPFLAGS} ${CXXFLAGS}" \ - # LDFLAGS="${LDFLAGS}" \ - # "${srcdir}/mruby/minirake" -f "${srcdir}/mruby/Rakefile" + # The mruby build needs some env vars. Alternatively, look at cmake -P + if(CMAKE_VERSION VERSION_LESS "3.1") + # XXX works only for Unixes? + set(ENV_COMMAND env) + else() + set(ENV_COMMAND ${CMAKE_COMMAND} -E env) + endif() + # 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: - # -rm -rf "${abs_builddir}/mruby/build" + # XXX clean ${CMAKE_CURRENT_BINARY_DIR}/mruby/build endif() endif()