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

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

View file

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

View file

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

View file

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