|
| 1 | +# Copyright 2026-present Alibaba Inc. |
| 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 | + |
| 15 | +function(paimon_find_target_headers OUT_VAR TARGET_NAME) |
| 16 | + set(options NO_DEFAULT_PATH) |
| 17 | + set(one_value_args) |
| 18 | + set(multi_value_args NAMES HINTS PATH_SUFFIXES) |
| 19 | + cmake_parse_arguments(ARG |
| 20 | + "${options}" |
| 21 | + "${one_value_args}" |
| 22 | + "${multi_value_args}" |
| 23 | + ${ARGN}) |
| 24 | + |
| 25 | + if(NOT TARGET ${TARGET_NAME} OR NOT ARG_NAMES) |
| 26 | + set(${OUT_VAR} |
| 27 | + "${OUT_VAR}-NOTFOUND" |
| 28 | + PARENT_SCOPE) |
| 29 | + return() |
| 30 | + endif() |
| 31 | + |
| 32 | + set(_target_include_dirs) |
| 33 | + foreach(_property INTERFACE_INCLUDE_DIRECTORIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES |
| 34 | + INCLUDE_DIRECTORIES) |
| 35 | + get_target_property(_property_value ${TARGET_NAME} ${_property}) |
| 36 | + if(_property_value AND NOT _property_value MATCHES "-NOTFOUND$") |
| 37 | + list(APPEND _target_include_dirs ${_property_value}) |
| 38 | + endif() |
| 39 | + endforeach() |
| 40 | + |
| 41 | + set(_search_dirs) |
| 42 | + foreach(_dir IN LISTS _target_include_dirs) |
| 43 | + if(_dir MATCHES "^\\$<BUILD_INTERFACE:(.*)>$") |
| 44 | + list(APPEND _search_dirs "${CMAKE_MATCH_1}") |
| 45 | + elseif(_dir MATCHES "^\\$<INSTALL_INTERFACE:(.*)>$") |
| 46 | + if(IS_ABSOLUTE "${CMAKE_MATCH_1}") |
| 47 | + list(APPEND _search_dirs "${CMAKE_MATCH_1}") |
| 48 | + endif() |
| 49 | + elseif(NOT _dir MATCHES "^\\$<") |
| 50 | + list(APPEND _search_dirs "${_dir}") |
| 51 | + endif() |
| 52 | + endforeach() |
| 53 | +
|
| 54 | + list(APPEND _search_dirs ${ARG_HINTS}) |
| 55 | + if(_search_dirs) |
| 56 | + list(REMOVE_DUPLICATES _search_dirs) |
| 57 | + endif() |
| 58 | +
|
| 59 | + string(MAKE_C_IDENTIFIER "${TARGET_NAME}_${ARG_NAMES}" _header_var_suffix) |
| 60 | + set(_header_dir_var "PAIMON_${_header_var_suffix}_HEADER_DIR") |
| 61 | + set(_find_args NAMES ${ARG_NAMES}) |
| 62 | + if(_search_dirs) |
| 63 | + list(APPEND _find_args HINTS ${_search_dirs}) |
| 64 | + endif() |
| 65 | + if(ARG_PATH_SUFFIXES) |
| 66 | + list(APPEND _find_args PATH_SUFFIXES ${ARG_PATH_SUFFIXES}) |
| 67 | + endif() |
| 68 | + list(APPEND _find_args NO_DEFAULT_PATH) |
| 69 | +
|
| 70 | + unset(${_header_dir_var} CACHE) |
| 71 | + find_path(${_header_dir_var} ${_find_args}) |
| 72 | +
|
| 73 | + if(NOT ${_header_dir_var}) |
| 74 | + get_property(_partial_targets GLOBAL PROPERTY PAIMON_PARTIAL_SYSTEM_TARGETS) |
| 75 | + list(APPEND _partial_targets "${TARGET_NAME}: ${ARG_NAMES}") |
| 76 | + set_property(GLOBAL PROPERTY PAIMON_PARTIAL_SYSTEM_TARGETS "${_partial_targets}") |
| 77 | + endif() |
| 78 | +
|
| 79 | + set(${OUT_VAR} |
| 80 | + "${${_header_dir_var}}" |
| 81 | + PARENT_SCOPE) |
| 82 | +
|
| 83 | + unset(${_header_dir_var} CACHE) |
| 84 | + unset(_find_args) |
| 85 | + unset(_header_dir_var) |
| 86 | + unset(_header_var_suffix) |
| 87 | + unset(_partial_targets) |
| 88 | + unset(_property_value) |
| 89 | + unset(_search_dirs) |
| 90 | + unset(_target_include_dirs) |
| 91 | +endfunction() |
0 commit comments