Commit 31217fb4 authored by Ghislain MARY's avatar Ghislain MARY

Simplify CMake packages search.

parent ee545d1a
......@@ -94,9 +94,8 @@ if(POLARSSL_FOUND)
endif()
if(ENABLE_TESTS_COMPONENT)
find_package(CUnit 3.0.1) # we need cunit 3.0.1 for automated junit output
find_package(CUnit)
if(CUNIT_FOUND)
set(HAVE_CU_FIXED_JUNIT 1)
cmake_push_check_state(RESET)
list(APPEND CMAKE_REQUIRED_INCLUDES ${CUNIT_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${CUNIT_LIBRARIES})
......@@ -104,18 +103,10 @@ if(ENABLE_TESTS_COMPONENT)
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 Cunit but with improper version, do not enable HAVE_CU_FIXED_JUNIT and search again for CUnit
if (CUNIT_LIBRARIES)
find_package(CUnit)
endif()
if (NOT CUNIT_FOUND)
message(WARNING "Could not find the Cunit library, disable tests.")
set(ENABLE_TESTS_COMPONENT OFF CACHE BOOL "Enable compilation of tests helper library" FORCE)
endif()
message(WARNING "Could not find the Cunit library, disable tests.")
set(ENABLE_TESTS_COMPONENT OFF CACHE BOOL "Enable compilation of tests helper library" FORCE)
endif()
endif()
......
......@@ -29,40 +29,46 @@
include(CheckIncludeFile)
include(CheckLibraryExists)
set(_CUNIT_ROOT_PATHS
${CMAKE_INSTALL_PREFIX}
)
set(CUNIT_REQUIRED_VARS CUNIT_INCLUDE_DIRS HAVE_CUNIT_CUNIT_H CUNIT_LIBRARIES)
find_path(CUNIT_INCLUDE_DIRS
NAMES CUnit/CUnit.h
HINTS _CUNIT_ROOT_PATHS
PATH_SUFFIXES include
)
if(CUNIT_INCLUDE_DIRS)
set(HAVE_CUNIT_CUNIT_H 1)
endif()
if(HAVE_CUNIT_CUNIT_H)
file(STRINGS "${CUNIT_INCLUDE_DIRS}/CUnit/CUnit.h" CUNIT_VERSION_STR
REGEX "^#define[\t ]+CU_VERSION[\t ]+\"(.+)\"$")
string(REGEX REPLACE "^.*CU_VERSION[\t ]+\"(.+)\"$" "\\1" CUNIT_VERSION "${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.1")
# 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)
endif()
endif()
find_library(CUNIT_LIBRARIES
NAMES cunit
HINTS ${_CUNIT_ROOT_PATHS}
PATH_SUFFIXES bin lib
)
include(FindPackageHandleStandardArgs)
include(FindPackageMessage)
if (CUNIT_VERSION)
find_package_handle_standard_args(CUnit
REQUIRED_VARS CUNIT_INCLUDE_DIRS CUNIT_LIBRARIES
VERSION_VAR CUNIT_VERSION
)
else()
find_package_handle_standard_args(CUnit
REQUIRED_VARS CUNIT_INCLUDE_DIRS CUNIT_LIBRARIES
)
find_package_handle_standard_args(CUnit
REQUIRED_VARS ${CUNIT_REQUIRED_VARS}
)
if(HAVE_CUNIT_CUNIT_H)
find_package_message(CUnit "Found fixed junit: ${HAVE_CU_FIXED_JUNIT}" "")
endif()
mark_as_advanced(CUNIT_INCLUDE_DIRS CUNIT_LIBRARIES)
mark_as_advanced(${CUNIT_REQUIRED_VARS})
unset(CUNIT_REQUIRED_VARS)
......@@ -51,7 +51,7 @@ find_library(MBEDCRYPTO_LIBRARY
)
# check we have a mbedTLS version 2 or above(all functions are prefixed mbedtls_)
if (MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY)
if(MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY)
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_INCLUDES ${MBEDTLS_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${MBEDTLS_LIBRARY} ${MBEDX509_LIBRARY} ${MBEDCRYPTO_LIBRARY})
......@@ -59,7 +59,7 @@ if (MBEDTLS_LIBRARY AND MBEDX509_LIBRARY AND MBEDCRYPTO_LIBRARY)
cmake_pop_check_state()
endif()
if (MBEDTLS_V2)
if(MBEDTLS_V2)
set (MBEDTLS_LIBRARIES
${MBEDTLS_LIBRARY}
${MBEDX509_LIBRARY}
......@@ -67,7 +67,7 @@ if (MBEDTLS_V2)
)
endif()
if (MBEDTLS_LIBRARIES)
if(MBEDTLS_LIBRARIES)
cmake_push_check_state(RESET)
set(CMAKE_REQUIRED_INCLUDES ${MBEDTLS_INCLUDE_DIRS})
set(CMAKE_REQUIRED_LIBRARIES ${MBEDTLS_LIBRARIES})
......
......@@ -31,13 +31,8 @@ include(CheckIncludeFile)
include(CheckCSourceCompiles)
include(CheckSymbolExists)
set(_POLARSSL_ROOT_PATHS
${CMAKE_INSTALL_PREFIX}
)
find_path(POLARSSL_INCLUDE_DIRS
NAMES polarssl/ssl.h
HINTS _POLARSSL_ROOT_PATHS
PATH_SUFFIXES include
)
if(POLARSSL_INCLUDE_DIRS)
......@@ -46,7 +41,6 @@ endif()
find_library(POLARSSL_LIBRARIES
NAMES polarssl mbedtls
HINTS _POLARSSL_ROOT_PATHS
PATH_SUFFIXES bin lib
)
......
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