Gyorgy Szing | 4909180 | 2020-11-24 00:33:09 +0100 | [diff] [blame^] | 1 | #------------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2020, Arm Limited and Contributors. All rights reserved. |
| 3 | # |
| 4 | # SPDX-License-Identifier: BSD-3-Clause |
| 5 | # |
| 6 | #------------------------------------------------------------------------------- |
| 7 | |
| 8 | #[===[.rst: |
| 9 | .. cmake:command:: export_library |
| 10 | |
| 11 | .. code:: cmake |
| 12 | |
| 13 | export_library(TARGET LIB_NAME INTERFACE_FILES) |
| 14 | |
| 15 | INPUTS: |
| 16 | |
| 17 | ``TARGET`` |
| 18 | The name of an already defined target that corresponds to the library. |
| 19 | |
| 20 | ``LIB_NAME`` |
| 21 | The name of the library. |
| 22 | |
| 23 | ``INTERFACE_FILES`` |
| 24 | List of header files to declare the library's public interface. |
| 25 | |
| 26 | #]===] |
| 27 | function(export_library) |
| 28 | set(options ) |
| 29 | set(oneValueArgs TARGET LIB_NAME) |
| 30 | set(multiValueArgs INTERFACE_FILES) |
| 31 | cmake_parse_arguments(MY_PARAMS "${options}" "${oneValueArgs}" |
| 32 | "${multiValueArgs}" ${ARGN} ) |
| 33 | |
| 34 | if(NOT DEFINED MY_PARAMS_TARGET) |
| 35 | message(FATAL_ERROR "export_library: mandatory parameter TARGET not defined!") |
| 36 | endif() |
| 37 | if(NOT DEFINED MY_PARAMS_LIB_NAME) |
| 38 | message(FATAL_ERROR "export_library: mandatory parameter LIB_NAME not defined!") |
| 39 | endif() |
| 40 | |
| 41 | # Set default install location if none specified |
| 42 | if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) |
| 43 | set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "location to install build output to." FORCE) |
| 44 | endif() |
| 45 | |
| 46 | # Specify export name and destinations for install |
| 47 | install( |
| 48 | TARGETS ${MY_PARAMS_TARGET} |
| 49 | EXPORT ${MY_PARAMS_LIB_NAME}_targets |
| 50 | ARCHIVE |
| 51 | DESTINATION lib |
| 52 | LIBRARY |
| 53 | DESTINATION lib |
| 54 | PUBLIC_HEADER |
| 55 | DESTINATION include |
| 56 | ) |
| 57 | |
| 58 | # Install library header files files |
| 59 | install( |
| 60 | FILES ${MY_PARAMS_INTERFACE_FILES} |
| 61 | DESTINATION include |
| 62 | ) |
| 63 | |
| 64 | # Install the export details |
| 65 | install( |
| 66 | EXPORT ${MY_PARAMS_LIB_NAME}_targets |
| 67 | FILE ${MY_PARAMS_LIB_NAME}_targets.cmake |
| 68 | NAMESPACE ${MY_PARAMS_LIB_NAME}:: |
| 69 | DESTINATION lib/cmake |
| 70 | COMPONENT ${MY_PARAMS_LIB_NAME} |
| 71 | ) |
| 72 | endfunction() |