cmake: process tests directory

Split the nghttp2 library into objects and a shared library from those
objects. This is needed because of symbol visibility. An advantage over
the autotools build is that there are no worries about static versus
static library builds.

Test:

    cmake $srcdir
    make nghttpx-unittest main failmalloc
    make test
This commit is contained in:
Peter Wu 2016-02-15 01:57:13 +01:00
parent cc92ebf471
commit 8c46d9181f
4 changed files with 81 additions and 24 deletions

View File

@ -140,8 +140,6 @@ cmake_pop_check_state()
# Checks for libraries.
# Additional libraries required for tests.
set(TEST_LIBRARIES)
# Additional libraries required for programs under src directory.
set(APP_LIBRARIES)
@ -163,6 +161,7 @@ endif()
find_package(CUnit 2.1)
if(CUNIT_FOUND)
enable_testing()
set(HAVE_CUNIT 1)
else()
set(HAVE_CUNIT 0)
@ -457,7 +456,6 @@ endif()
# # propagate $enable_static to tests/Makefile.am
# AM_CONDITIONAL([ENABLE_STATIC], [test "x$enable_static" = "xyes"])
#
# AC_SUBST([TESTLDADD])
# AC_SUBST([APPLDFLAGS])
add_definitions(-DHAVE_CONFIG_H)
@ -519,10 +517,8 @@ add_subdirectory(src)
#add_subdirectory(src/includes)
add_subdirectory(examples)
add_subdirectory(python)
if(0)
add_subdirectory(tests)
#add_subdirectory(tests/testdata)
endif()
add_subdirectory(integration-tests)
add_subdirectory(doc)
add_subdirectory(contrib)

View File

@ -24,7 +24,8 @@ set(NGHTTP2_SOURCES
nghttp2_http.c
)
add_library(nghttp2 SHARED ${NGHTTP2_SOURCES})
add_library(nghttp2-obj OBJECT ${NGHTTP2_SOURCES})
add_library(nghttp2 SHARED $<TARGET_OBJECTS:nghttp2-obj>)
#target_link_libraries(nghttp2 ...)
set_target_properties(nghttp2 PROPERTIES
COMPILE_FLAGS "${WARNCFLAGS} ${EXTRACFLAG}"

View File

@ -155,23 +155,30 @@ if(ENABLE_APP)
if(HAVE_CUNIT)
# check_PROGRAMS += nghttpx-unittest
# nghttpx_unittest_SOURCES = shrpx-unittest.cc
# shrpx_ssl_test.cc
# shrpx_downstream_test.cc
# shrpx_config_test.cc
# shrpx_http_test.cc
# http2_test.cc
# util_test.cc
# nghttp2_gzip_test.c
# nghttp2_gzip.c
# buffer_test.cc
# memchunk_test.cc
# template_test.cc
# base64_test.cc
# nghttpx_unittest_CPPFLAGS = ${AM_CPPFLAGS}
# -DNGHTTP2_TESTS_DIR=\"$(top_srcdir)/tests\"
# nghttpx_unittest_LDADD = libnghttpx.a ${LDADD} @CUNIT_LIBS@ @TESTLDADD@
#
set(NGHTTPX_UNITTEST_SOURCES
shrpx-unittest.cc
shrpx_ssl_test.cc
shrpx_downstream_test.cc
shrpx_config_test.cc
shrpx_http_test.cc
http2_test.cc
util_test.cc
nghttp2_gzip_test.c
nghttp2_gzip.c
buffer_test.cc
memchunk_test.cc
template_test.cc
base64_test.cc
)
add_executable(nghttpx-unittest EXCLUDE_FROM_ALL
${NGHTTPX_UNITTEST_SOURCES}
$<TARGET_OBJECTS:http-parser>
)
target_include_directories(nghttpx-unittest PRIVATE ${CUNIT_INCLUDE_DIRS})
target_compile_definitions(nghttpx-unittest
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@
@ -184,7 +191,7 @@ if(ENABLE_APP)
# nghttpx_unittest_LDADD += ${top_builddir}/third-party/libneverbleed.la
# endif # HAVE_NEVERBLEED
#
# TESTS += nghttpx-unittest
add_test(nghttpx-unittest nghttpx-unittest)
endif()
add_executable(nghttp ${NGHTTP_SOURCES} $<TARGET_OBJECTS:http-parser>)

53
tests/CMakeLists.txt Normal file
View File

@ -0,0 +1,53 @@
# XXX testdata/: EXTRA_DIST = cacert.pem index.html privkey.pem
if(HAVE_CUNIT)
# XXX replace this by lists (WARNCFLAGS_list)
string(REPLACE " " ";" c_flags "${WARNCFLAGS}")
add_compile_options(${c_flags})
include_directories(
"${CMAKE_SOURCE_DIR}/lib/includes"
"${CMAKE_SOURCE_DIR}/lib"
"${CMAKE_SOURCE_DIR}/src/includes"
"${CMAKE_BINARY_DIR}/lib/includes"
${CUNIT_INCLUDE_DIRS}
)
set(MAIN_SOURCES
main.c nghttp2_pq_test.c nghttp2_map_test.c nghttp2_queue_test.c
nghttp2_test_helper.c
nghttp2_frame_test.c
nghttp2_stream_test.c
nghttp2_session_test.c
nghttp2_hd_test.c
nghttp2_npn_test.c
nghttp2_helper_test.c
nghttp2_buf_test.c
)
add_executable(main EXCLUDE_FROM_ALL
${MAIN_SOURCES}
$<TARGET_OBJECTS:nghttp2-obj>
)
target_include_directories(main PRIVATE ${CUNIT_INCLUDE_DIRS})
target_link_libraries(main ${CUNIT_LIBRARIES})
add_test(main main)
if(ENABLE_FAILMALLOC)
set(FAILMALLOC_SOURCES
failmalloc.c failmalloc_test.c
malloc_wrapper.c
nghttp2_test_helper.c
)
add_executable(failmalloc EXCLUDE_FROM_ALL
${FAILMALLOC_SOURCES}
$<TARGET_OBJECTS:nghttp2-obj>
)
target_link_libraries(failmalloc ${CUNIT_LIBRARIES})
add_test(failmalloc failmalloc)
endif()
if(ENABLE_APP)
# EXTRA_DIST = end_to_end.py
# TESTS += end_to_end.py
endif()
endif()