+# Unit Test Suite
+IF(CHECK_FOUND)
+ # Get all of the test cases.
+ # XXX Per CMake documentation, if a test case is added or removed we must
+ # re-run CMake due to our use of GLOB. TBD if this tradeoff to have
+ # "plug-and-play" test cases is really worth it.
+ FILE(GLOB httpdunit_cases "${CMAKE_SOURCE_DIR}/test/unit/*.c")
+
+ ADD_EXECUTABLE(httpdunit
+ test/httpdunit.c
+ ${httpdunit_cases})
+ SET_TARGET_PROPERTIES(httpdunit PROPERTIES
+ INCLUDE_DIRECTORIES "${HTTPD_INCLUDE_DIRECTORIES} ${CHECK_INCLUDE_DIR}"
+ # FIXME why does Check need HAVE_STDINT_H on Windows?
+ COMPILE_FLAGS "-DHAVE_STDINT_H")
+ TARGET_LINK_LIBRARIES(httpdunit libhttpd ${APR_LIBRARIES} ${CHECK_LIBRARIES})
+
+ # Rules for generating the .tests stubs.
+ FILE(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/httpdunit_gen_stubs.bat"
+ CONTENT "perl \"${CMAKE_SOURCE_DIR}/build/httpdunit_gen_stubs.pl\" < %1 > %2")
+ FILE(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/test/unit")
+
+ FOREACH(case ${httpdunit_cases})
+ STRING(REGEX REPLACE "^${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}"
+ stub "${case}")
+ STRING(REGEX REPLACE "\\.c$" ".tests"
+ stub "${stub}")
+
+ ADD_CUSTOM_COMMAND(TARGET httpdunit
+ PRE_BUILD
+ COMMAND "${CMAKE_BINARY_DIR}/httpdunit_gen_stubs.bat" "\"${case}\"" "\"${stub}\""
+ BYPRODUCTS "${stub}")
+ ENDFOREACH()
+
+ # Rule for generating the .cases file.
+ FILE(GENERATE OUTPUT "${CMAKE_BINARY_DIR}/httpdunit_gen_cases.bat"
+ CONTENT "type \"${CMAKE_SOURCE_DIR}\"\\test\\unit\\*.c 2>NUL | perl \"${CMAKE_SOURCE_DIR}/build/httpdunit_gen_cases.pl\" --declaration > \"${CMAKE_BINARY_DIR}/test/httpdunit.cases\"
+ type \"${CMAKE_SOURCE_DIR}\"\\test\\unit\\*.c 2>NUL | perl \"${CMAKE_SOURCE_DIR}/build/httpdunit_gen_cases.pl\" >> \"${CMAKE_BINARY_DIR}/test/httpdunit.cases\"")
+ ADD_CUSTOM_COMMAND(TARGET httpdunit
+ PRE_BUILD
+ COMMAND "${CMAKE_BINARY_DIR}/httpdunit_gen_cases.bat"
+ BYPRODUCTS "${CMAKE_BINARY_DIR}/test/httpdunit.cases")
+ENDIF()
+