Author: rinrab
Date: Tue Jul 2 14:48:06 2024
New Revision: 1918852
URL: http://svn.apache.org/viewvc?rev=1918852&view=rev
Log:
On the 'cmake' branch: Generate *.def files for libraries to support
using shared DLLs on Windows.
When compiling shared library for Windows, it is required to generate
file with a list of what the DLL export from itself and let the compiler
create a *.lib file based on this list.
For extracting the library exports, there is already a python script,
named extractor.py. This commit adds a simple CMake wrapper for this
script for using it simply. Also, there is a field in the build.conf
file with the list of the headers to export from the library. This list
of headers in passed to the target_exports CMake function and then directly
to the extractor.py script to generate the *.def file.
After that, the generated *.def files are being passed to CMake target via
target_sources() command. This command is invocated from the target_exports
to make the usage simpler.
In addition, these *.def and *.lib are required only for Windows, because
on Linux there is a different system with shared libraries and definitions
are generated automatically.
About the function name: the decision to name the function for setting up
the exports of the target was done to keep the CMake command naming style.
In CMake, there are commands named like target_include_directories,
target_sources, target_link_libraries, so the function can be named in this
style as target_exports. Now the generated CMakeLists.txt file looks very
nice due to a list of simple commands and file sources. Also this naming
abstraction allows to move the `if (WIN32)` check to this function.
* build/cmake/extractor.cmake: New file.
(target_exports): New function.
* build/generator/gen_cmake.py
(cmake_target): Add the msvc_export field.
(Generator.write): Pass the msvc_export files to the ezt template.
* build/generator/templates/CMakeLists.txt.ezt
(): Include the `extractor.cmake` file to import the run_extractor function.
(targets loop): Generate run_extractor invocation for each library.
Added:
subversion/branches/cmake/build/cmake/extractor.cmake
Modified:
subversion/branches/cmake/build/generator/gen_cmake.py
subversion/branches/cmake/build/generator/templates/CMakeLists.txt.ezt
Added: subversion/branches/cmake/build/cmake/extractor.cmake
URL:
http://svn.apache.org/viewvc/subversion/branches/cmake/build/cmake/extractor.cmake?rev=1918852&view=auto
==============================================================================
--- subversion/branches/cmake/build/cmake/extractor.cmake (added)
+++ subversion/branches/cmake/build/cmake/extractor.cmake Tue Jul 2 14:48:06
2024
@@ -0,0 +1,25 @@
+find_package(Python COMPONENTS Interpreter REQUIRED)
+
+function(target_exports target_name msvc_export)
+ if (WIN32)
+ set(def_file_path "${CMAKE_BINARY_DIR}/${target_name}.def")
+
+ add_custom_command(
+ WORKING_DIRECTORY
+ "${CMAKE_SOURCE_DIR}"
+ COMMAND
+ "${Python_EXECUTABLE}"
+ ARGS
+ "build/generator/extractor.py"
+ ${msvc_exports}
+ ">${def_file_path}"
+ OUTPUT
+ "${def_file_path}"
+ DEPENDS
+ "build/generator/extractor.py"
+ ${msvc_exports}
+ )
+
+ target_sources("${target_name}" PRIVATE "${def_file_path}")
+ endif()
+endfunction()
Modified: subversion/branches/cmake/build/generator/gen_cmake.py
URL:
http://svn.apache.org/viewvc/subversion/branches/cmake/build/generator/gen_cmake.py?rev=1918852&r1=1918851&r2=1918852&view=diff
==============================================================================
--- subversion/branches/cmake/build/generator/gen_cmake.py (original)
+++ subversion/branches/cmake/build/generator/gen_cmake.py Tue Jul 2 14:48:06
2024
@@ -30,7 +30,7 @@ class _eztdata(object):
class cmake_target():
def __init__(self, name: str, type: str, sources,
- libs, msvc_libs, msvc_objects,
+ libs, msvc_libs, msvc_objects, msvc_export,
enable_condition: str, group: str):
self.name = name
self.type = type
@@ -39,6 +39,7 @@ class cmake_target():
self.msvc_libs = msvc_libs
self.msvc_objects = msvc_objects
+ self.msvc_export = msvc_export
self.enable_condition = enable_condition
self.group = group
@@ -99,6 +100,7 @@ class Generator(gen_base.GeneratorBase):
target: gen_base.Target
group = None
enable_condition = "TRUE"
+ msvc_export = []
if isinstance(target, gen_base.TargetScript):
# there is nothing to build
@@ -119,7 +121,9 @@ class Generator(gen_base.GeneratorBase):
elif isinstance(target, gen_base.TargetApacheMod):
pass
elif isinstance(target, gen_base.TargetLib):
- pass
+ for export in target.msvc_export:
+ path = "subversion/include/" + export.replace("\\", "/")
+ msvc_export.append(path)
sources = []
libs = []
@@ -171,6 +175,7 @@ class Generator(gen_base.GeneratorBase):
libs = libs,
msvc_libs = msvc_libs,
msvc_objects = msvc_objects,
+ msvc_export = msvc_export,
enable_condition = enable_condition,
group = group
)
Modified: subversion/branches/cmake/build/generator/templates/CMakeLists.txt.ezt
URL:
http://svn.apache.org/viewvc/subversion/branches/cmake/build/generator/templates/CMakeLists.txt.ezt?rev=1918852&r1=1918851&r2=1918852&view=diff
==============================================================================
--- subversion/branches/cmake/build/generator/templates/CMakeLists.txt.ezt
(original)
+++ subversion/branches/cmake/build/generator/templates/CMakeLists.txt.ezt Tue
Jul 2 14:48:06 2024
@@ -28,6 +28,8 @@ include("build/cmake/dependencies.cmake"
include("build/cmake/options.cmake")
+include("build/cmake/extractor.cmake")
+
set(SVN_INCLUDE_DIRECTORIES
"${CMAKE_CURRENT_SOURCE_DIR}/subversion/include"
"${CMAKE_CURRENT_BINARY_DIR}"
@@ -43,7 +45,10 @@ endif()
if ([targets.enable_condition])[is targets.type "lib"]
add_library([targets.name][for targets.sources]
[targets.sources][end]
- )
+ )[if-any targets.msvc_export]
+ target_exports([targets.name][for targets.msvc_export]
+ [targets.msvc_export][end]
+ )[end]
target_include_directories([targets.name] PUBLIC
${SVN_INCLUDE_DIRECTORIES})[if-any targets.group]
list(APPEND [targets.group] [targets.name])[end]
[end][is targets.type "exe"]