First check the CMake Package Registry for CUnit

This is useful when building CycloneDDS on platforms that provide CMake
configuration for CUnit outside of Conan.

If no configuration is found in the system CMake registry the module
continues as before.

Co-authored-by: Steven! Ragnarök <steven@nuclearsandwich.com>
Signed-off-by: Scott K Logan <logans@cottsay.net>
This commit is contained in:
Scott K Logan 2019-10-22 10:53:18 -07:00 committed by eboasson
parent 41d36d59b2
commit 1cc6caff14

View file

@ -9,17 +9,22 @@
#
# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
#
set(CUNIT_HEADER "CUnit/CUnit.h")
if(CONAN_INCLUDE_DIRS)
find_path(CUNIT_INCLUDE_DIR ${CUNIT_HEADER} HINTS ${CONAN_INCLUDE_DIRS})
find_package(CUnit CONFIG QUIET)
if(CUnit_FOUND)
message(STATUS "Found CUnit via Config file: ${CUnit_DIR}")
set(CUNIT_FOUND ${CUnit_FOUND})
else()
set(CUNIT_HEADER "CUnit/CUnit.h")
if(CONAN_INCLUDE_DIRS)
find_path(CUNIT_INCLUDE_DIR ${CUNIT_HEADER} HINTS ${CONAN_INCLUDE_DIRS})
else()
find_path(CUNIT_INCLUDE_DIR ${CUNIT_HEADER})
endif()
endif()
mark_as_advanced(CUNIT_INCLUDE_DIR)
mark_as_advanced(CUNIT_INCLUDE_DIR)
if(CUNIT_INCLUDE_DIR AND EXISTS "${CUNIT_INCLUDE_DIR}/${CUNIT_HEADER}")
if(CUNIT_INCLUDE_DIR AND EXISTS "${CUNIT_INCLUDE_DIR}/${CUNIT_HEADER}")
set(PATTERN "^#define CU_VERSION \"([0-9]+)\\.([0-9]+)\\-([0-9]+)\"$")
file(STRINGS "${CUNIT_INCLUDE_DIR}/${CUNIT_HEADER}" CUNIT_H REGEX "${PATTERN}")
@ -28,12 +33,13 @@ if(CUNIT_INCLUDE_DIR AND EXISTS "${CUNIT_INCLUDE_DIR}/${CUNIT_HEADER}")
string(REGEX REPLACE "${PATTERN}" "\\3" CUNIT_VERSION_PATCH "${CUNIT_H}")
set(CUNIT_VERSION "${CUNIT_VERSION_MAJOR}.${CUNIT_VERSION_MINOR}-${CUNIT_VERSION_PATCH}")
endif()
endif()
if(CONAN_LIB_DIRS)
if(CONAN_LIB_DIRS)
find_library(CUNIT_LIBRARY cunit HINTS ${CONAN_LIB_DIRS})
else()
else()
find_library(CUNIT_LIBRARY cunit)
endif()
endif()
include(FindPackageHandleStandardArgs)