|
| 1 | +# Copyright (c) Facebook, Inc. and its affiliates. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +include_guard(GLOBAL) |
| 15 | + |
| 16 | +# TODO use file sets |
| 17 | +function(velox_install_library_headers) |
| 18 | + # Find any headers and install them relative to the source tree in include. |
| 19 | + file(GLOB _hdrs "*.h") |
| 20 | + if(NOT "${_hdrs}" STREQUAL "") |
| 21 | + cmake_path( |
| 22 | + RELATIVE_PATH |
| 23 | + CMAKE_CURRENT_SOURCE_DIR |
| 24 | + BASE_DIRECTORY |
| 25 | + "${CMAKE_SOURCE_DIR}" |
| 26 | + OUTPUT_VARIABLE |
| 27 | + _hdr_dir) |
| 28 | + install(FILES ${_hdrs} DESTINATION include/${_hdr_dir}) |
| 29 | + endif() |
| 30 | +endfunction() |
| 31 | + |
| 32 | +# Base add velox library call to add a library and install it. |
| 33 | +function(velox_base_add_library TARGET) |
| 34 | + add_library(${TARGET} ${ARGN}) |
| 35 | + install(TARGETS ${TARGET} DESTINATION lib/velox) |
| 36 | + velox_install_library_headers() |
| 37 | +endfunction() |
| 38 | + |
| 39 | +# This is extremely hackish but presents an easy path to installation. |
| 40 | +function(velox_add_library TARGET) |
| 41 | + set(options OBJECT STATIC SHARED INTERFACE) |
| 42 | + set(oneValueArgs) |
| 43 | + set(multiValueArgs) |
| 44 | + cmake_parse_arguments( |
| 45 | + VELOX |
| 46 | + "${options}" |
| 47 | + "${oneValueArgs}" |
| 48 | + "${multiValueArgs}" |
| 49 | + ${ARGN}) |
| 50 | + |
| 51 | + # Remove library type specifiers from ARGN |
| 52 | + set(library_type) |
| 53 | + if(VELOX_OBJECT) |
| 54 | + set(library_type OBJECT) |
| 55 | + elseif(VELOX_STATIC) |
| 56 | + set(library_type STATIC) |
| 57 | + elseif(VELOX_SHARED) |
| 58 | + set(library_type SHARED) |
| 59 | + elseif(VELOX_INTERFACE) |
| 60 | + set(library_type INTERFACE) |
| 61 | + endif() |
| 62 | + |
| 63 | + list(REMOVE_ITEM ARGN OBJECT) |
| 64 | + list(REMOVE_ITEM ARGN STATIC) |
| 65 | + list(REMOVE_ITEM ARGN SHARED) |
| 66 | + list(REMOVE_ITEM ARGN INTERFACE) |
| 67 | + # Propagate to the underlying add_library and then install the target. |
| 68 | + if(VELOX_MONO_LIBRARY) |
| 69 | + if(TARGET velox) |
| 70 | + # Target already exists, append sources to it. |
| 71 | + target_sources(velox PRIVATE ${ARGN}) |
| 72 | + else() |
| 73 | + # Create the target if this is the first invocation. |
| 74 | + add_library(velox ${ARGN}) |
| 75 | + set_target_properties(velox PROPERTIES LIBRARY_OUTPUT_DIRECTORY |
| 76 | + ${CMAKE_BINARY_DIR}/lib) |
| 77 | + set_target_properties(velox PROPERTIES ARCHIVE_OUTPUT_DIRECTORY |
| 78 | + ${CMAKE_BINARY_DIR}/lib) |
| 79 | + install(TARGETS velox DESTINATION lib/velox) |
| 80 | + endif() |
| 81 | + # create alias for compatability |
| 82 | + if(NOT TARGET ${TARGET}) |
| 83 | + add_library(${TARGET} ALIAS velox) |
| 84 | + endif() |
| 85 | + else() |
| 86 | + # Create a library for each invocation. |
| 87 | + velox_base_add_library(${TARGET} ${library_type} ${ARGN}) |
| 88 | + endif() |
| 89 | + velox_install_library_headers() |
| 90 | +endfunction() |
| 91 | + |
| 92 | +function(velox_link_libraries TARGET) |
| 93 | + # TODO(assignUser): Handle scope keywords (they currently are empty calls ala |
| 94 | + # target_link_libraries(target PRIVATE)) |
| 95 | + if(VELOX_MONO_LIBRARY) |
| 96 | + message(DEBUG "${TARGET}: ${ARGN}") |
| 97 | + foreach(_lib ${ARGN}) |
| 98 | + if("${_lib}" MATCHES "^velox_*") |
| 99 | + message(DEBUG "\t\tDROP: ${_lib}") |
| 100 | + else() |
| 101 | + message(DEBUG "\t\tADDING: ${_lib}") |
| 102 | + target_link_libraries(velox ${_lib}) |
| 103 | + endif() |
| 104 | + endforeach() |
| 105 | + else() |
| 106 | + target_link_libraries(${TARGET} ${ARGN}) |
| 107 | + endif() |
| 108 | +endfunction() |
| 109 | + |
| 110 | +function(velox_include_directories TARGET) |
| 111 | + if(VELOX_MONO_LIBRARY) |
| 112 | + target_include_directories(velox ${ARGN}) |
| 113 | + else() |
| 114 | + target_include_directories(${TARGET} ${ARGN}) |
| 115 | + endif() |
| 116 | +endfunction() |
| 117 | + |
| 118 | +function(velox_compile_definitions TARGET) |
| 119 | + if(VELOX_MONO_LIBRARY) |
| 120 | + target_compile_definitions(velox ${ARGN}) |
| 121 | + else() |
| 122 | + target_compile_definitions(${TARGET} ${ARGN}) |
| 123 | + endif() |
| 124 | +endfunction() |
| 125 | + |
| 126 | +function(velox_sources TARGET) |
| 127 | + if(VELOX_MONO_LIBRARY) |
| 128 | + target_sources(velox ${ARGN}) |
| 129 | + else() |
| 130 | + target_sources(${TARGET} ${ARGN}) |
| 131 | + endif() |
| 132 | +endfunction() |
0 commit comments