The open source OpenXR runtime
at main 122 lines 3.6 kB view raw
1# Copyright 2019-2021 Collabora, Ltd. 2# 3# SPDX-License-Identifier: BSL-1.0 4# 5# Distributed under the Boost Software License, Version 1.0. 6# (See accompanying file LICENSE_1_0.txt or copy at 7# http://www.boost.org/LICENSE_1_0.txt) 8# 9# Original Author: 10# 2019-2021 Rylie Pavlik <rylie.pavlik@collabora.com> 11 12#.rst: 13# FindCheck 14# --------------- 15# 16# Find the "Check" C unit testing framework. 17# 18# See https://libcheck.github.io 19# 20# The Debian package for this is called ``check`` 21# 22# Targets 23# ^^^^^^^ 24# 25# If successful, the following imported targets are created. 26# 27# ``libcheck::check`` 28# 29# Cache variables 30# ^^^^^^^^^^^^^^^ 31# 32# The following cache variable may also be set to assist/control the operation of this module: 33# 34# ``LIBCHECK_ROOT_DIR`` 35# The root to search for libcheck. 36 37set(LIBCHECK_ROOT_DIR 38 "${LIBCHECK_ROOT_DIR}" 39 CACHE PATH "Root to search for libcheck") 40 41if(NOT ANDROID) 42 find_package(PkgConfig QUIET) 43 if(PKG_CONFIG_FOUND) 44 set(_old_prefix_path "${CMAKE_PREFIX_PATH}") 45 # So pkg-config uses LIBCHECK_ROOT_DIR too. 46 if(LIBCHECK_ROOT_DIR) 47 list(APPEND CMAKE_PREFIX_PATH ${LIBCHECK_ROOT_DIR}) 48 endif() 49 pkg_check_modules(PC_LIBCHECK QUIET check) 50 # Restore 51 set(CMAKE_PREFIX_PATH "${_old_prefix_path}") 52 endif() 53endif() 54 55find_path( 56 LIBCHECK_INCLUDE_DIR 57 NAMES check.h 58 PATHS ${LIBCHECK_ROOT_DIR} 59 HINTS ${PC_LIBCHECK_INCLUDE_DIRS} 60 PATH_SUFFIXES include) 61find_library( 62 LIBCHECK_LIBRARY 63 NAMES check_pic check 64 PATHS ${LIBCHECK_ROOT_DIR} 65 HINTS ${PC_LIBCHECK_LIBRARY_DIRS} 66 PATH_SUFFIXES lib) 67find_library( 68 LIBCHECK_SUBUNIT_LIBRARY 69 NAMES subunit 70 PATHS ${LIBCHECK_ROOT_DIR} 71 HINTS ${PC_LIBCHECK_LIBRARY_DIRS} 72 PATH_SUFFIXES lib) 73find_library(LIBCHECK_LIBRT rt) 74find_library(LIBCHECK_LIBM m) 75 76find_package(Threads QUIET) 77 78set(_libcheck_extra_required) 79if(PC_LIBCHECK_FOUND AND "${PC_LIBCHECK_LIBRARIES}" MATCHES "subunit") 80 list(APPEND _libcheck_extra_required LIBCHECK_SUBUNIT_LIBRARY) 81endif() 82 83include(FindPackageHandleStandardArgs) 84find_package_handle_standard_args( 85 Libcheck REQUIRED_VARS LIBCHECK_INCLUDE_DIR LIBCHECK_LIBRARY THREADS_FOUND) 86if(LIBCHECK_FOUND) 87 if(NOT TARGET libcheck::check) 88 add_library(libcheck::check UNKNOWN IMPORTED) 89 90 set_target_properties( 91 libcheck::check 92 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBCHECK_INCLUDE_DIR}" 93 IMPORTED_LINK_INTERFACE_LANGUAGES "C" 94 IMPORTED_LOCATION ${LIBCHECK_LIBRARY} 95 IMPORTED_LINK_INTERFACE_LIBRARIES Threads::Threads) 96 97 # if we found librt or libm, link them. 98 if(LIBCHECK_LIBRT) 99 set_property( 100 TARGET libcheck::check 101 APPEND 102 PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES "${LIBCHECK_LIBRT}") 103 endif() 104 if(LIBCHECK_LIBM) 105 set_property( 106 TARGET libcheck::check 107 APPEND 108 PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES "${LIBCHECK_LIBM}") 109 endif() 110 if(LIBCHECK_SUBUNIT_LIBRARY) 111 set_property( 112 TARGET libcheck::check 113 APPEND 114 PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES 115 "${LIBCHECK_SUBUNIT_LIBRARY}") 116 endif() 117 118 endif() 119 mark_as_advanced(LIBCHECK_INCLUDE_DIR LIBCHECK_LIBRARY 120 LIBCHECK_SUBUNIT_LIBRARY) 121endif() 122mark_as_advanced(LIBCHECK_ROOT_DIR LIBCHECK_LIBRT LIBCHECK_LIBM)