From 085985dce7f7017384594c4cdbe71d9cbadb3830 Mon Sep 17 00:00:00 2001 From: Jeroen Koekkoek Date: Sun, 5 Aug 2018 21:58:08 +0200 Subject: [PATCH] add support for CUnit versions less than 2.1-3 Signed-off-by: Jeroen Koekkoek --- src/cmake/modules/CUnit.cmake | 5 +++++ src/cmake/modules/CUnit/src/runner.c | 2 ++ src/cmake/modules/FindCUnit.cmake | 17 ++++++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/cmake/modules/CUnit.cmake b/src/cmake/modules/CUnit.cmake index 699cb20..a0021b9 100644 --- a/src/cmake/modules/CUnit.cmake +++ b/src/cmake/modules/CUnit.cmake @@ -124,5 +124,10 @@ function(add_cunit_executable target) add_executable(${target} "${runner}.c" "${root}/src/runner.c" ${sources}) target_link_libraries(${target} CUnit) target_include_directories(${target} PRIVATE "${root}/include") + if("2.1.3" VERSION_LESS_EQUAL + "${CUNIT_VERSION_MAJOR}.${CUNIT_VERSION_MINOR}.${CUNIT_VERSION_PATCH}") + set_source_files_properties( + "${root}/src/runner.c" PROPERTIES COMPILE_DEFINITIONS HAVE_ENABLE_JUNIT_XML) + endif() endfunction() diff --git a/src/cmake/modules/CUnit/src/runner.c b/src/cmake/modules/CUnit/src/runner.c index b6799e8..c63a148 100644 --- a/src/cmake/modules/CUnit/src/runner.c +++ b/src/cmake/modules/CUnit/src/runner.c @@ -195,7 +195,9 @@ cu_runner_run( } if (runner.junit) { +#if defined(HAVE_ENABLE_JUNIT_XML) CU_automated_enable_junit_xml(CU_TRUE); +#endif } else { CU_list_tests_to_file(); } diff --git a/src/cmake/modules/FindCUnit.cmake b/src/cmake/modules/FindCUnit.cmake index 7a883ea..17a8f05 100644 --- a/src/cmake/modules/FindCUnit.cmake +++ b/src/cmake/modules/FindCUnit.cmake @@ -12,8 +12,23 @@ find_path(CUNIT_INC CUnit/CUnit.h) find_library(CUNIT_LIB cunit) +if(CUNIT_INC AND EXISTS "${CUNIT_INC}/CUnit/CUnit.h") + set(PATTERN "^#define CU_VERSION \"([0-9]+)\.([0-9]+)\-([0-9]+)\"$") + file(STRINGS "${CUNIT_INC}/CUnit/CUnit.h" CUNIT_H REGEX "${PATTERN}") + + string(REGEX REPLACE "${PATTERN}" "\\1" CUNIT_VERSION_MAJOR "${CUNIT_H}") + string(REGEX REPLACE "${PATTERN}" "\\2" CUNIT_VERSION_MINOR "${CUNIT_H}") + string(REGEX REPLACE "${PATTERN}" "\\3" CUNIT_VERSION_PATCH "${CUNIT_H}") + + set(CUNIT_VERSION "${CUNIT_VERSION_MAJOR}.${CUNIT_VERSION_MINOR}-${CUNIT_VERSION_PATCH}") +endif() + include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(CUnit DEFAULT_MSG CUNIT_LIB CUNIT_INC) +find_package_handle_standard_args( + CUnit + REQUIRED_VARS + CUNIT_LIB CUNIT_INC + VERSION_VAR CUNIT_VERSION) if(CUNIT_FOUND AND NOT TARGET CUnit) add_library(CUnit INTERFACE IMPORTED)