cmake: Update scripts from shared module repo.

This commit is contained in:
Ryan Pavlik 2020-08-05 14:13:00 -05:00 committed by Jakob Bornecrantz
parent 9a398b7de5
commit 72662d91c1
5 changed files with 251 additions and 266 deletions

10
cmake/.cmake-format.json Normal file
View file

@ -0,0 +1,10 @@
{
"tab_size": 4,
"dangle_parens": false,
"line_ending": "unix",
"command_case": "canonical",
"keyword_case": "upper",
"first_comment_is_literal": true,
"literal_comment_pattern": "(^[.]rst)|(#+)",
"enable_markup": false
}

View file

@ -1,7 +1,7 @@
#.rst:
# FindHIDAPI
# ----------
#
#
# Try to find HIDAPI library, from http://www.signal11.us/oss/hidapi/
#
# Cache Variables: (probably not for direct use in your scripts)
@ -23,7 +23,7 @@
#
# IMPORTED Targets
# ^^^^^^^^^^^^^^^^
#
# This module defines :prop_tgt:`IMPORTED` target ``HIDAPI::hidapi`` (in all cases or
# if no components specified), ``HIDAPI::hidapi-libusb`` (if you requested the libusb component),
# and ``HIDAPI::hidapi-hidraw`` (if you requested the hidraw component),
@ -50,74 +50,68 @@
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
set(HIDAPI_ROOT_DIR "${HIDAPI_ROOT_DIR}" CACHE PATH "Root to search for HIDAPI")
set(HIDAPI_ROOT_DIR
"${HIDAPI_ROOT_DIR}"
CACHE PATH "Root to search for HIDAPI")
# Clean up components
if(HIDAPI_FIND_COMPONENTS)
if(WIN32 OR APPLE)
# This makes no sense on Windows or Mac, which have native APIs
list(REMOVE HIDAPI_FIND_COMPONENTS libusb)
endif()
if(WIN32 OR APPLE)
# This makes no sense on Windows or Mac, which have native APIs
list(REMOVE HIDAPI_FIND_COMPONENTS libusb)
endif()
if(NOT ${CMAKE_SYSTEM} MATCHES "Linux")
# hidraw is only on linux
list(REMOVE HIDAPI_FIND_COMPONENTS hidraw)
endif()
if(NOT ${CMAKE_SYSTEM} MATCHES "Linux")
# hidraw is only on linux
list(REMOVE HIDAPI_FIND_COMPONENTS hidraw)
endif()
endif()
if(NOT HIDAPI_FIND_COMPONENTS)
# Default to any
set(HIDAPI_FIND_COMPONENTS any)
# Default to any
set(HIDAPI_FIND_COMPONENTS any)
endif()
# Ask pkg-config for hints
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
set(_old_prefix_path "${CMAKE_PREFIX_PATH}")
# So pkg-config uses HIDAPI_ROOT_DIR too.
if(HIDAPI_ROOT_DIR)
list(APPEND CMAKE_PREFIX_PATH ${HIDAPI_ROOT_DIR})
endif()
pkg_check_modules(PC_HIDAPI_LIBUSB QUIET hidapi-libusb)
pkg_check_modules(PC_HIDAPI_HIDRAW QUIET hidapi-hidraw)
set(_old_prefix_path "${CMAKE_PREFIX_PATH}")
# So pkg-config uses HIDAPI_ROOT_DIR too.
if(HIDAPI_ROOT_DIR)
list(APPEND CMAKE_PREFIX_PATH ${HIDAPI_ROOT_DIR})
endif()
pkg_check_modules(PC_HIDAPI_LIBUSB QUIET hidapi-libusb)
pkg_check_modules(PC_HIDAPI_HIDRAW QUIET hidapi-hidraw)
# Restore
set(CMAKE_PREFIX_PATH "${_old_prefix_path}")
endif()
# Actually search
find_library(HIDAPI_UNDECORATED_LIBRARY
NAMES hidapi
PATHS
"${HIDAPI_ROOT_DIR}"
PATH_SUFFIXES
lib)
find_library(
HIDAPI_UNDECORATED_LIBRARY
NAMES hidapi
PATHS "${HIDAPI_ROOT_DIR}"
PATH_SUFFIXES lib)
find_library(HIDAPI_LIBUSB_LIBRARY
NAMES hidapi hidapi-libusb
PATHS
"${HIDAPI_ROOT_DIR}"
PATH_SUFFIXES
lib
HINTS
${PC_HIDAPI_LIBUSB_LIBRARY_DIRS})
find_library(
HIDAPI_LIBUSB_LIBRARY
NAMES hidapi hidapi-libusb
PATHS "${HIDAPI_ROOT_DIR}"
PATH_SUFFIXES lib
HINTS ${PC_HIDAPI_LIBUSB_LIBRARY_DIRS})
if(CMAKE_SYSTEM MATCHES "Linux")
find_library(HIDAPI_HIDRAW_LIBRARY
NAMES hidapi-hidraw
HINTS
${PC_HIDAPI_HIDRAW_LIBRARY_DIRS})
find_library(
HIDAPI_HIDRAW_LIBRARY
NAMES hidapi-hidraw
HINTS ${PC_HIDAPI_HIDRAW_LIBRARY_DIRS})
endif()
find_path(HIDAPI_INCLUDE_DIR
NAMES hidapi.h
PATHS
"${HIDAPI_ROOT_DIR}"
PATH_SUFFIXES
hidapi
include
include/hidapi
HINTS
${PC_HIDAPI_HIDRAW_INCLUDE_DIRS}
${PC_HIDAPI_LIBUSB_INCLUDE_DIRS})
find_path(
HIDAPI_INCLUDE_DIR
NAMES hidapi.h
PATHS "${HIDAPI_ROOT_DIR}"
PATH_SUFFIXES hidapi include include/hidapi
HINTS ${PC_HIDAPI_HIDRAW_INCLUDE_DIRS} ${PC_HIDAPI_LIBUSB_INCLUDE_DIRS})
find_package(Threads QUIET)
@ -127,62 +121,68 @@ find_package(Threads QUIET)
set(HIDAPI_LIBRARY)
# First, try to use a preferred backend if supplied
if("${HIDAPI_FIND_COMPONENTS}" MATCHES "libusb" AND HIDAPI_LIBUSB_LIBRARY AND NOT HIDAPI_LIBRARY)
set(HIDAPI_LIBRARY ${HIDAPI_LIBUSB_LIBRARY})
if("${HIDAPI_FIND_COMPONENTS}" MATCHES "libusb"
AND HIDAPI_LIBUSB_LIBRARY
AND NOT HIDAPI_LIBRARY)
set(HIDAPI_LIBRARY ${HIDAPI_LIBUSB_LIBRARY})
endif()
if("${HIDAPI_FIND_COMPONENTS}" MATCHES "hidraw" AND HIDAPI_HIDRAW_LIBRARY AND NOT HIDAPI_LIBRARY)
set(HIDAPI_LIBRARY ${HIDAPI_HIDRAW_LIBRARY})
if("${HIDAPI_FIND_COMPONENTS}" MATCHES "hidraw"
AND HIDAPI_HIDRAW_LIBRARY
AND NOT HIDAPI_LIBRARY)
set(HIDAPI_LIBRARY ${HIDAPI_HIDRAW_LIBRARY})
endif()
# Then, if we don't have a preferred one, settle for anything.
if(NOT HIDAPI_LIBRARY)
if(HIDAPI_LIBUSB_LIBRARY)
set(HIDAPI_LIBRARY ${HIDAPI_LIBUSB_LIBRARY})
elseif(HIDAPI_HIDRAW_LIBRARY)
set(HIDAPI_LIBRARY ${HIDAPI_HIDRAW_LIBRARY})
elseif(HIDAPI_UNDECORATED_LIBRARY)
set(HIDAPI_LIBRARY ${HIDAPI_UNDECORATED_LIBRARY})
endif()
if(HIDAPI_LIBUSB_LIBRARY)
set(HIDAPI_LIBRARY ${HIDAPI_LIBUSB_LIBRARY})
elseif(HIDAPI_HIDRAW_LIBRARY)
set(HIDAPI_LIBRARY ${HIDAPI_HIDRAW_LIBRARY})
elseif(HIDAPI_UNDECORATED_LIBRARY)
set(HIDAPI_LIBRARY ${HIDAPI_UNDECORATED_LIBRARY})
endif()
endif()
###
# Determine if the various requested components are found.
###
set(_hidapi_component_required_vars)
foreach(_comp IN LISTS HIDAPI_FIND_COMPONENTS)
if("${_comp}" STREQUAL "any")
list(APPEND _hidapi_component_required_vars
HIDAPI_INCLUDE_DIR
HIDAPI_LIBRARY)
if(HIDAPI_INCLUDE_DIR AND EXISTS "${HIDAPI_LIBRARY}")
set(HIDAPI_any_FOUND TRUE)
mark_as_advanced(HIDAPI_INCLUDE_DIR)
else()
set(HIDAPI_any_FOUND FALSE)
endif()
if("${_comp}" STREQUAL "any")
list(APPEND _hidapi_component_required_vars HIDAPI_INCLUDE_DIR
HIDAPI_LIBRARY)
if(HIDAPI_INCLUDE_DIR AND EXISTS "${HIDAPI_LIBRARY}")
set(HIDAPI_any_FOUND TRUE)
mark_as_advanced(HIDAPI_INCLUDE_DIR)
else()
set(HIDAPI_any_FOUND FALSE)
endif()
elseif("${_comp}" STREQUAL "libusb")
list(APPEND _hidapi_component_required_vars HIDAPI_INCLUDE_DIR HIDAPI_LIBUSB_LIBRARY)
if(HIDAPI_INCLUDE_DIR AND EXISTS "${HIDAPI_LIBUSB_LIBRARY}")
set(HIDAPI_libusb_FOUND TRUE)
mark_as_advanced(HIDAPI_INCLUDE_DIR HIDAPI_LIBUSB_LIBRARY)
else()
set(HIDAPI_libusb_FOUND FALSE)
endif()
elseif("${_comp}" STREQUAL "libusb")
list(APPEND _hidapi_component_required_vars HIDAPI_INCLUDE_DIR
HIDAPI_LIBUSB_LIBRARY)
if(HIDAPI_INCLUDE_DIR AND EXISTS "${HIDAPI_LIBUSB_LIBRARY}")
set(HIDAPI_libusb_FOUND TRUE)
mark_as_advanced(HIDAPI_INCLUDE_DIR HIDAPI_LIBUSB_LIBRARY)
else()
set(HIDAPI_libusb_FOUND FALSE)
endif()
elseif("${_comp}" STREQUAL "hidraw")
list(APPEND _hidapi_component_required_vars HIDAPI_INCLUDE_DIR HIDAPI_HIDRAW_LIBRARY)
if(HIDAPI_INCLUDE_DIR AND EXISTS "${HIDAPI_HIDRAW_LIBRARY}")
set(HIDAPI_hidraw_FOUND TRUE)
mark_as_advanced(HIDAPI_INCLUDE_DIR HIDAPI_HIDRAW_LIBRARY)
else()
set(HIDAPI_hidraw_FOUND FALSE)
endif()
elseif("${_comp}" STREQUAL "hidraw")
list(APPEND _hidapi_component_required_vars HIDAPI_INCLUDE_DIR
HIDAPI_HIDRAW_LIBRARY)
if(HIDAPI_INCLUDE_DIR AND EXISTS "${HIDAPI_HIDRAW_LIBRARY}")
set(HIDAPI_hidraw_FOUND TRUE)
mark_as_advanced(HIDAPI_INCLUDE_DIR HIDAPI_HIDRAW_LIBRARY)
else()
set(HIDAPI_hidraw_FOUND FALSE)
endif()
else()
message(WARNING "${_comp} is not a recognized HIDAPI component")
set(HIDAPI_${_comp}_FOUND FALSE)
endif()
else()
message(WARNING "${_comp} is not a recognized HIDAPI component")
set(HIDAPI_${_comp}_FOUND FALSE)
endif()
endforeach()
unset(_comp)
@ -190,38 +190,40 @@ unset(_comp)
# FPHSA call
###
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(HIDAPI
REQUIRED_VARS
${_hidapi_component_required_vars}
THREADS_FOUND
HANDLE_COMPONENTS)
find_package_handle_standard_args(
HIDAPI
REQUIRED_VARS ${_hidapi_component_required_vars} THREADS_FOUND
HANDLE_COMPONENTS)
if(HIDAPI_FOUND)
set(HIDAPI_LIBRARIES "${HIDAPI_LIBRARY}")
set(HIDAPI_INCLUDE_DIRS "${HIDAPI_INCLUDE_DIR}")
if(NOT TARGET HIDAPI::hidapi)
add_library(HIDAPI::hidapi UNKNOWN IMPORTED)
set_target_properties(HIDAPI::hidapi PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${HIDAPI_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${HIDAPI_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LIBRARIES Threads::Threads)
endif()
set(HIDAPI_LIBRARIES "${HIDAPI_LIBRARY}")
set(HIDAPI_INCLUDE_DIRS "${HIDAPI_INCLUDE_DIR}")
if(NOT TARGET HIDAPI::hidapi)
add_library(HIDAPI::hidapi UNKNOWN IMPORTED)
set_target_properties(
HIDAPI::hidapi
PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${HIDAPI_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${HIDAPI_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LIBRARIES Threads::Threads)
endif()
endif()
if(HIDAPI_libusb_FOUND AND NOT TARGET HIDAPI::hidapi-libusb)
add_library(HIDAPI::hidapi-libusb UNKNOWN IMPORTED)
set_target_properties(HIDAPI::hidapi-libusb PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${HIDAPI_LIBUSB_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${HIDAPI_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LIBRARIES Threads::Threads)
add_library(HIDAPI::hidapi-libusb UNKNOWN IMPORTED)
set_target_properties(
HIDAPI::hidapi-libusb
PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${HIDAPI_LIBUSB_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${HIDAPI_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LIBRARIES Threads::Threads)
endif()
if(HIDAPI_hidraw_FOUND AND NOT TARGET HIDAPI::hidapi-hidraw)
add_library(HIDAPI::hidapi-hidraw UNKNOWN IMPORTED)
set_target_properties(HIDAPI::hidapi-hidraw PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${HIDAPI_HIDRAW_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${HIDAPI_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LIBRARIES Threads::Threads)
add_library(HIDAPI::hidapi-hidraw UNKNOWN IMPORTED)
set_target_properties(
HIDAPI::hidapi-hidraw
PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${HIDAPI_HIDRAW_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${HIDAPI_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LIBRARIES Threads::Threads)
endif()

View file

@ -32,7 +32,9 @@
# ``LIBCHECK_ROOT_DIR``
# The root to search for libcheck.
set(LIBCHECK_ROOT_DIR "${LIBCHECK_ROOT_DIR}" CACHE PATH "Root to search for libcheck")
set(LIBCHECK_ROOT_DIR
"${LIBCHECK_ROOT_DIR}"
CACHE PATH "Root to search for libcheck")
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
@ -45,37 +47,24 @@ if(PKG_CONFIG_FOUND)
# Restore
set(CMAKE_PREFIX_PATH "${_old_prefix_path}")
endif()
find_path(LIBCHECK_INCLUDE_DIR
NAMES
check.h
PATHS
${LIBCHECK_ROOT_DIR}
HINTS
${PC_LIBCHECK_INCLUDE_DIRS}
PATH_SUFFIXES
include
)
find_library(LIBCHECK_LIBRARY
NAMES
check_pic
check
PATHS
${LIBCHECK_ROOT_DIR}
HINTS
${PC_LIBCHECK_LIBRARY_DIRS}
PATH_SUFFIXES
lib
)
find_library(LIBCHECK_SUBUNIT_LIBRARY
NAMES
subunit
PATHS
${LIBCHECK_ROOT_DIR}
HINTS
${PC_LIBCHECK_LIBRARY_DIRS}
PATH_SUFFIXES
lib
)
find_path(
LIBCHECK_INCLUDE_DIR
NAMES check.h
PATHS ${LIBCHECK_ROOT_DIR}
HINTS ${PC_LIBCHECK_INCLUDE_DIRS}
PATH_SUFFIXES include)
find_library(
LIBCHECK_LIBRARY
NAMES check_pic check
PATHS ${LIBCHECK_ROOT_DIR}
HINTS ${PC_LIBCHECK_LIBRARY_DIRS}
PATH_SUFFIXES lib)
find_library(
LIBCHECK_SUBUNIT_LIBRARY
NAMES subunit
PATHS ${LIBCHECK_ROOT_DIR}
HINTS ${PC_LIBCHECK_LIBRARY_DIRS}
PATH_SUFFIXES lib)
find_library(LIBCHECK_LIBRT rt)
find_library(LIBCHECK_LIBM m)
@ -87,39 +76,42 @@ if(PC_LIBCHECK_FOUND AND "${PC_LIBCHECK_LIBRARIES}" MATCHES "subunit")
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Libcheck
REQUIRED_VARS
LIBCHECK_INCLUDE_DIR
LIBCHECK_LIBRARY
THREADS_FOUND
)
find_package_handle_standard_args(
Libcheck REQUIRED_VARS LIBCHECK_INCLUDE_DIR LIBCHECK_LIBRARY THREADS_FOUND)
if(LIBCHECK_FOUND)
if(NOT TARGET libcheck::check)
add_library(libcheck::check UNKNOWN IMPORTED)
set_target_properties(libcheck::check PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${LIBCHECK_INCLUDE_DIR}")
set_target_properties(libcheck::check PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION ${LIBCHECK_LIBRARY})
set_property(TARGET libcheck::check PROPERTY
IMPORTED_LINK_INTERFACE_LIBRARIES Threads::Threads)
set_target_properties(
libcheck::check
PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBCHECK_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION ${LIBCHECK_LIBRARY}
IMPORTED_LINK_INTERFACE_LIBRARIES Threads::Threads)
# if we found librt or libm, link them.
if(LIBCHECK_LIBRT)
set_property(TARGET libcheck::check APPEND PROPERTY
IMPORTED_LINK_INTERFACE_LIBRARIES "${LIBCHECK_LIBRT}")
set_property(
TARGET libcheck::check
APPEND
PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES "${LIBCHECK_LIBRT}")
endif()
if(LIBCHECK_LIBM)
set_property(TARGET libcheck::check APPEND PROPERTY
IMPORTED_LINK_INTERFACE_LIBRARIES "${LIBCHECK_LIBM}")
set_property(
TARGET libcheck::check
APPEND
PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES "${LIBCHECK_LIBM}")
endif()
if(LIBCHECK_SUBUNIT_LIBRARY)
set_property(TARGET libcheck::check APPEND PROPERTY
IMPORTED_LINK_INTERFACE_LIBRARIES "${LIBCHECK_SUBUNIT_LIBRARY}")
set_property(
TARGET libcheck::check
APPEND
PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES
"${LIBCHECK_SUBUNIT_LIBRARY}")
endif()
endif()
mark_as_advanced(LIBCHECK_INCLUDE_DIR LIBCHECK_LIBRARY LIBCHECK_SUBUNIT_LIBRARY)
mark_as_advanced(LIBCHECK_INCLUDE_DIR LIBCHECK_LIBRARY
LIBCHECK_SUBUNIT_LIBRARY)
endif()
mark_as_advanced(LIBCHECK_ROOT_DIR LIBCHECK_LIBRT LIBCHECK_LIBM)

View file

@ -30,7 +30,9 @@
# ``OPENHMD_ROOT_DIR``
# The root to search for OpenHMD.
set(OPENHMD_ROOT_DIR "${OPENHMD_ROOT_DIR}" CACHE PATH "Root to search for OpenHMD")
set(OPENHMD_ROOT_DIR
"${OPENHMD_ROOT_DIR}"
CACHE PATH "Root to search for OpenHMD")
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
@ -44,97 +46,83 @@ if(PKG_CONFIG_FOUND)
set(CMAKE_PREFIX_PATH "${_old_prefix_path}")
endif()
find_path(OPENHMD_INCLUDE_DIR
NAMES
openhmd.h
PATHS
${OPENHMD_ROOT_DIR}
HINTS
${PC_OPENHMD_INCLUDE_DIRS}
PATH_SUFFIXES
include
openhmd
include/openhmd
)
find_library(OPENHMD_LIBRARY
NAMES
openhmd
PATHS
${OPENHMD_ROOT_DIR}
${OPENHMD_ROOT_DIR}/build
HINTS
${PC_OPENHMD_LIBRARY_DIRS}
PATH_SUFFIXES
lib
)
if(NOT WIN32)
find_library(OPENHMD_LIBRT rt)
find_library(OPENHMD_LIBM m)
endif()
find_path(
OPENHMD_INCLUDE_DIR
NAMES openhmd.h
PATHS ${OPENHMD_ROOT_DIR}
HINTS ${PC_OPENHMD_INCLUDE_DIRS}
PATH_SUFFIXES include openhmd include/openhmd)
find_library(
OPENHMD_LIBRARY
NAMES openhmd
PATHS ${OPENHMD_ROOT_DIR} ${OPENHMD_ROOT_DIR}/build
HINTS ${PC_OPENHMD_LIBRARY_DIRS}
PATH_SUFFIXES lib)
find_library(OPENHMD_LIBRT rt)
find_library(OPENHMD_LIBM m)
find_package(Threads QUIET)
set(_ohmd_extra_deps)
set(OPENHMD_HIDAPI_TYPE)
if(OPENHMD_LIBRARY AND "${OPENHMD_LIBRARY}" MATCHES "${CMAKE_STATIC_LIBRARY_SUFFIX}")
# Looks like a static library
if(PC_OPENHMD_FOUND)
# See if we need a particular hidapi.
list(REMOVE_ITEM PC_OPENHMD_LIBRARIES openhmd)
if("${PC_OPENHMD_LIBRARIES}" MATCHES hidapi-libusb)
set(OPENHMD_HIDAPI_TYPE libusb)
find_package(HIDAPI QUIET COMPONENTS libusb)
list(APPEND _ohmd_extra_deps HIDAPI_libusb_FOUND)
elseif("${PC_OPENHMD_LIBRARIES}" MATCHES hidapi-hidraw)
set(OPENHMD_HIDAPI_TYPE hidraw)
find_package(HIDAPI QUIET COMPONENTS hidraw)
list(APPEND _ohmd_extra_deps HIDAPI_hidraw_FOUND)
endif()
endif()
if(NOT PC_OPENHMD_FOUND OR NOT OPENHMD_HIDAPI_TYPE)
# Undifferentiated
set(OPENHMD_HIDAPI_TYPE undifferentiated)
find_package(HIDAPI QUIET)
list(APPEND _ohmd_extra_deps HIDAPI_FOUND)
if(OPENHMD_LIBRARY AND "${OPENHMD_LIBRARY}" MATCHES
"${CMAKE_STATIC_LIBRARY_SUFFIX}")
# Looks like a static library
if(PC_OPENHMD_FOUND)
# See if we need a particular hidapi.
list(REMOVE_ITEM PC_OPENHMD_LIBRARIES openhmd)
if("${PC_OPENHMD_LIBRARIES}" MATCHES hidapi-libusb)
set(OPENHMD_HIDAPI_TYPE libusb)
find_package(HIDAPI QUIET COMPONENTS libusb)
list(APPEND _ohmd_extra_deps HIDAPI_libusb_FOUND)
elseif("${PC_OPENHMD_LIBRARIES}" MATCHES hidapi-hidraw)
set(OPENHMD_HIDAPI_TYPE hidraw)
find_package(HIDAPI QUIET COMPONENTS hidraw)
list(APPEND _ohmd_extra_deps HIDAPI_hidraw_FOUND)
endif()
endif()
if(NOT PC_OPENHMD_FOUND OR NOT OPENHMD_HIDAPI_TYPE)
# Undifferentiated
set(OPENHMD_HIDAPI_TYPE undifferentiated)
find_package(HIDAPI QUIET)
list(APPEND _ohmd_extra_deps HIDAPI_FOUND)
endif()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(OpenHMD
REQUIRED_VARS
OPENHMD_INCLUDE_DIR
OPENHMD_LIBRARY
THREADS_FOUND
)
find_package_handle_standard_args(
OpenHMD REQUIRED_VARS OPENHMD_INCLUDE_DIR OPENHMD_LIBRARY THREADS_FOUND)
if(OPENHMD_FOUND)
set(OPENHMD_INCLUDE_DIRS "${OPENHMD_INCLUDE_DIR}")
set(OPENHMD_LIBRARIES "${OPENHMD_LIBRARY}")
if(NOT TARGET OpenHMD::OpenHMD)
add_library(OpenHMD::OpenHMD UNKNOWN IMPORTED)
endif()
set_target_properties(OpenHMD::OpenHMD PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${OPENHMD_INCLUDE_DIR}")
set_target_properties(OpenHMD::OpenHMD PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${OPENHMD_LIBRARY}")
set_property(TARGET OpenHMD::OpenHMD PROPERTY
IMPORTED_LINK_INTERFACE_LIBRARIES Threads::Threads)
set_target_properties(
OpenHMD::OpenHMD
PROPERTIES IMPORTED_LOCATION "${OPENHMD_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${OPENHMD_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LINK_INTERFACE_LIBRARIES Threads::Threads)
if("${OPENHMD_HIDAPI_TYPE}" STREQUAL libusb)
set_property(TARGET OpenHMD::OpenHMD APPEND PROPERTY
IMPORTED_LINK_INTERFACE_LIBRARIES HIDAPI::hidapi-libusb)
set_property(
TARGET OpenHMD::OpenHMD
APPEND
PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES HIDAPI::hidapi-libusb)
list(APPEND OPENHMD_LIBRARIES HIDAPI::hidapi-libusb)
elseif("${OPENHMD_HIDAPI_TYPE}" STREQUAL hidraw)
set_property(TARGET OpenHMD::OpenHMD APPEND PROPERTY
IMPORTED_LINK_INTERFACE_LIBRARIES HIDAPI::hidapi-hidraw)
set_property(
TARGET OpenHMD::OpenHMD
APPEND
PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES HIDAPI::hidapi-hidraw)
list(APPEND OPENHMD_LIBRARIES HIDAPI::hidapi-hidraw)
elseif("${OPENHMD_HIDAPI_TYPE}" STREQUAL undifferentiated)
set_property(TARGET OpenHMD::OpenHMD APPEND PROPERTY
IMPORTED_LINK_INTERFACE_LIBRARIES HIDAPI::hidapi)
set_property(
TARGET OpenHMD::OpenHMD
APPEND
PROPERTY IMPORTED_LINK_INTERFACE_LIBRARIES HIDAPI::hidapi)
list(APPEND OPENHMD_LIBRARIES HIDAPI::hidapi)
endif()
mark_as_advanced(OPENHMD_INCLUDE_DIR OPENHMD_LIBRARY)

View file

@ -28,42 +28,35 @@
# ``CJSON_ROOT_DIR``
# The root to search for cJSON.
set(CJSON_ROOT_DIR "${CJSON_ROOT_DIR}" CACHE PATH "Root to search for cJSON")
set(CJSON_ROOT_DIR
"${CJSON_ROOT_DIR}"
CACHE PATH "Root to search for cJSON")
find_path(CJSON_INCLUDE_DIR
NAMES
cjson/cJSON.h
PATHS
${CJSON_ROOT_DIR}
PATH_SUFFIXES
include
)
find_library(CJSON_LIBRARY
NAMES
cjson
PATHS
${CJSON_ROOT_DIR}
PATH_SUFFIXES
lib
)
find_path(
CJSON_INCLUDE_DIR
NAMES cjson/cJSON.h
PATHS ${CJSON_ROOT_DIR}
PATH_SUFFIXES include)
find_library(
CJSON_LIBRARY
NAMES cjson
PATHS ${CJSON_ROOT_DIR}
PATH_SUFFIXES lib)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(cJSON
REQUIRED_VARS
CJSON_INCLUDE_DIR
CJSON_LIBRARY
)
find_package_handle_standard_args(cJSON REQUIRED_VARS CJSON_INCLUDE_DIR
CJSON_LIBRARY)
if(CJSON_FOUND)
set(CJSON_INCLUDE_DIRS "${CJSON_INCLUDE_DIR}")
set(CJSON_LIBRARIES "${CJSON_LIBRARY}")
if(NOT TARGET cJSON::cJSON)
add_library(cJSON::cJSON UNKNOWN IMPORTED)
endif()
set_target_properties(cJSON::cJSON PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${CJSON_INCLUDE_DIR}")
set_target_properties(cJSON::cJSON PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${CJSON_LIBRARY}")
set_target_properties(cJSON::cJSON PROPERTIES INTERFACE_INCLUDE_DIRECTORIES
"${CJSON_INCLUDE_DIR}")
set_target_properties(
cJSON::cJSON PROPERTIES IMPORTED_LINK_INTERFACE_LANGUAGES "C"
IMPORTED_LOCATION "${CJSON_LIBRARY}")
mark_as_advanced(CJSON_INCLUDE_DIR CJSON_LIBRARY)
endif()
mark_as_advanced(CJSON_ROOT_DIR)