You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "xuxin930 (via GitHub)" <gi...@apache.org> on 2023/08/15 02:04:40 UTC

[GitHub] [nuttx] xuxin930 commented on a diff in pull request #10224: cmake:new feature on enhance apps header cmake module

xuxin930 commented on code in PR #10224:
URL: https://github.com/apache/nuttx/pull/10224#discussion_r1294119319


##########
cmake/nuttx_apps_headers.cmake:
##########
@@ -0,0 +1,127 @@
+# ##############################################################################
+# cmake/nuttx_apps_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
+# `prefix` directory and preserve their relative relationship
+#
+# When the target relative path is repeated and the original path is different
+# throws an exception and abort the build
+function(export_relative_path_recursively prefix include_directory)
+  # 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}")
+        # create symbolic lick in the BINAPPS/include directory
+        file(CREATE_LINK ${FOUND_FILE} ${prefix}/${REL_FILE} COPY_ON_ERROR
+             SYMBOLIC)
+      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 libfoo INCLUDE_DIRECTORIES ${INCDIRS})
+#
+#   foo/include/                          build/apps/include/foo/
+#       ├── demo/                                   ├── demo/
+#       |   └── demo.h      symbolic link           |   └── demo.h

Review Comment:
   Yes, it is better, and more suitable for situations like install header
   let me replace it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org