преобразование waf в CMake застряло - PullRequest
0 голосов
/ 01 ноября 2018

пытается сделать ns-3 cmake совместимым. Тем не мение. при попытке настроить привязки Python, я не могу. Может кто-нибудь попытаться помочь мне разобраться в чем дело? Я пытаюсь заставить работать модуль визуализатора, чего нельзя сделать, пока не будут выполнены все привязки python. Код будет скомпилирован правильно, однако при выполнении модуля визуализатора возникает фатальная ошибка. Даже если у вас есть какие-либо советы или предложения, с чего начать, это будет очень полезно!

WScript

def ns3_python_bindings(bld):

# this method is called from a module wscript, so remember bld.path is not bindings/python!
module_abs_src_path = bld.path.abspath()
module = os.path.basename(module_abs_src_path)
env = bld.env
env.append_value("MODULAR_BINDINGS_MODULES", "ns3-"+module)

if Options.options.apiscan:
    return

if not env['ENABLE_PYTHON_BINDINGS']:
    return

bindings_dir = bld.path.find_dir("bindings")
if bindings_dir is None or not os.path.exists(bindings_dir.abspath()):
    warnings.warn("(in %s) Requested to build modular python bindings, but apidefs dir not found "
                  "=> skipped the bindings." % str(bld.path),
                  Warning, stacklevel=2)
    return

if ("ns3-%s" % (module,)) not in env.NS3_ENABLED_MODULES:
    #print "bindings for module %s which is not enabled, skip" % module
    return

env.append_value('PYTHON_MODULES_BUILT', module)
try:
    apidefs = env['PYTHON_BINDINGS_APIDEFS'].replace("-", "_")
except AttributeError:
    # we likely got an empty list for env['PYTHON_BINDINGS_APIDEFS']
    return

#debug = ('PYBINDGEN_DEBUG' in os.environ)
debug = True # XXX
source = [bld.srcnode.find_resource('bindings/python/ns3modulegen-modular.py'),
          bld.path.find_resource("bindings/modulegen__%s.py" % apidefs)]

modulegen_customizations = bindings_dir.find_resource("modulegen_customizations.py")
if modulegen_customizations is not None:
    source.append(modulegen_customizations)

modulegen_local = bld.path.find_resource("bindings/modulegen_local.py")
# the local customization file may or not exist
if modulegen_local is not None:
    source.append("bindings/modulegen_local.py")

module_py_name = module.replace('-', '_')
module_target_dir = bld.srcnode.find_dir("bindings/python/ns").path_from(bld.path)

# if bindings/<module>.py exists, it becomes the module frontend, and the C extension befomes _<module>
if bld.path.find_resource("bindings/%s.py" % (module_py_name,)) is not None:
    bld(features='copy',
        source=("bindings/%s.py" % (module_py_name,)),
        target=('%s/%s.py' % (module_target_dir, module_py_name)))
    extension_name = '_%s' % (module_py_name,)
    bld.install_files('${PYTHONARCHDIR}/ns', ["bindings/%s.py" % (module_py_name,)])
else:
    extension_name = module_py_name

target = ['bindings/ns3module.cc', 'bindings/ns3module.h', 'bindings/ns3modulegen.log']
#if not debug:
#    target.append('ns3modulegen.log')

argv = ['NS3_ENABLED_FEATURES=${FEATURES}',
        'GCC_RTTI_ABI_COMPLETE=${GCC_RTTI_ABI_COMPLETE}',
        '${PYTHON}']
#if debug:
#    argv.extend(["-m", "pdb"])

argv.extend(['${SRC[0]}', module_abs_src_path, apidefs, extension_name, '${TGT[0]}'])

argv.extend(['2>', '${TGT[2]}']) # 2> ns3modulegen.log

features = []
for (name, caption, was_enabled, reason_not_enabled) in env['NS3_OPTIONAL_FEATURES']:
    if was_enabled:
        features.append(name)

bindgen = bld(features='command', source=source, target=target, command=argv)
bindgen.env['FEATURES'] = ','.join(features)
bindgen.dep_vars = ['FEATURES', "GCC_RTTI_ABI_COMPLETE"]
bindgen.before = 'cxx'
bindgen.after = 'gen_ns3_module_header'
bindgen.name = "pybindgen(ns3 module %s)" % module
bindgen.install_path = None

# generate the extension module
pymod = bld(features='cxx cxxshlib pyext')
pymod.source = ['bindings/ns3module.cc']
pymod.target = '%s/%s' % (module_target_dir, extension_name)
pymod.name = 'ns3module_%s' % module
pymod.use = ["%s" % mod for mod in pymod.env['NS3_ENABLED_MODULES']] #  Should be '"ns3-"+module', but see bug 1117
if pymod.env['ENABLE_STATIC_NS3']:
    if sys.platform == 'darwin':
        pymod.env.append_value('LINKFLAGS', '-Wl,-all_load')
        for mod in pymod.usel:
            #mod = mod.split("--lib")[0]
            pymod.env.append_value('LINKFLAGS', '-l' + mod)
    else:
        pymod.env.append_value('LINKFLAGS', '-Wl,--whole-archive,-Bstatic')
        for mod in pymod.use:
            #mod = mod.split("--lib")[0]
            pymod.env.append_value('LINKFLAGS', '-l' + mod)
        pymod.env.append_value('LINKFLAGS', '-Wl,-Bdynamic,--no-whole-archive')
defines = list(pymod.env['DEFINES'])
defines.extend(['NS_DEPRECATED=', 'NS3_DEPRECATED_H'])
if Utils.unversioned_sys_platform()== 'win32':
    try:
        defines.remove('_DEBUG') # causes undefined symbols on win32
    except ValueError:
        pass
pymod.env['DEFINES'] = defines
pymod.includes = '# bindings'
pymod.install_path = '${PYTHONARCHDIR}/ns'

# Workaround to a WAF bug, remove this when ns-3 upgrades to WAF > 1.6.10
# https://www.nsnam.org/bugzilla/show_bug.cgi?id=1335
# http://code.google.com/p/waf/issues/detail?id=1098
if Utils.unversioned_sys_platform() == 'darwin':
    pymod.mac_bundle = True

return pymod

CMake

if(${NS3_PYTHON})
    set(arch gcc_ILP32)

    FIND_PACKAGE(PythonLibs REQUIRED)
    FIND_PACKAGE(PythonInterp REQUIRED)
    IF(NOT PYTHONLIBS_FOUND OR NOT PYTHON_EXECUTABLE)
        MESSAGE(SEND_ERROR "You need Python to build Python binding")
    ENDIF(NOT PYTHONLIBS_FOUND OR NOT PYTHON_EXECUTABLE)

    message(STATUS "BUILDING PYTHON BINDINGS")
    add_custom_command(
            OUTPUT
            ${PROJECT_SOURCE_DIR}/src/${libname}/bindings/modulegen_${arch}.py
            COMMAND
            ${PROJECT_SOURCE_DIR}/bindings/python/ns3modulegen-modular.py
            ${PROJECT_SOURCE_DIR}/src/${libname}/bindings/
            ${PROJECT_SOURCE_DIR}/src/${libname}/
            ${CMAKE_HEADER_OUTPUT_DIRECTORY}/${libname}-module.h
            modulegen_${arch}.py
            ${CMAKE_CXX_FLAGS}
            )
endif()
...