1
0
Fork 0
forked from nuttx/nuttx-update

cmake:export_header support origin link and export install

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
This commit is contained in:
xuxin19 2023-08-25 15:37:56 +08:00 committed by Xiang Xiao
parent 033f265e53
commit 5dd4af19f2

View file

@ -23,11 +23,12 @@ include(nuttx_parse_function_args)
# export_relative_path_recursively # export_relative_path_recursively
# #
# Used to recursively add all header files under the `include_directory` to the # Used to recursively add all header files under the `include_directory` to the
# `prefix` directory and preserve their relative relationship # `include_path` directory and preserve their relative relationship
# #
# When the target relative path is repeated and the original path is different # When the target relative path is repeated and the original path is different
# throws an exception and abort the build # throws an exception and abort the build
function(export_relative_path_recursively prefix include_directory) function(export_relative_path_recursively include_path export_path
include_directory)
# recursively find header files under the path # recursively find header files under the path
file(GLOB_RECURSE FOUND_FILES ${include_directory}/*.h) file(GLOB_RECURSE FOUND_FILES ${include_directory}/*.h)
if(FOUND_FILES) if(FOUND_FILES)
@ -48,12 +49,12 @@ function(export_relative_path_recursively prefix include_directory)
message( message(
VERBOSE VERBOSE
"NUTTX_ADD_APPS_HEADER: REL_FILE found: ${REL_FILE} in ${INCDIR}") "NUTTX_ADD_APPS_HEADER: REL_FILE found: ${REL_FILE} in ${INCDIR}")
# create symbolic link for origin
file(CREATE_LINK ${FOUND_FILE} ${include_path}/${REL_FILE}
COPY_ON_ERROR SYMBOLIC)
# do export to the BINAPPS/include directory # do export to the BINAPPS/include directory
get_filename_component(DES_PATH ${prefix}/${REL_FILE} DIRECTORY) get_filename_component(DES_PATH ${export_path}/${REL_FILE} DIRECTORY)
file( install(FILES ${FOUND_FILE} DESTINATION ${DES_PATH})
COPY ${FOUND_FILE}
DESTINATION ${DES_PATH}
FOLLOW_SYMLINK_CHAIN)
endif() endif()
endforeach() endforeach()
endif() endif()
@ -82,12 +83,12 @@ endfunction()
# set(INCDIRS foo/include) # set(INCDIRS foo/include)
# nuttx_export_header(TARGET foo INCLUDE_DIRECTORIES ${INCDIRS}) # nuttx_export_header(TARGET foo INCLUDE_DIRECTORIES ${INCDIRS})
# #
# foo/include/ build/apps/include/foo/ # foo/include/ build/apps/include/foo/
# demo/ demo/ # demo/ demo/
# | demo.h export to | demo.h # | demo.h cmake --build:origin link | demo.h
# test/ ============> test/ # test/ =====================> test/
# | test.h | test.h # | test.h cmake --install:export | test.h
# foo.h foo.h # foo.h foo.h
# ~~~ # ~~~
function(nuttx_export_header) function(nuttx_export_header)
@ -107,8 +108,10 @@ function(nuttx_export_header)
ARGN ARGN
${ARGN}) ${ARGN})
# destination directory to be exported # destination directory to be exported by install
set(PATH_PREFIX ${NUTTX_APPS_BINDIR}/include/${TARGET}) set(EXPORT_PATH_PREFIX ${CMAKE_BINARY_DIR}/staging/include/${TARGET})
# destination directory origin compile
set(INCLUDE_PATH_PREFIX ${NUTTX_APPS_BINDIR}/include/${TARGET})
foreach(INCDIR ${INCLUDE_DIRECTORIES}) foreach(INCDIR ${INCLUDE_DIRECTORIES})
if(NOT EXISTS ${INCDIR}) if(NOT EXISTS ${INCDIR})
@ -119,14 +122,13 @@ function(nuttx_export_header)
else() else()
if(IS_DIRECTORY ${INCDIR}) if(IS_DIRECTORY ${INCDIR})
# export relative path to directories # export relative path to directories
export_relative_path_recursively(${PATH_PREFIX} ${INCDIR}) export_relative_path_recursively(${INCLUDE_PATH_PREFIX}
${EXPORT_PATH_PREFIX} ${INCDIR})
else() else()
# export single file # export single file
get_filename_component(DES_PATH ${prefix}/${REL_FILE} DIRECTORY) file(CREATE_LINK ${INCDIR} ${INCLUDE_PATH_PREFIX}/${INCDIR}
file( COPY_ON_ERROR SYMBOLIC)
COPY ${FOUND_FILE} install(FILES ${INCDIR} DESTINATION ${EXPORT_PATH_PREFIX})
DESTINATION ${DES_PATH}
FOLLOW_SYMLINK_CHAIN)
endif() endif()
endif() endif()
endforeach() endforeach()