Author: brane
Date: Thu Jun  5 04:08:41 2025
New Revision: 1926140

URL: http://svn.apache.org/viewvc?rev=1926140&view=rev
Log:
In the CMake build, export only public symbols from Elf and Mach-O shared
libraries, just as we're already doing with Windows DLLs.

* build/SerfFindExports.cmake: Renamed from build/SerfWindowsToolkit.cmake.
  (SerfFindExports): Renamed from SerfWindowsGenDef. Just create and return
   the list of public symbols, don't write them to a file.
* build/SerfElfGenMap.cmake: New; generate the Elf .map file.
* build/SerfMachGenExp.cmake: New; generate the Mach-O .exp file.
* build/SerfWindowsGenDef.cmake: Use SerfFindExports and write the symbols
   to the Windows .def file.
* build/SerfPlatform.cmake
  (SERF_ELF_TARGET): New symbol. Defined for Linux. Maybe someday CMake
   will be nice enough to tell us if we're compiling for an Elf target.

* CMakeLists.txt:
  (SerfWindowsToolkit): Remove include of deleted file.
  (SERF_DEF_FILE): Rename the Windows .def file.
  (SERF_EXP_FILE, SERF_MAP_FILE): Generate .exp for Mack-O and .map for Elf.
  (serf_shared): Use .exp/.map to modify the list of exported symbols.

Added:
    serf/trunk/build/SerfElfGenMap.cmake   (with props)
    serf/trunk/build/SerfFindExports.cmake
      - copied, changed from r1926139, serf/trunk/build/SerfWindowsToolkit.cmake
    serf/trunk/build/SerfMachGenExp.cmake   (with props)
Removed:
    serf/trunk/build/SerfWindowsToolkit.cmake
Modified:
    serf/trunk/CMakeLists.txt
    serf/trunk/build/SerfPlatform.cmake
    serf/trunk/build/SerfWindowsGenDef.cmake

Modified: serf/trunk/CMakeLists.txt
URL: 
http://svn.apache.org/viewvc/serf/trunk/CMakeLists.txt?rev=1926140&r1=1926139&r2=1926140&view=diff
==============================================================================
--- serf/trunk/CMakeLists.txt (original)
+++ serf/trunk/CMakeLists.txt Thu Jun  5 04:08:41 2025
@@ -92,7 +92,6 @@ endif()
 
 include(GNUInstallDirs)
 include(SerfPlatform)
-include(SerfWindowsToolkit)
 
 # On the Mac: Use dependencies from Homebrew or MacPorts
 if(USE_HOMEBREW OR USE_MACPORTS)
@@ -188,15 +187,15 @@ list(APPEND SOURCES
 
 if(SERF_WINDOWS)
   # Generate the .def file for the Windows DLL import library.
-  set(SERF_DEF_FILE "${CMAKE_CURRENT_BINARY_DIR}/serf.def")
+  set(SERF_DEF_FILE 
"${CMAKE_CURRENT_BINARY_DIR}/libserf-${SERF_MAJOR_VERSION}.def")
   add_custom_command(
     OUTPUT "${SERF_DEF_FILE}"
     DEPENDS ${HEADERS}
     COMMAND ${CMAKE_COMMAND}
             -DCMAKE_SYSTEM_NAME="${CMAKE_SYSTEM_NAME}"
             -DCMAKE_MODULE_PATH="${CMAKE_MODULE_PATH}"
-            -DSERF_DEF_BLACKLIST="${EXPORTS_BLACKLIST}"
-            -DSERF_DEF_HEADERS="${HEADERS}"
+            -DSERF_EXPORT_BLACKLIST="${EXPORTS_BLACKLIST}"
+            -DSERF_EXPORT_HEADERS="${HEADERS}"
             -DSERF_DEF_FILE="${SERF_DEF_FILE}"
             -P "build/SerfWindowsGenDef.cmake"
     WORKING_DIRECTORY "${SERF_SOURCE_DIR}"
@@ -216,6 +215,40 @@ if(SERF_WINDOWS)
   add_compile_definitions("SERF_HAVE_SSPI")
 endif(SERF_WINDOWS)
 
+if(SERF_DARWIN)
+  set(SERF_EXP_FILE 
"${CMAKE_CURRENT_BINARY_DIR}/libserf-${SERF_MAJOR_VERSION}.exp")
+  add_custom_command(
+    OUTPUT "${SERF_EXP_FILE}"
+    DEPENDS ${HEADERS}
+    COMMAND ${CMAKE_COMMAND}
+            -DCMAKE_SYSTEM_NAME="${CMAKE_SYSTEM_NAME}"
+            -DCMAKE_MODULE_PATH="${CMAKE_MODULE_PATH}"
+            -DSERF_EXPORT_BLACKLIST="${EXPORTS_BLACKLIST}"
+            -DSERF_EXPORT_HEADERS="${HEADERS}"
+            -DSERF_EXP_FILE="${SERF_EXP_FILE}"
+            -P "build/SerfMachGenExp.cmake"
+    WORKING_DIRECTORY "${SERF_SOURCE_DIR}"
+  )
+  set(SHARED_SOURCES "${SERF_EXP_FILE}")
+endif(SERF_DARWIN)
+
+if(SERF_ELF_TARGET)
+  set(SERF_MAP_FILE 
"${CMAKE_CURRENT_BINARY_DIR}/libserf-${SERF_MAJOR_VERSION}.map")
+  add_custom_command(
+    OUTPUT "${SERF_MAP_FILE}"
+    DEPENDS ${HEADERS}
+    COMMAND ${CMAKE_COMMAND}
+            -DCMAKE_SYSTEM_NAME="${CMAKE_SYSTEM_NAME}"
+            -DCMAKE_MODULE_PATH="${CMAKE_MODULE_PATH}"
+            -DSERF_EXPORT_BLACKLIST="${EXPORTS_BLACKLIST}"
+            -DSERF_EXPORT_HEADERS="${HEADERS}"
+            -DSERF_MAP_FILE="${SERF_MAP_FILE}"
+            -P "build/SerfElfGenMap.cmake"
+    WORKING_DIRECTORY "${SERF_SOURCE_DIR}"
+  )
+  set(SHARED_SOURCES "${SERF_MAP_FILE}")
+endif(SERF_ELF_TARGET)
+
 # Process build options for dependency search
 if(SERF_WINDOWS)
   if(EXPAT)
@@ -379,6 +412,14 @@ if(NOT SKIP_SHARED)
     set_target_properties(serf_shared PROPERTIES
       INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${SERF_INSTALL_LIBRARIES}")
   endif()
+  if(SERF_DARWIN)
+    set_target_properties(serf_shared PROPERTIES
+      LINK_FLAGS "-Wl,-exported_symbols_list,${SERF_EXP_FILE}")
+  endif()
+  if(SERF_ELF_TARGET)
+    set_target_properties(serf_shared PROPERTIES
+      LINK_FLAGS "-Wl,--version-script,${SERF_MAP_FILE}")
+  endif()
   set(SERF_TARGETS "serf_shared")
 
   if(SERF_WINDOWS)

Added: serf/trunk/build/SerfElfGenMap.cmake
URL: 
http://svn.apache.org/viewvc/serf/trunk/build/SerfElfGenMap.cmake?rev=1926140&view=auto
==============================================================================
--- serf/trunk/build/SerfElfGenMap.cmake (added)
+++ serf/trunk/build/SerfElfGenMap.cmake Thu Jun  5 04:08:41 2025
@@ -0,0 +1,37 @@
+# ===================================================================
+#   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.
+# ===================================================================
+
+# Generate Serf's .map file for Elf shared libraries.
+
+include(SerfFindExports)
+
+separate_arguments(SERF_EXPORT_BLACKLIST)
+separate_arguments(SERF_EXPORT_HEADERS)
+
+SerfFindExports("${SERF_EXPORT_BLACKLIST}" exports_ ${SERF_EXPORT_HEADERS})
+file(WRITE "${SERF_MAP_FILE}"
+     "{\n"
+     "  global:\n")
+foreach(symbol_ ${exports_})
+  file(APPEND "${SERF_MAP_FILE}" "    ${symbol_};\n")
+endforeach()
+file(APPEND "${SERF_MAP_FILE}"
+     "  local:\n"
+     "    *;\n"
+     "};\n")

Propchange: serf/trunk/build/SerfElfGenMap.cmake
------------------------------------------------------------------------------
    svn:eol-style = native

Copied: serf/trunk/build/SerfFindExports.cmake (from r1926139, 
serf/trunk/build/SerfWindowsToolkit.cmake)
URL: 
http://svn.apache.org/viewvc/serf/trunk/build/SerfFindExports.cmake?p2=serf/trunk/build/SerfFindExports.cmake&p1=serf/trunk/build/SerfWindowsToolkit.cmake&r1=1926139&r2=1926140&rev=1926140&view=diff
==============================================================================
--- serf/trunk/build/SerfWindowsToolkit.cmake (original)
+++ serf/trunk/build/SerfFindExports.cmake Thu Jun  5 04:08:41 2025
@@ -17,39 +17,33 @@
 #   under the License.
 # ===================================================================
 
-# Generate a Windows DLL .def file from a list of headers.
-function(SerfWindowsGenDef blacklist_ target_)
-  if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
-    set(W "[a-zA-Z_0-9]") # Word characters pattern
-    set(base_func_rx_     "^((${W}+|\\*) )+\\*?(serf_[a-z]${W}*)\\(")
-    set(base_type_rx_     "^extern const serf_bucket_type_t (serf_[a-z_]*)")
-    set(func_search_rx_   "${base_func_rx_}")
-    set(type_search_rx_   "${base_type_rx_};")
-    set(func_name_rx_     "${base_func_rx_}.*$")
-    set(type_name_rx_     "${base_type_rx_}.*$")
+# Generate list of symbols to export from shared libraries..
+function(SerfFindExports blacklist_ output_)
+  set(W "[a-zA-Z_0-9]") # Word characters pattern
+  set(base_func_rx_     "^((${W}+|\\*) )+\\*?(serf_[a-z]${W}*)\\(")
+  set(base_type_rx_     "^extern const serf_bucket_type_t (serf_[a-z_]*)")
+  set(func_search_rx_   "${base_func_rx_}")
+  set(type_search_rx_   "${base_type_rx_};")
+  set(func_name_rx_     "${base_func_rx_}.*$")
+  set(type_name_rx_     "${base_type_rx_}.*$")
 
-    foreach(file_ ${ARGN})
-      message(STATUS "Looking for exports in ${file_}")
-      file(STRINGS ${file_} funcs_ REGEX "${func_search_rx_}")
-      file(STRINGS ${file_} types_ REGEX "${type_search_rx_}")
-      foreach(sym_ ${funcs_})
-        string(REGEX REPLACE "${func_name_rx_}" "\\3" def_ ${sym_})
-        list(APPEND defs_ ${def_})
-      endforeach()
-      foreach(sym_ ${types_})
-        string(REGEX REPLACE "${type_name_rx_}" "\\1" def_ ${sym_})
-        list(APPEND defs_ ${def_})
-      endforeach()
+  foreach(file_ ${ARGN})
+    message(STATUS "Looking for exports in ${file_}")
+    file(STRINGS ${file_} funcs_ REGEX "${func_search_rx_}")
+    file(STRINGS ${file_} types_ REGEX "${type_search_rx_}")
+    foreach(sym_ ${funcs_})
+      string(REGEX REPLACE "${func_name_rx_}" "\\3" def_ ${sym_})
+      list(APPEND symbols_ ${def_})
     endforeach()
-
-    list(SORT defs_)
-    list(REMOVE_DUPLICATES defs_)
-    file(WRITE ${target_} "EXPORTS\n")
-    foreach(def_ ${defs_})
-      list(FIND blacklist_ "${def_}" skip_)
-      if(skip_ LESS 0)
-        file(APPEND ${target_} "${def_}\n")
-      endif()
+    foreach(sym_ ${types_})
+      string(REGEX REPLACE "${type_name_rx_}" "\\1" def_ ${sym_})
+      list(APPEND symbols_ ${def_})
     endforeach()
-  endif()
-endfunction(SerfWindowsGenDef)
+  endforeach()
+
+  list(SORT symbols_)
+  list(REMOVE_DUPLICATES symbols_)
+  list(JOIN blacklist_ "|" filter_)
+  list(FILTER symbols_ EXCLUDE REGEX "${filter_}")
+  set(${output_} "${symbols_}" PARENT_SCOPE)
+endfunction(SerfFindExports)

Added: serf/trunk/build/SerfMachGenExp.cmake
URL: 
http://svn.apache.org/viewvc/serf/trunk/build/SerfMachGenExp.cmake?rev=1926140&view=auto
==============================================================================
--- serf/trunk/build/SerfMachGenExp.cmake (added)
+++ serf/trunk/build/SerfMachGenExp.cmake Thu Jun  5 04:08:41 2025
@@ -0,0 +1,31 @@
+# ===================================================================
+#   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.
+# ===================================================================
+
+# Generate Serf's .exp file for Mach-O shared libraries.
+
+include(SerfFindExports)
+
+separate_arguments(SERF_EXPORT_BLACKLIST)
+separate_arguments(SERF_EXPORT_HEADERS)
+
+SerfFindExports("${SERF_EXPORT_BLACKLIST}" exports_ ${SERF_EXPORT_HEADERS})
+file(WRITE "${SERF_EXP_FILE}" "# Exported symbols\n")
+foreach(symbol_ ${exports_})
+  file(APPEND "${SERF_EXP_FILE}" "_${symbol_}\n")
+endforeach()

Propchange: serf/trunk/build/SerfMachGenExp.cmake
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: serf/trunk/build/SerfPlatform.cmake
URL: 
http://svn.apache.org/viewvc/serf/trunk/build/SerfPlatform.cmake?rev=1926140&r1=1926139&r2=1926140&view=diff
==============================================================================
--- serf/trunk/build/SerfPlatform.cmake (original)
+++ serf/trunk/build/SerfPlatform.cmake Thu Jun  5 04:08:41 2025
@@ -29,6 +29,7 @@ if(${CMAKE_SYSTEM_NAME} MATCHES  "Darwin
   endif()
 elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
   set(SERF_LINUX TRUE)
+  set(SERF_ELF_TARGET TRUE)
   set(SERF_PLATFORM "Linux")
 elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
   set(SERF_WINDOWS TRUE)

Modified: serf/trunk/build/SerfWindowsGenDef.cmake
URL: 
http://svn.apache.org/viewvc/serf/trunk/build/SerfWindowsGenDef.cmake?rev=1926140&r1=1926139&r2=1926140&view=diff
==============================================================================
--- serf/trunk/build/SerfWindowsGenDef.cmake (original)
+++ serf/trunk/build/SerfWindowsGenDef.cmake Thu Jun  5 04:08:41 2025
@@ -19,8 +19,13 @@
 
 # Generate Serf's .def file for Windows DLLs.
 
-include(SerfWindowsToolkit)
+include(SerfFindExports)
 
-string(REGEX REPLACE " +" ";" SERF_DEF_BLACKLIST "${SERF_DEF_BLACKLIST}")
-string(REGEX REPLACE " +" ";" SERF_DEF_HEADERS "${SERF_DEF_HEADERS}")
-SerfWindowsGenDef("${SERF_DEF_BLACKLIST}" "${SERF_DEF_FILE}" 
${SERF_DEF_HEADERS})
+separate_arguments(SERF_EXPORT_BLACKLIST)
+separate_arguments(SERF_EXPORT_HEADERS)
+
+SerfFindExports("${SERF_EXPORT_BLACKLIST}" exports_ ${SERF_EXPORT_HEADERS})
+file(WRITE "${SERF_DEF_FILE}" "EXPORTS\n")
+foreach(symbol_ ${exports_})
+  file(APPEND "${SERF_DEF_FILE}" "${symbol_}\n")
+endforeach()


Reply via email to