|
| 1 | +cmake_minimum_required(VERSION 3.1.3 FATAL_ERROR) |
| 2 | + |
| 3 | +if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
| 4 | + add_subdirectory(src) |
| 5 | + # compatinility with find_package() vs add_subdirectory |
| 6 | + set(hidapi_VERSION "${hidapi_VERSION}" PARENT_SCOPE) |
| 7 | + return() |
| 8 | +endif() |
| 9 | +# All of the below in this file is meant for a standalone build. |
| 10 | +# When building as a subdirectory of a larger project, most of the options may not make sense for it, |
| 11 | +# so it is up to developer to configure those, e.g.: |
| 12 | +# |
| 13 | +# # a subfolder of a master project, e.g.: 3rdparty/hidapi/CMakeLists.txt |
| 14 | +# |
| 15 | +# set(HIDAPI_WITH_HIDRAW OFF) |
| 16 | +# set(CMAKE_FRAMEWORK ON) |
| 17 | +# # and keep everything else to their defaults |
| 18 | +# add_subdirectory(hidapi) |
| 19 | +# |
| 20 | + |
| 21 | +set(DEFAULT_CMAKE_BUILD_TYPES "Debug" "Release" "MinSizeRel" "RelWithDebInfo") |
| 22 | +if(NOT DEFINED CMAKE_BUILD_TYPE OR NOT CMAKE_BUILD_TYPE) |
| 23 | + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "${DEFAULT_CMAKE_BUILD_TYPES}" FORCE) |
| 24 | +endif() |
| 25 | +# This part is for convenience, when used one of the standard build types with cmake-gui |
| 26 | +list(FIND DEFAULT_CMAKE_BUILD_TYPES "${CMAKE_BUILD_TYPE}" _build_type_index) |
| 27 | +if(${_build_type_index} GREATER -1) |
| 28 | + # set it optionally, so a custom CMAKE_BUILD_TYPE can be used as well, if needed |
| 29 | + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS ${DEFAULT_CMAKE_BUILD_TYPES}) |
| 30 | +endif() |
| 31 | +unset(_build_type_index) |
| 32 | +# |
| 33 | + |
| 34 | +project(hidapi LANGUAGES C) |
| 35 | + |
| 36 | +if(APPLE) |
| 37 | + if(NOT CMAKE_VERSION VERSION_LESS "3.15") |
| 38 | + option(CMAKE_FRAMEWORK "Build macOS/iOS Framework version of the library" OFF) |
| 39 | + endif() |
| 40 | +elseif(NOT WIN32) |
| 41 | + if(CMAKE_SYSTEM_NAME MATCHES "Linux") |
| 42 | + option(HIDAPI_WITH_HIDRAW "Build HIDRAW-based implementation of HIDAPI" ON) |
| 43 | + option(HIDAPI_WITH_LIBUSB "Build LIBUSB-based implementation of HIDAPI" ON) |
| 44 | + endif() |
| 45 | +endif() |
| 46 | + |
| 47 | +option(BUILD_SHARED_LIBS "Build shared version of the libraries, otherwise build statically" ON) |
| 48 | + |
| 49 | +set(HIDAPI_INSTALL_TARGETS ON) |
| 50 | +set(HIDAPI_PRINT_VERSION ON) |
| 51 | + |
| 52 | +add_subdirectory(src) |
| 53 | + |
| 54 | +set(BUILD_HIDTEST_DEFAULT OFF) |
| 55 | +if(CMAKE_BUILD_TYPE STREQUAL "Debug") |
| 56 | + set(BUILD_HIDTEST_DEFAULT ON) |
| 57 | +endif() |
| 58 | +option(HIDAPI_BUILD_HIDTEST "Build small console test application hidtest" ${BUILD_HIDTEST_DEFAULT}) |
| 59 | +if(HIDAPI_BUILD_HIDTEST) |
| 60 | + add_subdirectory(hidtest) |
| 61 | +endif() |
0 commit comments