Author: rinrab Date: Thu Aug 8 14:09:04 2024 New Revision: 1919745 URL: http://svn.apache.org/viewvc?rev=1919745&view=rev Log: On the 'cmake' branch: Implement generation of SWIG targets.
For compiling SWIG files, we will use built-in CMake module; UseSWIG. It provides the swig_add_library function that could create a SWIG target. This approach is a bit differ from similar used for gen-win and autoconf build systems, but this is more correct, simpler and it provides more abstraction. The creation of SWIG targets are different a lot from the other executable or library targets and theirs templates have nothing same, so we don't use the other templates for these targets. The SWIG bindings would not success to build yet. * build/generator/gen_cmake.py (get_target_type): Remove handling of the TargetSWIGLib target type since these targets are just libraries and could be compiled without any modifications. (get_target_conditions): Add SVN_ENABLE_SWIG_[LANG] for TargetSWIG and TargetSWIGLib target types. (Generator.write, swig_lang): Setup this variable and pass it to the EZT template. (Generator.write, dependencies loop): Ignore TargetSWIG dependencies, because they don't make sense for CMake. (Generator.write, sources): Little refactoring in the loop that reads sources and add reading of the SWIG sources. (Generator.write, target_type check): Add 'swig' to the list of the target possible types to generate them also. * build/generator/templates/targets.cmake.ezt (swig): Generate swig targets and use swig_add_library function to create a new swig target. * CMakeLists.txt (options): Add options for enabling swig bindings for different languages. (swig): Add finding of SWIG using find_package() and include UseSWIG module if compiling swig bindings for any languages. Modified: subversion/branches/cmake/CMakeLists.txt subversion/branches/cmake/build/generator/gen_cmake.py subversion/branches/cmake/build/generator/templates/targets.cmake.ezt Modified: subversion/branches/cmake/CMakeLists.txt URL: http://svn.apache.org/viewvc/subversion/branches/cmake/CMakeLists.txt?rev=1919745&r1=1919744&r2=1919745&view=diff ============================================================================== --- subversion/branches/cmake/CMakeLists.txt (original) +++ subversion/branches/cmake/CMakeLists.txt Thu Aug 8 14:09:04 2024 @@ -61,6 +61,10 @@ option(SVN_BUILD_PROGRAMS "Build Subvers option(SVN_BUILD_TOOLS "Build Subversion tools" OFF) option(SVN_BUILD_TESTS "Build Subversion test-suite" OFF) +option(SVN_ENABLE_SWIG_PERL "Enable Subversion SWIG bindings for Perl" OFF) +option(SVN_ENABLE_SWIG_PYTHON "Enable Subversion SWIG bindings into Python" OFF) +option(SVN_ENABLE_SWIG_RUBY "Enable Subversion SWIG bindings into Ruby" OFF) + # Enable modules and features option(SVN_ENABLE_RA_LOCAL "Enable Subversion Local Repository Access Library" ON) option(SVN_ENABLE_RA_SERF "Enable Subversion HTTP/WebDAV Protocol Repository Access Library" OFF) @@ -227,6 +231,11 @@ endif() find_package(Python COMPONENTS Interpreter REQUIRED) +if(SVN_ENABLE_SWIG_PERL OR SVN_ENABLE_SWIG_PYTHON OR SVN_ENABLE_SWIG_RUBY) + find_package(SWIG REQUIRED) + include(${SWIG_USE_FILE}) +endif() + function(target_exports target_name) if (WIN32) set(def_file_path "${CMAKE_BINARY_DIR}/${target_name}.def") Modified: subversion/branches/cmake/build/generator/gen_cmake.py URL: http://svn.apache.org/viewvc/subversion/branches/cmake/build/generator/gen_cmake.py?rev=1919745&r1=1919744&r2=1919745&view=diff ============================================================================== --- subversion/branches/cmake/build/generator/gen_cmake.py (original) +++ subversion/branches/cmake/build/generator/gen_cmake.py Thu Aug 8 14:09:04 2024 @@ -38,8 +38,6 @@ def get_target_type(target): return "swig" if isinstance(target, gen_base.TargetSWIGProject): return "swig-project" - if isinstance(target, gen_base.TargetSWIGLib): - return "swig-lib" if isinstance(target, gen_base.TargetLib): return "lib" else: @@ -82,6 +80,10 @@ def get_target_conditions(target): if target.msvc_force_static: enable_condition.append("NOT BUILD_SHARED_LIBS") + if isinstance(target, gen_base.TargetSWIG) or \ + isinstance(target, gen_base.TargetSWIG): + enable_condition.append("SVN_ENABLE_SWIG_" + target.lang.upper()) + return enable_condition class Generator(gen_base.GeneratorBase): @@ -107,6 +109,7 @@ class Generator(gen_base.GeneratorBase): enable_condition = [] enable_condition += get_target_conditions(target) build_type = None + swig_lang = None if isinstance(target, gen_base.TargetScript): # there is nothing to build @@ -119,6 +122,8 @@ class Generator(gen_base.GeneratorBase): build_type = "${SVN_FS_BUILD_TYPE}" elif isinstance(target, gen_base.TargetApacheMod): pass + elif isinstance(target, gen_base.TargetSWIG): + swig_lang = target.lang elif isinstance(target, gen_base.TargetLib): if target.msvc_static: build_type = "STATIC" @@ -134,7 +139,10 @@ class Generator(gen_base.GeneratorBase): for dep in self.get_dependecies(target.name): enable_condition += get_target_conditions(dep) - if isinstance(dep, gen_base.TargetLinked): + if isinstance(dep, gen_base.TargetSWIG): + # Just ignore them + pass + elif isinstance(dep, gen_base.TargetLinked): if dep.external_lib: if dep.name == "ra-libs": libs.append("ra-libs") @@ -154,15 +162,19 @@ class Generator(gen_base.GeneratorBase): else: libs.append(dep.name) elif isinstance(dep, gen_base.ObjectFile): - deps = self.graph.get_sources(gen_base.DT_OBJECT, - dep, - gen_base.SourceFile) - for dep in deps: - sources.append(dep.filename) + for source in self.graph.get_sources(gen_base.DT_OBJECT, dep, + gen_base.SourceFile): + sources.append(source.filename) + + for obj in self.graph.get_sources(gen_base.DT_OBJECT, dep, + gen_base.ObjectFile): + for source in self.graph.get_sources(gen_base.DT_SWIG_C, obj, + gen_base.SWIGSource): + sources.append(source.filename) target_type = get_target_type(target) - if target_type in ["exe", "lib", "test"]: + if target_type in ["exe", "lib", "test", "swig"]: msvc_libs = [] msvc_objects = [] @@ -198,6 +210,7 @@ class Generator(gen_base.GeneratorBase): description = target.desc, srcdir = target.path, install_target = ezt.boolean(install_target), + swig_lang = swig_lang, ) targets.append(new_target) Modified: subversion/branches/cmake/build/generator/templates/targets.cmake.ezt URL: http://svn.apache.org/viewvc/subversion/branches/cmake/build/generator/templates/targets.cmake.ezt?rev=1919745&r1=1919744&r2=1919745&view=diff ============================================================================== --- subversion/branches/cmake/build/generator/templates/targets.cmake.ezt (original) +++ subversion/branches/cmake/build/generator/templates/targets.cmake.ezt Thu Aug 8 14:09:04 2024 @@ -21,7 +21,11 @@ # [for targets] # [if-any targets.description][targets.description][else][targets.name][end] -if ([targets.enable_condition])[is targets.type "lib"] +if ([targets.enable_condition])[is targets.type "swig"] + swig_add_library([targets.name] + LANGUAGE [targets.swig_lang] + SOURCES[for targets.sources] [targets.sources][end] + )[else][is targets.type "lib"] add_library([targets.name][if-any targets.build_type] [targets.build_type][end][for targets.sources] [targets.sources][end] )[if-any targets.msvc_export] @@ -58,6 +62,6 @@ if ([targets.enable_condition])[is targe if (WIN32) target_sources([targets.name] PRIVATE build/win32/svn.rc) endif()[if-any targets.install_target] - install(TARGETS [targets.name])[end] + install(TARGETS [targets.name])[end][end] endif() [end]