|
| 1 | +include_guard(GLOBAL) |
| 2 | + |
| 3 | +if (NOT CPM_PACKAGE_eebus-grpc_SOURCE_DIR) |
| 4 | + message(FATAL_ERROR "CPM_PACKAGE_eebus-grpc_SOURCE_DIR not set") |
| 5 | +endif() |
| 6 | + |
| 7 | +set(EEBUS_GRPC_API_SOURCE_DIR ${CPM_PACKAGE_eebus-grpc_SOURCE_DIR}) |
| 8 | +set(EEBUS_GRPC_API_BINARY_DIR ${CMAKE_BINARY_DIR}/eebus-grpc) |
| 9 | + |
| 10 | +file(GLOB_RECURSE EEBUS_GRPC_API_SOURCE_FILES |
| 11 | + CONFIGURE_DEPENDS |
| 12 | + ${EEBUS_GRPC_API_SOURCE_DIR}/* |
| 13 | +) |
| 14 | + |
| 15 | +setup_go() |
| 16 | +add_go_target( |
| 17 | + NAME |
| 18 | + eebus_grpc_api_cmd |
| 19 | + OUTPUT |
| 20 | + ${EEBUS_GRPC_API_BINARY_DIR}/cmd |
| 21 | + GO_PACKAGE_SOURCE_PATH |
| 22 | + ${EEBUS_GRPC_API_SOURCE_DIR}/cmd |
| 23 | + OUTPUT_DIRECTORY |
| 24 | + ${EEBUS_GRPC_API_BINARY_DIR} |
| 25 | + WORKING_DIRECTORY |
| 26 | + ${EEBUS_GRPC_API_SOURCE_DIR} |
| 27 | + DEPENDS |
| 28 | + ${EEBUS_GRPC_API_SOURCE_FILES} |
| 29 | +) |
| 30 | + |
| 31 | +add_go_target( |
| 32 | + NAME |
| 33 | + eebus_grpc_api_create_cert |
| 34 | + OUTPUT |
| 35 | + ${EEBUS_GRPC_API_BINARY_DIR}/create_cert |
| 36 | + GO_PACKAGE_SOURCE_PATH |
| 37 | + ${EEBUS_GRPC_API_SOURCE_DIR}/cmd/create_cert |
| 38 | + OUTPUT_DIRECTORY |
| 39 | + ${EEBUS_GRPC_API_BINARY_DIR} |
| 40 | + WORKING_DIRECTORY |
| 41 | + ${EEBUS_GRPC_API_SOURCE_DIR} |
| 42 | + DEPENDS |
| 43 | + ${EEBUS_GRPC_API_SOURCE_FILES} |
| 44 | +) |
| 45 | + |
| 46 | +add_custom_target(eebus_grpc_api_all |
| 47 | + DEPENDS |
| 48 | + eebus_grpc_api_cmd |
| 49 | + eebus_grpc_api_create_cert |
| 50 | +) |
| 51 | + |
| 52 | +install( |
| 53 | + FILES |
| 54 | + ${EEBUS_GRPC_API_BINARY_DIR}/cmd |
| 55 | + DESTINATION |
| 56 | + ${CMAKE_INSTALL_PREFIX}/bin |
| 57 | + RENAME |
| 58 | + eebus_grpc_api |
| 59 | + PERMISSIONS |
| 60 | + OWNER_EXECUTE OWNER_WRITE OWNER_READ |
| 61 | + GROUP_EXECUTE GROUP_READ |
| 62 | + WORLD_EXECUTE WORLD_READ |
| 63 | +) |
| 64 | + |
| 65 | +# This function creates certificates for an EEBus component |
| 66 | +# |
| 67 | +# It will generate thre files: |
| 68 | +# - <OUT_DIR>/<NAME>_cert |
| 69 | +# - <OUT_DIR>/<NAME>_key |
| 70 | +# - <OUT_DIR>/<NAME>_ski |
| 71 | +# The generation can be triggered by calling the target <TARGET_NAME> |
| 72 | +# |
| 73 | +function(eebus_create_cert) |
| 74 | + set(options) |
| 75 | + set(one_value_args |
| 76 | + NAME |
| 77 | + OUT_DIR |
| 78 | + TARGET_NAME |
| 79 | + OUT_FILES_VAR |
| 80 | + ) |
| 81 | + set(multi_value_args) |
| 82 | + cmake_parse_arguments(arg "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN}) |
| 83 | + |
| 84 | + if (arg_UNPARSED_ARGUMENTS) |
| 85 | + message(FATAL_ERROR "Unparsed arguments: ${arg_UNPARSED_ARGUMENTS}") |
| 86 | + endif() |
| 87 | + if (arg_KEYWORDS_MISSING_VALUES) |
| 88 | + message(FATAL_ERROR "Keywords missing values: ${arg_KEYWORDS_MISSING_VALUES}") |
| 89 | + endif() |
| 90 | + if (NOT arg_NAME) |
| 91 | + message(FATAL_ERROR "NAME not set") |
| 92 | + endif() |
| 93 | + if (NOT arg_OUT_DIR) |
| 94 | + message(FATAL_ERROR "OUT_DIR not set") |
| 95 | + endif() |
| 96 | + if (NOT IS_ABSOLUTE ${arg_OUT_DIR}) |
| 97 | + message(FATAL_ERROR "OUT_DIR ${arg_OUT_DIR} is not an absolute path") |
| 98 | + endif() |
| 99 | + if (NOT arg_TARGET_NAME) |
| 100 | + message(FATAL_ERROR "TARGET_NAME not set") |
| 101 | + endif() |
| 102 | + |
| 103 | + get_target_property(CREATE_CERT_BINARY_FILE eebus_grpc_api_create_cert TARGET_FILE) |
| 104 | + set(OUT_FILES |
| 105 | + ${arg_OUT_DIR}/${arg_NAME}_cert |
| 106 | + ${arg_OUT_DIR}/${arg_NAME}_key |
| 107 | + ${arg_OUT_DIR}/${arg_NAME}_ski |
| 108 | + ) |
| 109 | + add_custom_command( |
| 110 | + OUTPUT |
| 111 | + ${OUT_FILES} |
| 112 | + COMMAND |
| 113 | + mkdir -p ${arg_OUT_DIR} |
| 114 | + COMMAND |
| 115 | + ${CREATE_CERT_BINARY_FILE} |
| 116 | + ARGS |
| 117 | + ${arg_OUT_DIR} |
| 118 | + ${arg_NAME} |
| 119 | + DEPENDS |
| 120 | + eebus_grpc_api_create_cert |
| 121 | + COMMENT |
| 122 | + "Creating ${arg_NAME} certificates" |
| 123 | + ) |
| 124 | + add_custom_target(${arg_TARGET_NAME} |
| 125 | + DEPENDS |
| 126 | + ${OUT_FILES} |
| 127 | + ) |
| 128 | + |
| 129 | + if (arg_OUT_FILES_VAR) |
| 130 | + set(${arg_OUT_FILES_VAR} ${OUT_FILES} PARENT_SCOPE) |
| 131 | + endif() |
| 132 | +endfunction() |
0 commit comments