Commit 9352d7ca authored by Ghislain MARY's avatar Ghislain MARY

Require CUnit when tests component is built.

parent fcb6f739
......@@ -94,22 +94,15 @@ if(POLARSSL_FOUND)
endif()
if(ENABLE_TESTS_COMPONENT)
find_package(CUnit 3.0.1) # we need cunit 3.0-1 for automated junit output
if(CUNIT_FOUND)
cmake_push_check_state(RESET)
list(APPEND CMAKE_REQUIRED_INCLUDES ${CUNIT_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${CUNIT_LIBRARIES})
check_symbol_exists("CU_get_suite" "CUnit/CUnit.h" HAVE_CU_GET_SUITE)
check_symbol_exists("CU_curses_run_tests" "CUnit/CUnit.h" HAVE_CU_CURSES)
check_symbol_exists("CU_set_trace_handler" "CUnit/Util.h" HAVE_CU_SET_TRACE_HANDLER)
cmake_pop_check_state()
set(TESTER_REQUIRES_PRIVATE "cunit")
else()
# if we found did not found Cunit or improper version, just lamentably fail
# there are too much issue with using an old version...
message(FATAL_WARNING "Could not find the Cunit library with proper version. Consider turning tests component OFF with -DENABLE_TESTS_COMPONENT=OFF")
endif()
find_package(CUnit 3.0 REQUIRED)
cmake_push_check_state(RESET)
list(APPEND CMAKE_REQUIRED_INCLUDES ${CUNIT_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${CUNIT_LIBRARIES})
check_symbol_exists("CU_get_suite" "CUnit/CUnit.h" HAVE_CU_GET_SUITE)
check_symbol_exists("CU_curses_run_tests" "CUnit/CUnit.h" HAVE_CU_CURSES)
check_symbol_exists("CU_set_trace_handler" "CUnit/Util.h" HAVE_CU_SET_TRACE_HANDLER)
cmake_pop_check_state()
set(TESTER_REQUIRES_PRIVATE "cunit")
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/bctoolbox.pc.in ${CMAKE_CURRENT_BINARY_DIR}/bctoolbox.pc)
......
......@@ -29,8 +29,6 @@
include(CheckIncludeFile)
include(CheckLibraryExists)
set(CUNIT_REQUIRED_VARS CUNIT_INCLUDE_DIRS HAVE_CUNIT_CUNIT_H CUNIT_LIBRARIES)
find_path(CUNIT_INCLUDE_DIRS
NAMES CUnit/CUnit.h
PATH_SUFFIXES include
......@@ -41,15 +39,11 @@ if(CUNIT_INCLUDE_DIRS)
endif()
if(HAVE_CUNIT_CUNIT_H)
file(STRINGS "${CUNIT_INCLUDE_DIRS}/CUnit/CUnit.h" CUNIT_VERSION_STR
REGEX "^#define[\t ]+CU_VERSION[\t ]+\"([0-9.]+).*\"$")
string(REGEX REPLACE "^.*CU_VERSION[\t ]+\"([0-9.]+).*\"$" "\\1" CUNIT_VERSION "${CUNIT_VERSION_STR}")
if(CUNIT_VERSION VERSION_LESS "3.0")
# Version too low to activate automated junit output
set(HAVE_CU_FIXED_JUNIT FALSE)
else()
set(HAVE_CU_FIXED_JUNIT TRUE)
list(APPEND CUNIT_REQUIRED_VARS HAVE_CU_FIXED_JUNIT)
if(CUnit_FIND_VERSION)
list(APPEND CUNIT_REQUIRED_VARS CUNIT_VERSION)
file(STRINGS "${CUNIT_INCLUDE_DIRS}/CUnit/CUnit.h" CUNIT_VERSION_STR
REGEX "^#define[\t ]+CU_VERSION[\t ]+\"([0-9.]+).*\"$")
string(REGEX REPLACE "^.*CU_VERSION[\t ]+\"([0-9.]+).*\"$" "\\1" CUNIT_VERSION "${CUNIT_VERSION_STR}")
endif()
endif()
......@@ -59,16 +53,16 @@ find_library(CUNIT_LIBRARIES
)
include(FindPackageHandleStandardArgs)
include(FindPackageMessage)
if(CUnit_FIND_VERSION)
set(CHECK_VERSION_ARGS VERSION_VAR CUNIT_VERSION)
endif()
find_package_handle_standard_args(CUnit
REQUIRED_VARS ${CUNIT_REQUIRED_VARS}
REQUIRED_VARS CUNIT_INCLUDE_DIRS CUNIT_LIBRARIES
${CHECK_VERSION_ARGS}
)
if(HAVE_CUNIT_CUNIT_H)
find_package_message(CUnit "Found fixed junit: ${HAVE_CU_FIXED_JUNIT}" "")
endif()
mark_as_advanced(${CUNIT_REQUIRED_VARS})
mark_as_advanced(CUNIT_INCLUDE_DIRS CUNIT_LIBRARIES)
unset(CUNIT_REQUIRED_VARS)
unset(CHECK_VERSION_ARGS)
......@@ -25,6 +25,5 @@
#cmakedefine HAVE_CU_GET_SUITE 1
#cmakedefine HAVE_CU_CURSES 1
#cmakedefine HAVE_CU_SET_TRACE_HANDLER 1
#cmakedefine HAVE_CU_FIXED_JUNIT 1
#cmakedefine HAVE_LIBRT 1
......@@ -601,9 +601,7 @@ int bc_tester_start(const char* prog_name) {
if( xml_enabled ){
char * xml_tmp_file = bc_sprintf("%s.tmp", xml_file);
CU_set_output_filename(xml_tmp_file);
#ifdef HAVE_CU_FIXED_JUNIT
CU_automated_enable_junit_xml(TRUE); /* this requires 3.0.1 because previous versions crash automated.c */
#endif
free(xml_tmp_file);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment