def get_dep_merged(modules, name, ordered): ret = [] alldeps = tools.get_all_dependencies(".", modules, "", ordered) for d in alldeps: ret.append("${%s_%s}" % (d.upper(), name.upper())) ret = sorted(set(ret)) return "\n ".join(ret)
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
def get_dep_merged(modules, name, ordered): ret=[] alldeps=tools.get_all_dependencies(".", modules, "", ordered) for d in alldeps: info = tools.get_dependency_info(d, ".") lst= tools.split(info[name], ';') # cmake lists are semicolon-separated ret.extend(lst) ret=list(set(ret)) ret.sort() return ret
def get_dep_merged(modules, name, ordered): ret = [] alldeps = tools.get_all_dependencies(".", modules, "", ordered) for d in alldeps: info = tools.get_dependency_info(d, ".") # cmake lists are semicolon-separated lst = tools.split(info[name], ';') ret.extend(lst) ret = sorted(set(ret)) return ret
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
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
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
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