Пример #1
0
def setup_application(options, name, ordered):
    contents = []
    path = os.path.join("applications", name)
    local = os.path.join(path, "Setup.cmake")
    if os.path.exists(local):
        contents.append("include(%s)" % tools.to_cmake_path(local))

    values = {"name": name}
    values["NAME"] = name.upper()
    data = tools.get_application_description(".", name, "")
    all_modules = data["required_modules"] + tools.get_all_modules(
        ".", data["required_modules"], "", ordered)
    all_dependencies = tools.get_all_dependencies(
        ".", all_modules, "", ordered) + data["required_dependencies"]
    modules = ["${IMP_%s_LIBRARY}" % s for s in all_modules]
    dependencies = ["${%s_LIBRARIES}" % s.upper() for s in all_dependencies]
    values["modules"] = "\n".join(modules)
    values["tags"] = "\n".join(["${IMP_%s_DOC}" % m for m in all_modules])
    values["dependencies"] = "\n".join(dependencies)
    values["module_deps"] = "\n".join("${IMP_%s}" % m for m in all_modules)
    exes = tools.get_application_executables(path)
    exedirs = sorted(set(sum([x[1] for x in exes], [])))
    localincludes = "\n     ".join(
        ["${CMAKE_SOURCE_DIR}/" + tools.to_cmake_path(x) for x in exedirs])
    bintmpl = """
   add_executable("IMP.%(name)s-%(cname)s" %(cpps)s)
   target_link_libraries(IMP.%(name)s-%(cname)s
    %(modules)s
    %(dependencies)s)
   set_target_properties(IMP.%(name)s-%(cname)s PROPERTIES OUTPUT_NAME %(cname)s RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
   set_property(TARGET "IMP.%(name)s-%(cname)s" PROPERTY FOLDER "IMP.%(name)s")
   install(TARGETS IMP.%(name)s-%(cname)s DESTINATION ${CMAKE_INSTALL_BINDIR})
   set(bins ${bins} IMP.%(name)s-%(cname)s)
"""
    bins = []
    for e in exes:
        cpps = e[0]
        cname = os.path.splitext(os.path.split(cpps[0])[1])[0]
        values["cname"] = cname
        values["cpps"] = "\n".join(
            ["${CMAKE_SOURCE_DIR}/%s" % tools.to_cmake_path(c) for c in cpps])
        bins.append(bintmpl % values)
    values["bins"] = "\n".join(bins)
    values["includepath"] = get_dep_merged(all_modules, "include_path",
                                           ordered) + " " + localincludes
    values["libpath"] = get_dep_merged(all_modules, "link_path", ordered)
    values["swigpath"] = get_dep_merged(all_modules, "swig_path", ordered)
    pybins = get_app_sources(path, ["*"], tools.filter_pyapps)
    values["pybins"] = "\n".join(pybins)
    cppbins = [os.path.splitext(e[0][0])[0] for e in exes]
    values["bin_names"] = "\n".join([os.path.basename(x) \
                                     for x in pybins + cppbins])
    values["pytests"] = "\n".join(
        get_app_sources(os.path.join(path, "test"),
                        ["test_*.py", "expensive_test_*.py"]))
    contents.append(application_template % values)
    out = os.path.join(path, "CMakeLists.txt")
    tools.rewrite(out, "\n".join(contents))
    return out
Пример #2
0
def setup_application(options, name, ordered):
    contents = []
    path = os.path.join("applications", name)
    local = os.path.join(path, "Setup.cmake")
    if os.path.exists(local):
        contents.append("include(%s)" % tools.to_cmake_path(local))

    values = {"name": name}
    values["NAME"] = name.upper()
    data = tools.get_application_description(".", name, "")
    all_modules = data["required_modules"] + tools.get_all_modules(".", data["required_modules"], "", ordered)
    all_dependencies = tools.get_all_dependencies(".", all_modules, "", ordered)
    modules = ["${IMP_%s_LIBRARY}" % s for s in all_modules]
    dependencies = ["${%s_LIBRARIES}" % s.upper() for s in all_dependencies]
    values["modules"] = "\n".join(modules)
    values["tags"] = "\n".join(["${IMP_%s_DOC}" % m for m in all_modules])
    values["dependencies"] = "\n".join(dependencies)
    values["module_deps"] = "\n".join("${IMP_%s}" % m for m in all_modules)
    exes = tools.get_application_executables(path)
    exedirs = list(set(sum([x[1] for x in exes], [])))
    exedirs.sort()
    localincludes = "\n     ".join(["${CMAKE_SOURCE_DIR}/" + tools.to_cmake_path(x) for x in exedirs])
    bintmpl = """
   add_executable("IMP.%(name)s-%(cname)s" %(cpps)s)
   target_link_libraries(IMP.%(name)s-%(cname)s
    %(modules)s
    %(dependencies)s)
   set_target_properties(IMP.%(name)s-%(cname)s PROPERTIES OUTPUT_NAME %(cname)s RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
   set_property(TARGET "IMP.%(name)s-%(cname)s" PROPERTY FOLDER "IMP.%(name)s")
   install(TARGETS IMP.%(name)s-%(cname)s DESTINATION ${CMAKE_INSTALL_BINDIR})
   set(bins ${bins} IMP.%(name)s-%(cname)s)
"""
    bins = []
    for e in exes:
        cpps = e[0]
        cname = os.path.splitext(os.path.split(cpps[0])[1])[0]
        values["cname"] = cname
        values["cpps"] = "\n".join(["${CMAKE_SOURCE_DIR}/%s" % tools.to_cmake_path(c) for c in cpps])
        bins.append(bintmpl % values)
    values["bins"] = "\n".join(bins)
    values["includepath"] = get_dep_merged(all_modules, "include_path", ordered) + " " + localincludes
    values["libpath"] = get_dep_merged(all_modules, "link_path", ordered)
    values["swigpath"] = get_dep_merged(all_modules, "swig_path", ordered)
    values["pybins"] = get_app_sources(path, ["*.py"])
    values["pytests"] = get_app_sources(os.path.join(path, "test"), ["test_*.py", "expensive_test_*.py"])
    contents.append(application_template % values)
    out = os.path.join(path, "CMakeLists.txt")
    tools.rewrite(out, "\n".join(contents))
    return out
Пример #3
0
def get_sources(module, path, subdir, pattern):
    matching = tools.get_glob([
        os.path.join(path, subdir, pattern),
        os.path.join(path, subdir, "*", pattern)
    ])
    return "\n".join(
        ["${CMAKE_SOURCE_DIR}/%s" % tools.to_cmake_path(x) for x in matching])
Пример #4
0
def get_sources(module, path, subdir, pattern):
    matching = tools.get_glob([
        os.path.join(path, subdir, pattern),
        os.path.join(path, subdir, "*", pattern)
    ])
    return "\n".join(
        ["${CMAKE_SOURCE_DIR}/%s" % tools.to_cmake_path(x) for x in matching])
Пример #5
0
 def get_files(module, suffix, prefix, allh):
     ret = []
     for h in allh:
         if h.endswith(suffix) and os.path.split(os.path.split(h)[0])[1] == module:
             fname = prefix + os.path.split(h)[1]
             ret.append(tools.to_cmake_path(fname))
     return ret
Пример #6
0
 def get_files(module, suffix, prefix, allh):
     ret = []
     for h in allh:
         if h.endswith(suffix) and os.path.split(
                 os.path.split(h)[0])[1] == module:
             fname = prefix + os.path.split(h)[1]
             ret.append(tools.to_cmake_path(fname))
     return ret
Пример #7
0
def make_one(path, params, test=True):
    (function_name, type_name, class_name, variable_type, argument_type,
     return_type, storage_type, plural_variable_type, plural_argument_type,
     plural_storage_type, index_type, plural_index_type,
     pass_index_type) = params
    multi = class_name
    plural_multi = multi + "s"
    cname = function_name

    inputs = tools.get_glob([
        os.path.join(path, "*", "*.h"),
        os.path.join(path, "*", "internal", "*.h"),
        os.path.join(path, "*", "*.cpp"),
        os.path.join(path, "*", "internal", "*.cpp")
    ])
    files = []
    for ip in inputs:
        p = ip[len(path) + 1:]
        module = os.path.split(p)[0]
        rest = os.path.split(p)[1]
        if module.find("internal") != -1:
            module = os.path.split(module)[0]
            rest = os.path.join("internal", rest)
        name = filter(params, rest, rest)
        if p.endswith(".h"):
            out_path = os.path.join("include", "IMP",
                                    '' if module == 'kernel' else module, name)
        else:
            out_path = os.path.join("src", module, name)
        files.append((out_path, ip))

    if test:
        files.append(("test/container/test_" + cname + "_restraint.py",
                      path + "/test.py"))
        files.append(("test/container/test_" + cname + "_state.py",
                      path + "/test_state.py"))
    for p in files:
        g = ContainerFileGenerator(p[1])
        g.write(p[0], params)
        all_outputs.append(tools.to_cmake_path(p[0]))
        all_inputs.append(tools.to_cmake_path(p[1]))
Пример #8
0
def make_one(path, params, test=True):
    (function_name, type_name, class_name, variable_type, argument_type, return_type,
     storage_type,
     plural_variable_type, plural_argument_type, plural_storage_type,
     index_type, plural_index_type, pass_index_type) = params
    multi = class_name
    plural_multi = multi + "s"
    cname = function_name

    inputs = tools.get_glob([os.path.join(path, "*", "*.h"),
                            os.path.join(path, "*", "internal", "*.h"),
                            os.path.join(path, "*", "*.cpp"),
                            os.path.join(path, "*", "internal", "*.cpp")])
    files = []
    for ip in inputs:
        p = ip[len(path) + 1:]
        module = os.path.split(p)[0]
        rest = os.path.split(p)[1]
        if module.find("internal") != -1:
            module = os.path.split(module)[0]
            rest = os.path.join("internal", rest)
        name = filter(params, rest, rest)
        if p.endswith(".h"):
            out_path = os.path.join("include", "IMP",
                                    '' if module == 'kernel' else module, name)
        else:
            out_path = os.path.join("src", module, name)
        files.append((out_path, ip))

    if test:
        files.append(("test/container/test_" + cname + "_restraint.py",
                      path + "/test.py"))
        files.append(("test/container/test_" + cname + "_state.py",
                      path + "/test_state.py"))
    for p in files:
        g = ContainerFileGenerator(p[1])
        g.write(p[0], params)
        all_outputs.append(tools.to_cmake_path(p[0]))
        all_inputs.append(tools.to_cmake_path(p[1]))
Пример #9
0
def setup_module(module, path, ordered):
    checks = []
    deps = []
    contents = []
    defines = []
    for cc in tools.get_glob([os.path.join(path, "compiler", "*.cpp")]):
        ret = make_check(cc, module, path)
        checks.append(ret[0])
        defines.append(ret[1])
    for cc in tools.get_glob([os.path.join(path, "dependency", "*.description")]):
        ret = make_dependency_check(cc, module, path)
        if ret:
            deps.append(ret)

    g = tools.CMakeFileGenerator()
    if len(checks) > 0:
        g.write("modules/%s/compiler/CMakeLists.txt" % module,
                "\n".join(["include(${CMAKE_SOURCE_DIR}/%s)\n" %
                               tools.to_cmake_path(x) for x in checks]))
        contents.append(
            "add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/compiler)" %
            module)
    if len(deps) > 0:
        g.write("modules/%s/dependency/CMakeLists.txt" % module,
                "\n".join(["include(${CMAKE_SOURCE_DIR}/%s)" %
                               tools.to_cmake_path(x) for x in deps]))
        contents.append(
            "add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/dependency)" %
            module)
    local = os.path.join(path, "Setup.cmake")
    if os.path.exists(local):
        contents.append("include(${CMAKE_SOURCE_DIR}/%s)"
                        % tools.to_cmake_path(local))

    values = {"name": module}
    if module == 'kernel':
        values['subdir'] = 'IMP'
        values['pymod'] = 'IMP'
        values['allh_header'] = 'IMP.h'
    else:
        values['subdir'] = 'IMP/' + module
        values['pymod'] = 'IMP.' + module
        values['allh_header'] = 'IMP/%s.h' % module
    values["NAME"] = module.upper()
    values["CPPNAME"] = module.upper().replace('_', '')
    data = tools.get_module_description(".", module, "")
    all_modules = tools.get_all_modules(".", [module], "", ordered)
    modules = ["${IMP_%s_LIBRARY}" % s for s in all_modules]
    dependencies = ["${%s_LIBRARIES}" % s.upper()
                    for s in tools.get_all_dependencies(".", [module], "", ordered)]
    values["modules"] = ";".join(modules)
    values["tags"] = "\n".join(["${IMP_%s_DOC}" % m for m in all_modules])
    values["other_pythons"] = "\n".join(
        ["${IMP_%s_PYTHON}" %
         m for m in all_modules])
    values["dependencies"] = ";".join(dependencies)
    values["headers"] = get_sources(module, path, "include", "*.h")
    values["includepath"] = get_dep_merged([module], "include_path", ordered)
    values["libpath"] = get_dep_merged([module], "link_path", ordered)
    values["swigpath"] = get_dep_merged([module], "swig_path", ordered)
    values["defines"] = ":".join(defines)
    cppbins = tools.get_glob([os.path.join(path, "bin", "*.cpp")])
    cppbins = [os.path.splitext(e)[0] for e in cppbins]
    pybins = get_app_sources(os.path.join(path, "bin"), ["*"],
                             tools.filter_pyapps)
    values["pybins"] = "\n".join(pybins)
    values["bin_names"] = "\n".join([os.path.basename(x) \
                                     for x in pybins + cppbins])
    main = os.path.join(path, "src", "CMakeLists.txt")
    tests = os.path.join(path, "test", "CMakeLists.txt")
    swig = os.path.join(path, "pyext", "CMakeLists.txt")
    util = os.path.join(path, "utility", "CMakeLists.txt")
    bin = os.path.join(path, "bin", "CMakeLists.txt")
    benchmark = os.path.join(path, "benchmark", "CMakeLists.txt")
    examples = os.path.join(path, "examples", "CMakeLists.txt")
    lib_template.write(main, values)
    test_template.write(tests, values)
    swig_template.write(swig, values)
    util_template.write(util, values)
    bin_template.write(bin, values)
    benchmark_template.write(benchmark, values)
    examples_template.write(examples, values)
    values["tests"] = "\n".join(contents)
    values["subdirs"] = """add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/src)
add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/test)
add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/examples)
add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/benchmark)
add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/bin)
add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/utility)""" % ((module,) * 6)

    out = os.path.join(path, "CMakeLists.txt")
    module_template.write(out, values)

    # at end so directories exist
    cmd = subprocess.Popen(
        ["python",
         os.path.join(
             "..",
             "..",
             "tools",
             "dev_tools",
             "setup_cmake.py")],
        cwd=path, universal_newlines=True)

    return out
Пример #10
0
def get_app_sources(path, patterns, filt=lambda x:True):
    matching = tools.get_glob([os.path.join(path, x) for x in patterns])
    return ["${CMAKE_SOURCE_DIR}/%s" % tools.to_cmake_path(x) \
            for x in matching if filt(x)]
Пример #11
0
def setup_module(module, path, ordered):
    checks = []
    deps = []
    contents = []
    defines = []
    for cc in tools.get_glob([os.path.join(path, "compiler", "*.cpp")]):
        ret = make_check(cc, module, path)
        checks.append(ret[0])
        defines.append(ret[1])
    for cc in tools.get_glob(
        [os.path.join(path, "dependency", "*.description")]):
        ret = make_dependency_check(cc, module, path)
        if ret:
            deps.append(ret)

    if len(checks) > 0:
        tools.rewrite(
            "modules/%s/compiler/CMakeLists.txt" % module, "\n".join([
                "include(${CMAKE_SOURCE_DIR}/%s)\n" % tools.to_cmake_path(x)
                for x in checks
            ]))
        contents.append(
            "add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/compiler)" %
            module)
    if len(deps) > 0:
        tools.rewrite(
            "modules/%s/dependency/CMakeLists.txt" % module, "\n".join([
                "include(${CMAKE_SOURCE_DIR}/%s)" % tools.to_cmake_path(x)
                for x in deps
            ]))
        contents.append(
            "add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/dependency)" %
            module)
    local = os.path.join(path, "Setup.cmake")
    if os.path.exists(local):
        contents.append("include(${CMAKE_SOURCE_DIR}/%s)" %
                        tools.to_cmake_path(local))

    values = {"name": module}
    values["NAME"] = module.upper()
    values["CPPNAME"] = module.upper().replace('_', '')
    data = tools.get_module_description(".", module, "")
    all_modules = tools.get_all_modules(".", [module], "", ordered)
    modules = ["${IMP_%s_LIBRARY}" % s for s in all_modules]
    dependencies = [
        "${%s_LIBRARIES}" % s.upper()
        for s in tools.get_all_dependencies(".", [module], "", ordered)
    ]
    values["modules"] = ";".join(modules)
    values["tags"] = "\n".join(["${IMP_%s_DOC}" % m for m in all_modules])
    values["other_pythons"] = "\n".join(
        ["${IMP_%s_PYTHON}" % m for m in all_modules])
    values["dependencies"] = ";".join(dependencies)
    values["headers"] = get_sources(module, path, "include", "*.h")
    values["includepath"] = get_dep_merged([module], "include_path", ordered)
    values["libpath"] = get_dep_merged([module], "link_path", ordered)
    values["swigpath"] = get_dep_merged([module], "swig_path", ordered)
    values["defines"] = ":".join(defines)
    cppbins = tools.get_glob([os.path.join(path, "bin", "*.cpp")])
    cppbins = [os.path.splitext(e)[0] for e in cppbins]
    pybins = get_app_sources(os.path.join(path, "bin"), ["*"],
                             tools.filter_pyapps)
    values["pybins"] = "\n".join(pybins)
    values["bin_names"] = "\n".join([os.path.basename(x) \
                                     for x in pybins + cppbins])
    main = os.path.join(path, "src", "CMakeLists.txt")
    tests = os.path.join(path, "test", "CMakeLists.txt")
    swig = os.path.join(path, "pyext", "CMakeLists.txt")
    util = os.path.join(path, "utility", "CMakeLists.txt")
    bin = os.path.join(path, "bin", "CMakeLists.txt")
    benchmark = os.path.join(path, "benchmark", "CMakeLists.txt")
    examples = os.path.join(path, "examples", "CMakeLists.txt")
    tools.rewrite(main, lib_template % values)
    tools.rewrite(tests, test_template % values)
    tools.rewrite(swig, swig_template % values)
    tools.rewrite(util, util_template % values)
    tools.rewrite(bin, bin_template % values)
    tools.rewrite(benchmark, benchmark_template % values)
    tools.rewrite(examples, examples_template % values)
    values["tests"] = "\n".join(contents)
    values["subdirs"] = """add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/src)
add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/test)
add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/examples)
add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/benchmark)
add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/bin)
add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/utility)""" % ((module, ) * 6)

    out = os.path.join(path, "CMakeLists.txt")
    tools.rewrite(out, module_template % values)

    # at end so directories exist
    cmd = subprocess.Popen([
        "python",
        os.path.join("..", "..", "tools", "dev_tools", "setup_cmake.py")
    ],
                           cwd=path,
                           universal_newlines=True)

    return out
Пример #12
0
def get_app_sources(path, patterns, filt=lambda x: True):
    matching = tools.get_glob([os.path.join(path, x) for x in patterns])
    return ["${CMAKE_SOURCE_DIR}/%s" % tools.to_cmake_path(x) \
            for x in matching if filt(x)]
Пример #13
0
def get_app_sources(path, patterns):
    matching = tools.get_glob([os.path.join(path, x) for x in patterns])
    return "\n".join(
        ["${CMAKE_SOURCE_DIR}/%s" % tools.to_cmake_path(x) for x in matching if not x.endswith("dependencies.py")]
    )
Пример #14
0
def setup_module(module, path, ordered):
    checks = []
    deps = []
    contents = []
    defines = []
    for cc in tools.get_glob([os.path.join(path, "compiler", "*.cpp")]):
        ret = make_check(cc, module, path)
        checks.append(ret[0])
        defines.append(ret[1])
    for cc in tools.get_glob([os.path.join(path, "dependency", "*.description")]):
        ret = make_dependency_check(cc, module, path)
        if ret:
            deps.append(ret)

    if len(checks) > 0:
        tools.rewrite(
            "modules/%s/compiler/CMakeLists.txt" % module,
            "\n".join(["include(${CMAKE_SOURCE_DIR}/%s)\n" % tools.to_cmake_path(x) for x in checks]),
        )
        contents.append("add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/compiler)" % module)
    if len(deps) > 0:
        tools.rewrite(
            "modules/%s/dependency/CMakeLists.txt" % module,
            "\n".join(["include(${CMAKE_SOURCE_DIR}/%s)" % tools.to_cmake_path(x) for x in deps]),
        )
        contents.append("add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/dependency)" % module)
    local = os.path.join(path, "Setup.cmake")
    if os.path.exists(local):
        contents.append("include(${CMAKE_SOURCE_DIR}/%s)" % tools.to_cmake_path(local))

    values = {"name": module}
    values["NAME"] = module.upper()
    values["CPPNAME"] = module.upper().replace("_", "")
    data = tools.get_module_description(".", module, "")
    all_modules = tools.get_all_modules(".", [module], "", ordered)
    modules = ["${IMP_%s_LIBRARY}" % s for s in all_modules]
    dependencies = ["${%s_LIBRARIES}" % s.upper() for s in tools.get_all_dependencies(".", [module], "", ordered)]
    values["modules"] = ";".join(modules)
    values["tags"] = "\n".join(["${IMP_%s_DOC}" % m for m in all_modules])
    values["other_pythons"] = "\n".join(["${IMP_%s_PYTHON}" % m for m in all_modules])
    values["dependencies"] = ";".join(dependencies)
    values["sources"] = get_sources(module, path, "src", "*.cpp")
    values["headers"] = get_sources(module, path, "include", "*.h")
    values["cppbins"] = get_sources(module, path, "bin", "*.cpp")
    values["cppbenchmarks"] = get_sources(module, path, "benchmark", "*.cpp")
    values["pybenchmarks"] = get_sources(module, path, "benchmark", "*.py")
    values["pytests"] = get_sources(module, path, "test", "test_*.py")
    values["expytests"] = get_sources(module, path, "test", "expensive_test_*.py")
    values["mdpytests"] = get_sources(module, path, "test", "medium_test_*.py")
    values["cpptests"] = get_sources(module, path, "test", "test_*.cpp")
    values["mdcpptests"] = get_sources(module, path, "test", "medium_test_*.cpp")
    values["excpptests"] = get_sources(module, path, "test", "expensive_test_*.cpp")
    values["pyexamples"] = get_sources(module, path, "examples", "[a-zA-Z]*.py")
    values["cppexamples"] = get_sources(module, path, "examples", "*.cpp")
    values["excpptests"] = get_sources(module, path, "test", "expensive_test_*.cpp")
    values["includepath"] = get_dep_merged([module], "include_path", ordered)
    values["libpath"] = get_dep_merged([module], "link_path", ordered)
    values["swigpath"] = get_dep_merged([module], "swig_path", ordered)
    values["defines"] = ":".join(defines)

    main = os.path.join(path, "src", "CMakeLists.txt")
    tests = os.path.join(path, "test", "CMakeLists.txt")
    swig = os.path.join(path, "pyext", "CMakeLists.txt")
    bin = os.path.join(path, "bin", "CMakeLists.txt")
    benchmark = os.path.join(path, "benchmark", "CMakeLists.txt")
    examples = os.path.join(path, "examples", "CMakeLists.txt")
    tools.rewrite(main, lib_template % values)
    tools.rewrite(tests, test_template % values)
    tools.rewrite(swig, swig_template % values)
    tools.rewrite(bin, bin_template % values)
    tools.rewrite(benchmark, benchmark_template % values)
    tools.rewrite(examples, examples_template % values)
    values["tests"] = "\n".join(contents)
    values[
        "subdirs"
    ] = """add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/src)
add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/test)
add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/examples)
add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/benchmark)
add_subdirectory(${CMAKE_SOURCE_DIR}/modules/%s/bin)""" % (
        (module,) * 5
    )

    out = os.path.join(path, "CMakeLists.txt")
    tools.rewrite(out, module_template % values)
    return out
Пример #15
0
def setup_module(finder, module, tools_dir, extra_include, extra_swig,
                 required):
    checks = []
    deps = []
    contents = []
    defines = []
    for cc in tools.get_glob([os.path.join(module.path, "compiler", "*.cpp")]):
        ret = make_check(cc, module)
        checks.append(ret[0])
        defines.append(ret[1])
    for cc in tools.get_glob(
        [os.path.join(module.path, "dependency", "*.description")]):
        ret = make_dependency_check(cc, module)
        if ret:
            deps.append(ret)

    g = tools.CMakeFileGenerator()
    if len(checks) > 0:
        g.write(
            os.path.join(module.path, 'compiler', 'CMakeLists.txt'),
            "\n".join([
                "include(${CMAKE_SOURCE_DIR}/%s)\n" % tools.to_cmake_path(x)
                for x in checks
            ]))
        contents.append("add_subdirectory(${CMAKE_SOURCE_DIR}/%s/compiler)" %
                        tools.to_cmake_path(module.path))
    if len(deps) > 0:
        g.write(
            os.path.join(module.path, 'dependency', 'CMakeLists.txt'),
            "\n".join([
                "include(${CMAKE_SOURCE_DIR}/%s)" % tools.to_cmake_path(x)
                for x in deps
            ]))
        contents.append("add_subdirectory(${CMAKE_SOURCE_DIR}/%s/dependency)" %
                        tools.to_cmake_path(module.path))
    local = os.path.join(module.path, "Setup.cmake")
    if os.path.exists(local):
        contents.append("include(${CMAKE_SOURCE_DIR}/%s)" %
                        tools.to_cmake_path(local))

    values = {
        "name": module.name,
        "extra_include": extra_include,
        "extra_swig": extra_swig,
        "module_dir":
        tools.to_cmake_path(module.path) + '/' if module.path else '',
        "tools_dir": tools.to_cmake_path(tools_dir) + '/' if tools_dir else ''
    }
    if module.name == 'kernel':
        values['subdir'] = 'IMP'
        values['pymod'] = 'IMP'
        values['allh_header'] = 'IMP.h'
    else:
        values['subdir'] = 'IMP/' + module.name
        values['pymod'] = 'IMP.' + module.name
        values['allh_header'] = 'IMP/%s.h' % module.name
    values["NAME"] = module.name.upper()
    values["CPPNAME"] = module.name.upper().replace('_', '')
    all_modules = module.get_all_modules()
    modules = ["${IMP_%s_LIBRARY}" % s.name for s in all_modules]
    all_dependencies = list(finder.get_all_dependencies([module] +
                                                        all_modules))
    dependencies = ["${%s_LIBRARIES}" % s.upper() for s in all_dependencies]
    values["modules"] = ";".join(modules)
    values["tags"] = "\n".join(["${IMP_%s_DOC}" % m.name for m in all_modules])
    values["other_pythons"] = "\n".join(
        ["${IMP_%s_PYTHON}" % m.name for m in all_modules])
    values["dependencies"] = ";".join(dependencies)
    values["headers"] = get_sources(module, "include", "*.h")
    # Don't add NumPy include directory except for when we build SWIG
    # extensions; this prevents unnecessary rebuilds of C++ code when we
    # change Python version
    all_non_python_dependencies = [x for x in all_dependencies if x != 'NumPy']
    values["includepath"] = get_dep_merged(all_non_python_dependencies,
                                           "include_path")
    values["python_includepath"] = get_dep_merged(all_dependencies,
                                                  "include_path")
    values["libpath"] = get_dep_merged(all_dependencies, "link_path")
    values["swigpath"] = get_dep_merged(all_dependencies, "swig_path")
    values["defines"] = ":".join(defines)
    cppbins = tools.get_glob([os.path.join(module.path, "bin", "*.cpp")])
    cppbins = [os.path.splitext(e)[0] for e in cppbins]
    pybins = get_app_sources(os.path.join(module.path, "bin"), ["*"],
                             tools.filter_pyapps)
    values["pybins"] = "\n".join(pybins)
    values["bin_names"] = "\n".join([os.path.basename(x) \
                                     for x in pybins + cppbins])

    local = os.path.join(module.path, "Build.cmake")
    if os.path.exists(local):
        values["custom_build"] = "include(${CMAKE_SOURCE_DIR}/%s)\n" \
                                 % tools.to_cmake_path(local)
    else:
        values["custom_build"] = ""

    main = os.path.join(module.path, "src", "CMakeLists.txt")
    tests = os.path.join(module.path, "test", "CMakeLists.txt")
    swig = os.path.join(module.path, "pyext", "CMakeLists.txt")
    util = os.path.join(module.path, "utility", "CMakeLists.txt")
    bin = os.path.join(module.path, "bin", "CMakeLists.txt")
    benchmark = os.path.join(module.path, "benchmark", "CMakeLists.txt")
    examples = os.path.join(module.path, "examples", "CMakeLists.txt")
    lib_template.write(main, values)
    test_template.write(tests, values)
    swig_template.write(swig, values)
    util_template.write(util, values)
    bin_template.write(bin, values)
    benchmark_template.write(benchmark, values)
    examples_template.write(examples, values)
    values["tests"] = "\n".join(contents)
    topdir = '/' + tools.to_cmake_path(module.path) if module.path else ''
    if finder.external_dir:
        values["build_dir"] = "--build_dir=%s " % finder.external_dir
    else:
        values["build_dir"] = ""
    values["disabled_status"] = "FATAL_ERROR" if required else "STATUS"
    values["subdirs"] = """add_subdirectory(${CMAKE_SOURCE_DIR}%s/src)
add_subdirectory(${CMAKE_SOURCE_DIR}%s/test)
add_subdirectory(${CMAKE_SOURCE_DIR}%s/examples)
add_subdirectory(${CMAKE_SOURCE_DIR}%s/benchmark)
add_subdirectory(${CMAKE_SOURCE_DIR}%s/bin)
add_subdirectory(${CMAKE_SOURCE_DIR}%s/utility)""" % ((topdir, ) * 6)

    cmakelists = os.path.join(module.path, "CMakeLists.txt")
    if finder.one_module or standalone_cmake(cmakelists):
        out = os.path.join(module.path, "ModuleBuild.cmake")
    else:
        out = cmakelists
    module_template.write(out, values)

    # at end so directories exist
    subprocess.check_call([
        sys.executable,
        os.path.join(TOPDIR, "..", "dev_tools", "setup_cmake.py")
    ],
                          cwd=module.path or '.',
                          universal_newlines=True)

    return out