2023-08-14 20:22:05 +08:00
|
|
|
# ##############################################################################
|
|
|
|
# cmake/nuttx_export_headers.cmake
|
|
|
|
#
|
|
|
|
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
|
|
|
|
# license agreements. See the NOTICE file distributed with this work for
|
|
|
|
# additional information regarding copyright ownership. The ASF licenses this
|
|
|
|
# file to you under the Apache License, Version 2.0 (the "License"); you may not
|
|
|
|
# use this file except in compliance with the License. You may obtain a copy of
|
|
|
|
# the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
# License for the specific language governing permissions and limitations under
|
|
|
|
# the License.
|
|
|
|
#
|
|
|
|
# ##############################################################################
|
|
|
|
|
|
|
|
include(nuttx_parse_function_args)
|
|
|
|
|
|
|
|
# export_relative_path_recursively
|
|
|
|
#
|
|
|
|
# Used to recursively add all header files under the `include_directory` to the
|
2023-08-25 15:37:56 +08:00
|
|
|
# `include_path` directory and preserve their relative relationship
|
2023-08-14 20:22:05 +08:00
|
|
|
#
|
|
|
|
# When the target relative path is repeated and the original path is different
|
|
|
|
# throws an exception and abort the build
|
2023-08-25 15:37:56 +08:00
|
|
|
function(export_relative_path_recursively include_path export_path
|
|
|
|
include_directory)
|
2023-08-14 20:22:05 +08:00
|
|
|
# recursively find header files under the path
|
|
|
|
file(GLOB_RECURSE FOUND_FILES ${include_directory}/*.h)
|
|
|
|
if(FOUND_FILES)
|
|
|
|
foreach(FOUND_FILE ${FOUND_FILES})
|
|
|
|
if(EXISTS ${FOUND_FILE})
|
|
|
|
# take relative path
|
|
|
|
file(RELATIVE_PATH REL_FILE ${include_directory} ${FOUND_FILE})
|
|
|
|
# check for path conflicts
|
|
|
|
string(REPLACE "/" "_" CHECK_PROP _check_${prefix}_${REL_FILE})
|
|
|
|
get_property(REL_FILE_CHECK GLOBAL PROPERTY ${CHECK_PROP})
|
|
|
|
if(REL_FILE_CHECK AND NOT REL_FILE_CHECK STREQUAL FOUND_FILE)
|
|
|
|
message(
|
|
|
|
FATAL_ERROR
|
|
|
|
"Error: NUTTX_ADD_APPS_HEADER add a duplicate header files ${FOUND_FILE} ${REL_FILE_CHECK}"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
set_property(GLOBAL PROPERTY ${CHECK_PROP} ${FOUND_FILE})
|
|
|
|
message(
|
|
|
|
VERBOSE
|
|
|
|
"NUTTX_ADD_APPS_HEADER: REL_FILE found: ${REL_FILE} in ${INCDIR}")
|
2023-08-25 15:37:56 +08:00
|
|
|
# create symbolic link for origin
|
|
|
|
file(CREATE_LINK ${FOUND_FILE} ${include_path}/${REL_FILE}
|
|
|
|
COPY_ON_ERROR SYMBOLIC)
|
2023-08-14 20:22:05 +08:00
|
|
|
# do export to the BINAPPS/include directory
|
2023-08-25 15:37:56 +08:00
|
|
|
get_filename_component(DES_PATH ${export_path}/${REL_FILE} DIRECTORY)
|
|
|
|
install(FILES ${FOUND_FILE} DESTINATION ${DES_PATH})
|
2023-08-14 20:22:05 +08:00
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# ~~~
|
|
|
|
# nuttx_export_header
|
|
|
|
#
|
|
|
|
# Description:
|
|
|
|
# Export include directory to apps global include path.
|
|
|
|
# `${NUTTX_APPS_BINDIR}/include/${TARGET}`
|
|
|
|
# preserve relative paths to all header files.
|
|
|
|
#
|
|
|
|
# In the original GNU Make build, we use `Make.defs` to add the global include path,
|
|
|
|
# and the private include path of the application library is written in the `Makefile`
|
|
|
|
# In Nuttx CMake build, we achieve similar global functionality through this function.
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
# nuttx_export_header(TARGET <string> INCLUDE_DIRECTORIES <list>)
|
|
|
|
#
|
|
|
|
# Parameters:
|
|
|
|
# TARGET : target for exporting header directory
|
|
|
|
# INCLUDE_DIRECTORIES : directory list to be exported
|
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
# set(INCDIRS foo/include)
|
|
|
|
# nuttx_export_header(TARGET foo INCLUDE_DIRECTORIES ${INCDIRS})
|
|
|
|
#
|
2023-08-25 15:37:56 +08:00
|
|
|
# foo/include/ build/apps/include/foo/
|
|
|
|
# ├── demo/ ├── demo/
|
|
|
|
# | └── demo.h cmake --build:origin link | └── demo.h
|
|
|
|
# ├── test/ =====================> ├── test/
|
|
|
|
# | └── test.h cmake --install:export | └── test.h
|
|
|
|
# └── foo.h └── foo.h
|
2023-08-14 20:22:05 +08:00
|
|
|
# ~~~
|
|
|
|
|
|
|
|
function(nuttx_export_header)
|
|
|
|
|
|
|
|
# parse arguments into variables
|
|
|
|
|
|
|
|
nuttx_parse_function_args(
|
|
|
|
FUNC
|
|
|
|
nuttx_export_header
|
|
|
|
ONE_VALUE
|
|
|
|
TARGET
|
|
|
|
MULTI_VALUE
|
|
|
|
INCLUDE_DIRECTORIES
|
|
|
|
REQUIRED
|
|
|
|
TARGET
|
|
|
|
INCLUDE_DIRECTORIES
|
|
|
|
ARGN
|
|
|
|
${ARGN})
|
|
|
|
|
2023-08-25 15:37:56 +08:00
|
|
|
# destination directory to be exported by install
|
|
|
|
set(EXPORT_PATH_PREFIX ${CMAKE_BINARY_DIR}/staging/include/${TARGET})
|
|
|
|
# destination directory origin compile
|
|
|
|
set(INCLUDE_PATH_PREFIX ${NUTTX_APPS_BINDIR}/include/${TARGET})
|
2023-08-14 20:22:05 +08:00
|
|
|
|
|
|
|
foreach(INCDIR ${INCLUDE_DIRECTORIES})
|
|
|
|
if(NOT EXISTS ${INCDIR})
|
|
|
|
message(
|
|
|
|
WARNING
|
|
|
|
"warning: NUTTX_EXPORT_HEADER ${TARGET} added a path that does not exist ${INCDIR}"
|
|
|
|
)
|
|
|
|
else()
|
|
|
|
if(IS_DIRECTORY ${INCDIR})
|
|
|
|
# export relative path to directories
|
2023-08-25 15:37:56 +08:00
|
|
|
export_relative_path_recursively(${INCLUDE_PATH_PREFIX}
|
|
|
|
${EXPORT_PATH_PREFIX} ${INCDIR})
|
2023-08-14 20:22:05 +08:00
|
|
|
else()
|
|
|
|
# export single file
|
2023-08-25 15:37:56 +08:00
|
|
|
file(CREATE_LINK ${INCDIR} ${INCLUDE_PATH_PREFIX}/${INCDIR}
|
|
|
|
COPY_ON_ERROR SYMBOLIC)
|
|
|
|
install(FILES ${INCDIR} DESTINATION ${EXPORT_PATH_PREFIX})
|
2023-08-14 20:22:05 +08:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
endfunction()
|