svn commit: r1926286 - in /subversion/trunk: CMakeLists.txt build/cmake/extractor.cmake

[email protected]
Newsgroups gmane.comp.version-control.subversion.svn
Message-ID <[email protected]>
Author: rinrab
Date: Mon Jun  9 13:41:13 2025
New Revision: 1926286

URL: http://svn.apache.org/viewvc?rev=1926286&view=rev
Log:
cmake: Generate def files in build time using an external script
extractor.cmake script (similarly to extractor.py).

* build/cmake/extractor.cmake: New file, with symbol scrapper code.
* CMakeLists.txt
  (def generator): Generate def files using custom commands and
   the extractor.cmake script.

Added:
    subversion/trunk/build/cmake/extractor.cmake
Modified:
    subversion/trunk/CMakeLists.txt

Modified: subversion/trunk/CMakeLists.txt
URL: http://svn.apache.org/viewvc/subversion/trunk/CMakeLists.txt?rev=1926286&r1=1926285&r2=1926286&view=diff
==============================================================================
--- subversion/trunk/CMakeLists.txt (original)
+++ subversion/trunk/CMakeLists.txt Mon Jun  9 13:41:13 2025
@@ -516,52 +516,22 @@ function(target_exports target_name)
     )
 
     set(def_file_path ${CMAKE_BINARY_DIR}/${target_name}.def)
+    set(headers)
 
-    # see build/generator/extractor.py
-    set(func_regex "(^|\n)((([A-Za-z0-9_]+|[*]) )+[*]?)?((svn|apr)_[A-Za-z0-9_]+)[ \t\r\n]*\\(")
-
-    set(defs)
     foreach(file ${ARGN})
-      file(READ ${file} contents)
-      string(REGEX MATCHALL "${func_regex}" funcs ${contents})
-
-      foreach(func_string ${funcs})
-        string(REGEX MATCH "[A-Za-z0-9_]+[ \t\r\n]*\\($" func_name ${func_string})
-        string(REGEX REPLACE "[ \t\r\n]*\\($" "" func_name ${func_name})
-        list(APPEND defs "${func_name}")
-      endforeach()
-
-      get_filename_component(filename ${file} NAME)
-      if(${filename} STREQUAL "svn_ctype.h")
-        # See libsvn_subr/ctype.c for an explanation why we use CONSTANT and not
-        # DATA, even though it causes an LNK4087 warning!
-        list(APPEND defs "svn_ctype_table = svn_ctype_table_internal CONSTANT")
-      elseif(${filename} STREQUAL "svn_wc_private.h")
-        # svn_wc__internal_walk_children() is now internal to libsvn_wc
-        # but entries-dump.c still calls it
-        list(APPEND defs "svn_wc__internal_walk_children")
-      endif()
+      list(APPEND headers "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
     endforeach()
 
-    list(SORT defs)
-    list(REMOVE_DUPLICATES defs)
-
-    set(def_file_content "EXPORTS\n")
-    foreach(def ${defs})
-      list(FIND filter_names "${def}" skip)
-      if(skip LESS 0)
-        string(APPEND def_file_content "${def}\n")
-      endif()
-    endforeach()
-
-    if(EXISTS "${def_file_path}")
-      file(READ "${def_file_path}" old_file_content)
-    else()
-      set(old_file_content "NOT_EXISTS")
-    endif()
-    if(NOT ${old_file_content} STREQUAL ${def_file_content})
-      file(WRITE "${def_file_path}" ${def_file_content})
-    endif()
+    add_custom_command(
+      OUTPUT "${def_file_path}"
+      DEPENDS ${headers}
+      COMMAND ${CMAKE_COMMAND}
+              "-DEXPORT_HEADER_FILE_PATHS=${headers}"
+              "-DEXPORT_DEF_FILE_PATH=${def_file_path}"
+              "-DEXPORT_BLACKLIST=${filter_names}"
+              -P "${CMAKE_CURRENT_SOURCE_DIR}/build/cmake/extractor.cmake"
+      WORKING_DIRECTORY "${SERF_SOURCE_DIR}"
+    )
 
     target_sources("${target_name}" PRIVATE "${def_file_path}")
   endif()

Added: subversion/trunk/build/cmake/extractor.cmake
URL: http://svn.apache.org/viewvc/subversion/trunk/build/cmake/extractor.cmake?rev=1926286&view=auto
==============================================================================
--- subversion/trunk/build/cmake/extractor.cmake (added)
+++ subversion/trunk/build/cmake/extractor.cmake Mon Jun  9 13:41:13 2025
@@ -0,0 +1,74 @@
+#
+# 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.
+#
+# extractor.cmake -- Extracts function names from header files and writes
+# them to a .def file.
+#
+# cmake -DEXPORT_HEADER_FILE_PATHS=<...path_to_header_files>
+#       -DEXPORT_DEF_FILE_PATH=<path_to_def_file>
+#       [-DEXPORT_BLACKLIST=<...symbols_to_ignore>]
+#       -P extractor.cmake
+
+separate_arguments(EXPORT_HEADER_FILE_PATHS)
+separate_arguments(EXPORT_BLACKLIST)
+
+# see build/generator/extractor.py
+set(func_regex "(^|\n)((([A-Za-z0-9_]+|[*]) )+[*]?)?((svn|apr)_[A-Za-z0-9_]+)[ \t\r\n]*\\(")
+
+set(defs)
+foreach(file ${EXPORT_HEADER_FILE_PATHS})
+  file(READ ${file} contents)
+  string(REGEX MATCHALL "${func_regex}" funcs ${contents})
+
+  foreach(func_string ${funcs})
+    string(REGEX MATCH "[A-Za-z0-9_]+[ \t\r\n]*\\($" func_name ${func_string})
+    string(REGEX REPLACE "[ \t\r\n]*\\($" "" func_name ${func_name})
+    list(APPEND defs "${func_name}")
+  endforeach()
+
+  get_filename_component(filename ${file} NAME)
+  if(${filename} STREQUAL "svn_ctype.h")
+    # See libsvn_subr/ctype.c for an explanation why we use CONSTANT and not
+    # DATA, even though it causes an LNK4087 warning!
+    list(APPEND defs "svn_ctype_table = svn_ctype_table_internal CONSTANT")
+  elseif(${filename} STREQUAL "svn_wc_private.h")
+    # svn_wc__internal_walk_children() is now internal to libsvn_wc
+    # but entries-dump.c still calls it
+    list(APPEND defs "svn_wc__internal_walk_children")
+  endif()
+endforeach()
+
+list(SORT defs)
+list(REMOVE_DUPLICATES defs)
+
+set(def_file_content "EXPORTS\n")
+foreach(def ${defs})
+  list(FIND EXPORT_BLACKLIST "${def}" skip)
+  if(skip LESS 0)
+    string(APPEND def_file_content "${def}\n")
+  endif()
+endforeach()
+
+if(EXISTS "${EXPORT_DEF_FILE_PATH}")
+  file(READ "${EXPORT_DEF_FILE_PATH}" old_file_content)
+else()
+  set(old_file_content "NOT_EXISTS")
+endif()
+if(NOT ${old_file_content} STREQUAL ${def_file_content})
+  file(WRITE "${EXPORT_DEF_FILE_PATH}" ${def_file_content})
+endif()
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.