Author: rinrab
Date: Fri Jun 28 13:28:56 2024
New Revision: 1918731

URL: http://svn.apache.org/viewvc?rev=1918731&view=rev
Log:
On the 'cmake' branch: Generate custom objects and libraries to link.

In build.conf, there is a field, called msvc-libs. It contains additional
`*.lib` and `*.obj` files to link on Windows platform. The built-in CMake
function `target_link_libraries` supports only CMake targets or `*.lib`
files, but objects doesn't work. For them the only resolution is to add
these objects to link flags. Additionally, setargv.obj doesn't work on
non-MSVC compilers, so using `if (MSVC)`.

* build/generator/gen_cmake.py
  (cmake_target): Add msvc_libs and msvc_objects fields and create boolean
   fields has_msvc_libs and has_msvc_objects based on existing of above.

  (Generator.write): Read msvc_libs and msvc_objects from target.msvc_libs,
   then pass them to cmake_target constructor with a little rework of this
   code.

* build/generator/templates/CMakeLists.txt.ezt
  (): Generate linking with these objects and libraries.

Modified:
    subversion/branches/cmake/build/generator/gen_cmake.py
    subversion/branches/cmake/build/generator/templates/CMakeLists.txt.ezt

Modified: subversion/branches/cmake/build/generator/gen_cmake.py
URL: 
http://svn.apache.org/viewvc/subversion/branches/cmake/build/generator/gen_cmake.py?rev=1918731&r1=1918730&r2=1918731&view=diff
==============================================================================
--- subversion/branches/cmake/build/generator/gen_cmake.py (original)
+++ subversion/branches/cmake/build/generator/gen_cmake.py Fri Jun 28 13:28:56 
2024
@@ -8,12 +8,18 @@ class _eztdata(object):
     vars(self).update(kw)
 
 class cmake_target():
-  def __init__(self, name: str, type: str, sources, libs):
+  def __init__(self, name: str, type: str, sources, libs, msvc_libs, 
msvc_objects):
     self.name = name
     self.type = type
     self.sources = sources
     self.libs = libs
 
+    self.msvc_libs = msvc_libs
+    self.msvc_objects = msvc_objects
+
+    self.has_msvc_libs = ezt.boolean(len(msvc_libs) > 0)
+    self.has_msvc_objects = ezt.boolean(len(msvc_objects) > 0)
+
 def get_target_type(target: gen_base.Target):
   if isinstance(target, gen_base.TargetExe):
     if target.install == "test" and target.testing != "skip":
@@ -106,14 +112,25 @@ class Generator(gen_base.GeneratorBase):
 
       target_type = get_target_type(target)
 
-      target = cmake_target(
-        name = target.name,
-        type = target_type,
-        sources = sources,
-        libs = libs
-      )
-
       if target_type in ["exe", "lib"]:
+        msvc_libs = []
+        msvc_objects = []
+
+        for lib in target.msvc_libs:
+          if lib.endswith(".obj"):
+            msvc_objects.append(lib)
+          else:
+            msvc_libs.append(lib)
+
+        target = cmake_target(
+          name = target.name,
+          type = target_type,
+          sources = sources,
+          libs = libs,
+          msvc_libs = msvc_libs,
+          msvc_objects = msvc_objects,
+        )
+
         targets.append(target)
 
     data = _eztdata(

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=1918731&r1=1918730&r2=1918731&view=diff
==============================================================================
--- subversion/branches/cmake/build/generator/templates/CMakeLists.txt.ezt 
(original)
+++ subversion/branches/cmake/build/generator/templates/CMakeLists.txt.ezt Fri 
Jun 28 13:28:56 2024
@@ -29,7 +29,13 @@ target_include_directories([targets.name
 add_executable([targets.name][for targets.sources]
   [targets.sources][end]
 )
-[end]target_link_libraries([targets.name][for targets.libs]
+[end]target_link_libraries([targets.name] PRIVATE[for targets.libs]
   [targets.libs][end]
-)
+)[if-any targets.has_msvc_libs]
+if (WIN32)
+  target_link_libraries([targets.name] PRIVATE[for targets.msvc_libs] 
[targets.msvc_libs][end])
+endif()[end][if-any targets.has_msvc_objects]
+if (MSVC)
+  set_target_properties([targets.name] PROPERTIES LINK_FLAGS[for 
targets.msvc_objects] [targets.msvc_objects][end])
+endif()[end]
 [end]


Reply via email to