Beispiel #1
0
def main(argv):

    # parse and process the command-line arguments
    argparser = get_argument_parser()
    options = argparser.parse_args()
    cmake_env = os.environ.copy()
    if sys.platform == 'win32':
        env_list_sep = str(";")
    else:
        env_list_sep = str(":")

    # if we just wanted to generate the bash completion script
    if options.generate_bash_complete:
        args.print_bash_complete_script(argparser)
        return 0

    # if we just wanted to generate the bash completion script
    if options.generate_manual:
        args.print_manual(argparser)
        return 0

    # if we are in quiet mode we may also go to quick mode
    if options.quiet: options.quick = True

    # if we also want to build the project disable quick mode
    if options.build: options.quick = False

    # get the info from cmake if we are not in a hurry
    if not options.quick:
        cmake_info = cmake_system_info(options)
    else:
        cmake_info = list()

    # the search prefix
    for search_dir in options.search_dirs:
        subdir = os.path.join(search_dir, "include")
        if os.path.exists(subdir):
            options.include_dirs.append(subdir)
        subdir = os.path.join(search_dir, "lib")
        if os.path.exists(subdir):
            options.library_dirs.append(subdir)
            subdir = os.path.join(subdir, "pkgconfig")
            pkg_config_path = cmake_env.get("PKG_CONFIG_PATH", None)
            if pkg_config_path:
                pc_paths = pkg_config_path.split(env_list_sep)
                pc_paths.append(subdir)
                pkg_config_path = env_list_sep.join(pc_paths)
            else:
                pkg_config_path = subdir
            cmake_env["PKG_CONFIG_PATH"] = pkg_config_path

    # search the LD_LIBRARY_PATH
    options.library_dirs += search_ld_library_path()
    # search the CXX and LD FLAGS if requested
    if (options.use_cxxflags): options.include_dirs += search_cxxflags()
    if (options.use_ldflags): options.library_dirs += search_ldflags()

    # additional options for cmake
    cmake_options = list()

    # add configuration options
    if (len(options.config_types) == 1):
        cmake_options.append("-DCMAKE_BUILD_TYPE=" + options.config_types[0])
    elif (len(options.config_types) > 1):
        cmake_options.append("-DCMAKE_CONFIGURATION_TYPES=" +
                             ";".join(options.config_types))

    # add the installation prefix if provided
    if (options.install_prefix):
        cmake_options.append("-DCMAKE_INSTALL_PREFIX=" +
                             options.install_prefix)

    # set the low profile mode switch
    if (options.low_profile is not None):
        cmake_options.append("-DCONFIG_SET_LOW_PROFILE=On")
        if (options.low_profile):
            cmake_options.append("-DLOW_PROFILE=On")
        else:
            cmake_options.append("-DLOW_PROFILE=Off")

    # if we just want fo query the system configuration info
    if (options.info_only):
        cmake_options.append("-DCONFIG_INFO_ONLY=On")

    # disable building the examples
    if (not options.build_examples):
        cmake_options.append("-DNO_EXAMPLES=On")

    # limit the GL version
    if (options.max_gl_version):
        cmake_options.append("-DCONFIG_MAX_GL_VERSION=%s" %
                             options.max_gl_version)

    # enable/disable strict version detection
    if (options.strict_gl_version_detection is not None):
        value = int(options.strict_gl_version_detection)
        cmake_options.append("-DCONFIG_STRICT_GL_VERSION_CHECK=%d" % value)

    if (options.gl_tests_compile_only):
        cmake_options.append("-DCOMPILE_ONLY_GL_TESTS=On")

    # force the GL header to be used
    if (options.gl_api_lib):
        cmake_options.append("-DFORCE_GL_API_LIB=%s" % options.gl_api_lib)

    # force the GL initialization library to be used
    if (options.gl_init_lib):
        cmake_options.append("-DFORCE_GL_INIT_LIB=%s" % options.gl_init_lib)

    # add paths for header lookop
    if (options.include_dirs):
        cmake_options.append("-DHEADER_SEARCH_PATHS=" +
                             ";".join(options.include_dirs))

    # add paths for library lookup
    if (options.library_dirs):
        cmake_options.append("-DLIBRARY_SEARCH_PATHS=" +
                             ";".join(options.library_dirs))

    # remove the build dir if it was requested
    if (options.clean and os.path.exists(options.build_dir)):
        try:
            shutil.rmtree(options.build_dir)
        except OSError as os_error:
            print("Warning failed to remove build directory")

    # configure the test suite
    if (options.no_tests):
        cmake_options.append("-DNO_TESTS=On")
    if (options.no_enum_tests):
        cmake_options.append("-DNO_ENUM_TESTS=On")

    # set the generator if specified
    if (options.generator):
        cmake_options += ['-G', options.generator]

    # put cmake in debug mode if specified
    if (options.debug_gl_ver_error):
        cmake_options += ["-DDEBUG_GL_VER_ERROR=1"]
    if (options.debug_gl_feat_error):
        cmake_options += [
            "-DDEBUG_GL_FEAT_ERROR=%s" % options.debug_gl_feat_error
        ]
    if (options.debug_lib_error):
        cmake_options += ["-DDEBUG_LIB_ERROR=1"]
    if (options.debug_config):
        cmake_options += ["-DDEBUG_CONFIG=1"]
        cmake_options += ["--debug-output", "--debug-trycompile"]

    # get the work directory path
    workdir = os.path.abspath(os.path.dirname(sys.argv[0]))

    # create the build directory if necessary
    if (not os.path.isdir(options.build_dir)):
        os.makedirs(options.build_dir)

    # compose the command line for calling cmake
    cmake_cmd_line = ["cmake"
                      ] + cmake_options + options.cmake_options + [workdir]

    # call cmake
    try:
        ret = subprocess.call(cmake_cmd_line,
                              cwd=options.build_dir,
                              env=cmake_env)
        if ret < 0:
            print("# Configuration killed by signal %d" % -ret)
            sys.exit(-ret)
        elif ret > 0:
            print("# Configuration failed with code %d" % ret)
            sys.exit(ret)
    # handle errors
    except OSError as os_error:
        print("# Configuration failed")
        print("# Failed to execute '%(cmd)s': %(error)s" % {
            "cmd": str(" ").join(cmake_cmd_line),
            "error": str(os_error)
        })
        sys.exit(3)

    # use the specified number of jobs
    if options.jobs is not None:
        job_count = options.jobs
    else:
        # else try to get the processor count (use below)
        try:
            import multiprocessing
            job_count = multiprocessing.cpu_count() + 1
        except:
            job_count = None

    # print some info if not supressed
    if not options.quiet and not options.info_only:
        print("# Configuration completed successfully.")

        cmake_build_tool = cmake_info.get("CMAKE_BUILD_TOOL")
        if (cmake_build_tool):
            cmake_build_tool = paths.shorten_command(cmake_build_tool)
            path_to_build_dir = paths.shortest_path_from_to(
                os.getcwd(), options.build_dir)

            if (not options.build):
                if (cmake_build_tool == "make"):
                    print("# To build OGLplus do the following:")
                    print(str())
                    print("cd " + path_to_build_dir)
                    if job_count:
                        print("%(tool)s -j %(jobs)d" % {
                            "tool": cmake_build_tool,
                            "jobs": job_count
                        })
                    else:
                        print(cmake_build_tool)
                    print(cmake_build_tool + " install")

    # if the user requested build after config is done
    if options.build:
        cmake_build_tool = cmake_info.get("CMAKE_BUILD_TOOL")

        if cmake_build_tool:
            build_tool_name = os.path.basename(cmake_build_tool)
        else:
            build_tool_name = str()

        if build_tool_name in ("make", ):
            build_cmd_line = [cmake_build_tool]
            if job_count:
                build_cmd_line += ["-j", str(job_count)]
        elif build_tool_name in ("devenv.com", "devenv.exe"):
            build_cmd_line = [
                cmake_build_tool,
                os.path.join(options.build_dir, "OGLplus.sln"), "/Build",
                "Release"
            ]
        else:
            build_cmd_line = ["cmake", "--build", options.build_dir]

        if build_cmd_line:
            try:
                subprocess.call(build_cmd_line,
                                cwd=options.build_dir,
                                env=cmake_env)
            except OSError as os_error:
                print("# Build failed")
                print("# Failed to execute '%(cmd)s': %(error)s" % {
                    "cmd": str(" ").join(build_cmd_line),
                    "error": str(os_error)
                })
                sys.exit(4)
        else:
            print("# --build is not supported with the current build tool")

    # print the configuration info if requested
    if options.info_only:
        try:
            info_py_path = os.path.join(options.build_dir, 'config', 'info.py')
            info_py = open(info_py_path).read()
            exec(info_py) in locals()

            key_descs = {
                "GL_INIT_LIBS": "Possible values for --gl-init-lib",
                "GL_API_LIBS": "Possible values for --gl-api-lib",
            }
            for key, value in oglplus_config_info.items():

                try:
                    desc = key_descs[key]
                except:
                    desc = key

                if type(value) == list:
                    value = "\n\t".join(value)

                print("%(desc)s:\n\t%(value)s" % {
                    "desc": desc,
                    "value": value
                })
        except:
            pass

    # print additional info if not supressed
    elif not options.quiet:

        if not options.install_prefix:
            options.install_prefix = cmake_info.get("CMAKE_INSTALL_PREFIX")

        if (options.install_prefix):

            if not os.access(options.install_prefix, os.W_OK):
                print(str())
                print("# NOTE: installing to '%(prefix)s' "\
                 "may require administrative privilegues" % {
                  "prefix": options.install_prefix
                 }
                )
Beispiel #2
0
def main(argv):

	# parse and process the command-line arguments
	argparser = get_argument_parser()
	options = argparser.parse_args()
	cmake_env = os.environ.copy()
	if sys.platform == 'win32':
		env_list_sep = str(";")
	else: env_list_sep = str(":")

	# if we just wanted to generate the bash completion script
	if options.generate_bash_complete:
		args.print_bash_complete_script(argparser)
		return 0

	# if we just wanted to generate the bash completion script
	if options.generate_manual:
		args.print_manual(argparser)
		return 0

	# if we are in quiet mode we may also go to quick mode
	if options.quiet: options.quick = True

	# if we also want to build the project disable quick mode
	if options.build: options.quick = False

	# get the info from cmake if we are not in a hurry
	if not options.quick:
		cmake_info = cmake_system_info(options)
	else: cmake_info = list()

	# the search prefix
	for search_dir in options.search_dirs:
		subdir = os.path.join(search_dir, "include")
		if os.path.exists(subdir):
			options.include_dirs.append(subdir)
		subdir = os.path.join(search_dir, "lib")
		if os.path.exists(subdir):
			options.library_dirs.append(subdir)
			subdir = os.path.join(subdir, "pkgconfig")
			pkg_config_path = cmake_env.get("PKG_CONFIG_PATH", None)
			if pkg_config_path:
				pc_paths = pkg_config_path.split(env_list_sep)
				pc_paths.append(subdir)
				pkg_config_path = env_list_sep.join(pc_paths)
			else: pkg_config_path = subdir
			cmake_env["PKG_CONFIG_PATH"] = pkg_config_path

	# search the LD_LIBRARY_PATH
	options.library_dirs += search_ld_library_path()
	# search the CXX and LD FLAGS if requested
	if(options.use_cxxflags): options.include_dirs += search_cxxflags()
	if(options.use_ldflags):  options.library_dirs += search_ldflags()

	# additional options for cmake
	cmake_options = list()

	# add the installation prefix if provided
	if(options.install_prefix):
		cmake_options.append(
			"-DCMAKE_INSTALL_PREFIX="+
			options.install_prefix
		)

	# add paths for reflexpr header lookop
	if(options.reflexpr_include_dir):
		cmake_options.append("-DREFLEXPR_INCLUDE_DIR="+options.reflexpr_include_dir)

	# add paths for header lookop
	if(options.include_dirs):
		cmake_options.append("-DHEADER_SEARCH_PATHS="+";".join(options.include_dirs))

	# add paths for library lookup
	if(options.library_dirs):
		cmake_options.append("-DLIBRARY_SEARCH_PATHS="+";".join(options.library_dirs))

	# add configuration options
	if(len(options.config_types) == 1):
		cmake_options.append("-DCMAKE_BUILD_TYPE="+options.config_types[0])
	elif(len(options.config_types) > 1):
		cmake_options.append("-DCMAKE_CONFIGURATION_TYPES="+";".join(options.config_types))

	# enable/disable external libraries
	for ext_dep in external_deps:
		try:
			val = vars(options)["with_%s" % ext_dep]
			cmake_options.append("-DMIRROR_NO_%(EXT)s=%(VAL)s" % {
				"EXT" : ext_dep.upper(),
				"VAL" : ("Off" if val else "On")
			})
		except KeyError: pass

	# remove the build dir if it was requested
	if(options.clean and os.path.exists(options.build_dir)):
		try: shutil.rmtree(options.build_dir)
		except OSError as os_error:
			print("Warning failed to remove build directory")

	# configure the test suite
	if(options.no_tests):
		cmake_options.append("-DNO_TESTS=On")

	# set the generator if specified
	if(options.generator):
		cmake_options += ['-G', options.generator]

	if(options.debug_config):
		cmake_options += ["--debug-output", "--debug-trycompile"]

	# get the work directory path
	workdir = os.path.abspath(os.path.dirname(sys.argv[0]))

	# create the build directory if necessary
	if(not os.path.isdir(options.build_dir)):
		os.makedirs(options.build_dir)

	# compose the command line for calling cmake
	cmake_cmd_line = ["cmake"] + cmake_options + options.cmake_options + [workdir]

	# call cmake
	try:
		ret = subprocess.call(
			cmake_cmd_line,
			cwd=options.build_dir,
			env=cmake_env
		)
		if ret < 0:
			print("# Configuration killed by signal %d" % -ret)
			sys.exit(-ret)
		elif ret > 0:
			print("# Configuration failed with code %d" % ret)
			sys.exit(ret)
	# handle errors
	except OSError as os_error:
		print( "# Configuration failed")
		print("# Failed to execute '%(cmd)s': %(error)s" % {
			"cmd": str(" ").join(cmake_cmd_line),
			"error": str(os_error)
		})
		sys.exit(3)

	# use the specified number of jobs
	if options.jobs is not None:
		job_count = options.jobs
	else:
		# else try to get the processor count (use below)
		try:
			import multiprocessing
			job_count = multiprocessing.cpu_count()+1
		except: job_count = None

	# print some info if not supressed
	if not options.quiet:
		print("# Configuration completed successfully.")

		cmake_build_tool = cmake_info.get("CMAKE_BUILD_TOOL")
		if(cmake_build_tool):
			cmake_build_tool = paths.shorten_command(cmake_build_tool)
			path_to_build_dir = paths.shortest_path_from_to(os.getcwd(), options.build_dir)

			if(not options.build):
				if(cmake_build_tool == "make"):
					print("# To build Mirror do the following:")
					print(str())
					print("cd "+ path_to_build_dir)
					if job_count:
						print("%(tool)s -j %(jobs)d" % {
							"tool": cmake_build_tool,
							"jobs": job_count
						})
					else: print(cmake_build_tool)
					print(cmake_build_tool + " install")

	# if the user requested build after config is done
	if options.build:
		cmake_build_tool = cmake_info.get("CMAKE_BUILD_TOOL")

		if cmake_build_tool:
			build_tool_name = os.path.basename(cmake_build_tool)
		else:
			build_tool_name = str()

		if build_tool_name in ("make",):
			build_cmd_line = [cmake_build_tool];
			if job_count:
				build_cmd_line += ["-j", str(job_count)]
		elif build_tool_name in ("devenv.com", "devenv.exe"):
			build_cmd_line = [
				cmake_build_tool,
				os.path.join(options.build_dir, "Mirror.sln"),
				"/Build",
				"Release"
			]
		else: build_cmd_line = [ "cmake", "--build", options.build_dir ]

		if build_cmd_line:
			try: subprocess.call(
				build_cmd_line,
				cwd=options.build_dir,
				env=cmake_env
			)
			except OSError as os_error:
				print( "# Build failed")
				print("# Failed to execute '%(cmd)s': %(error)s" % {
					"cmd": str(" ").join(build_cmd_line),
					"error": str(os_error)
				})
				sys.exit(4)
		else: print("# --build is not supported with the current build tool")


	# print additional info if not supressed
	if not options.quiet:

		if not options.install_prefix:
			options.install_prefix = cmake_info.get("CMAKE_INSTALL_PREFIX")

		if(options.install_prefix):

			if not os.access(options.install_prefix, os.W_OK):
				print(str())
				print("# NOTE: installing to '%(prefix)s' "\
					"may require administrative privilegues" % {
						"prefix": options.install_prefix
					}
				)
Beispiel #3
0
def main(argv):

	# parse and process the command-line arguments
	argparser = get_argument_parser()
	options = argparser.parse_args()
	cmake_env = os.environ.copy()
	if sys.platform == 'win32':
		env_list_sep = str(";")
	else: env_list_sep = str(":")

	# if we just wanted to generate the bash completion script
	if options.generate_bash_complete:
		args.print_bash_complete_script(argparser)
		return 0

	# if we just wanted to generate the bash completion script
	if options.generate_manual:
		args.print_manual(argparser)
		return 0

	# if we are in quiet mode we may also go to quick mode
	if options.quiet: options.quick = True

	# if we also want to build the project disable quick mode
	if options.build: options.quick = False

	# get the info from cmake if we are not in a hurry
	if not options.quick:
		cmake_info = cmake_system_info(options)
	else: cmake_info = list()

	# the search prefix
	for search_dir in options.search_dirs:
		subdir = os.path.join(search_dir, "include")
		if os.path.exists(subdir):
			options.include_dirs.append(subdir)
		subdir = os.path.join(search_dir, "lib")
		if os.path.exists(subdir):
			options.library_dirs.append(subdir)
			subdir = os.path.join(subdir, "pkgconfig")
			pkg_config_path = cmake_env.get("PKG_CONFIG_PATH", None)
			if pkg_config_path:
				pc_paths = pkg_config_path.split(env_list_sep)
				pc_paths.append(subdir)
				pkg_config_path = env_list_sep.join(pc_paths)
			else: pkg_config_path = subdir
			cmake_env["PKG_CONFIG_PATH"] = pkg_config_path

	# search the LD_LIBRARY_PATH
	options.library_dirs += search_ld_library_path()
	# search the CXX and LD FLAGS if requested
	if(options.use_cxxflags): options.include_dirs += search_cxxflags()
	if(options.use_ldflags):  options.library_dirs += search_ldflags()

	# additional options for cmake
	cmake_options = list()

	# add the installation prefix if provided
	if(options.install_prefix):
		cmake_options.append(
			"-DCMAKE_INSTALL_PREFIX="+
			options.install_prefix
		)

	# set the low profile mode switch
	if(options.low_profile is not None):
		cmake_options.append("-DCONFIG_SET_LOW_PROFILE=On")
		if(options.low_profile):
			cmake_options.append("-DLOW_PROFILE=On")
		else:
			cmake_options.append("-DLOW_PROFILE=Off")

	# if we just want fo query the system configuration info
	if(options.info_only):
		cmake_options.append("-DCONFIG_INFO_ONLY=On")

	# disable building the examples
	if(not options.build_examples):
		cmake_options.append("-DNO_EXAMPLES=On")

	# limit the GL version
	if(options.max_gl_version):
		cmake_options.append("-DCONFIG_MAX_GL_VERSION=%s"%options.max_gl_version)

	# enable/disable strict version detection
	if(options.strict_gl_version_detection is not None):
		value = int(options.strict_gl_version_detection)
		cmake_options.append("-DCONFIG_STRICT_GL_VERSION_CHECK=%d"%value)

	if(options.gl_tests_compile_only):
		cmake_options.append("-DCOMPILE_ONLY_GL_TESTS=On")

	# force the GL header to be used
	if(options.gl_api_lib):
		cmake_options.append("-DFORCE_GL_API_LIB=%s"%options.gl_api_lib)

	# force the GL initialization library to be used
	if(options.gl_init_lib):
		cmake_options.append("-DFORCE_GL_INIT_LIB=%s"%options.gl_init_lib)

	# add paths for header lookop
	if(options.include_dirs):
		cmake_options.append("-DHEADER_SEARCH_PATHS="+";".join(options.include_dirs))

	# add paths for library lookup
	if(options.library_dirs):
		cmake_options.append("-DLIBRARY_SEARCH_PATHS="+";".join(options.library_dirs))

	# remove the build dir if it was requested
	if(options.clean and os.path.exists(options.build_dir)):
		try: shutil.rmtree(options.build_dir)
		except OSError as os_error:
			print("Warning failed to remove build directory")

	# configure the test suite
	if(options.no_tests):
		cmake_options.append("-DNO_TESTS=On")
	if(options.no_enum_tests):
		cmake_options.append("-DNO_ENUM_TESTS=On")

	# set the generator if specified
	if(options.generator):
		cmake_options += ['-G', options.generator]

	# put cmake in debug mode if specified
	if(options.debug_gl_ver_error):
		cmake_options += ["-DDEBUG_GL_VER_ERROR=1"]
	if(options.debug_gl_ext_error):
		cmake_options += ["-DDEBUG_GL_EXT_ERROR=%s"%options.debug_gl_ext_error]
	if(options.debug_lib_error):
		cmake_options += ["-DDEBUG_LIB_ERROR=1"]
	if(options.debug_config):
		cmake_options += ["--debug-output", "--debug-trycompile"]

	# get the work directory path
	workdir = os.path.abspath(os.path.dirname(sys.argv[0]))

	# create the build directory if necessary
	if(not os.path.isdir(options.build_dir)):
		os.makedirs(options.build_dir)

	# compose the command line for calling cmake
	cmake_cmd_line = ["cmake"] + cmake_options + options.cmake_options + [workdir]

	# call cmake
	try:
		ret = subprocess.call(
			cmake_cmd_line,
			cwd=options.build_dir,
			env=cmake_env
		)
		if ret < 0:
			print("# Configuration killed by signal %d" % -ret)
			sys.exit(-ret)
		elif ret > 0:
			print("# Configuration failed with code %d" % ret)
			sys.exit(ret)
	# handle errors
	except OSError as os_error:
		print( "# Configuration failed")
		print("# Failed to execute '%(cmd)s': %(error)s" % {
			"cmd": str(" ").join(cmake_cmd_line),
			"error": str(os_error)
		})
		sys.exit(3)

	# use the specified number of jobs
	if options.jobs is not None:
		job_count = options.jobs
	else:
		# else try to get the processor count (use below)
		try:
			import multiprocessing
			job_count = multiprocessing.cpu_count()+1
		except: job_count = None

	# print some info if not supressed
	if not options.quiet and not options.info_only:
		print("# Configuration completed successfully.")

		cmake_build_tool = cmake_info.get("CMAKE_BUILD_TOOL")
		if(cmake_build_tool):
			cmake_build_tool = paths.shorten_command(cmake_build_tool)
			path_to_build_dir = paths.shortest_path_from_to(os.getcwd(), options.build_dir)

			if(not options.build):
				if(cmake_build_tool == "make"):
					print("# To build OGLplus do the following:")
					print(str())
					print("cd "+ path_to_build_dir)
					if job_count:
						print("%(tool)s -j %(jobs)d" % {
							"tool": cmake_build_tool,
							"jobs": job_count
						})
					else: print(cmake_build_tool)
					print(cmake_build_tool + " install")

	# if the user requested build after config is done
	if options.build:
		cmake_build_tool = cmake_info.get("CMAKE_BUILD_TOOL")

		if cmake_build_tool:
			build_tool_name = os.path.basename(cmake_build_tool)
		else:
			build_tool_name = str()

		if build_tool_name in ("make",):
			build_cmd_line = [cmake_build_tool];
			if job_count:
				build_cmd_line += ["-j", str(job_count)]
		elif build_tool_name in ("devenv.com", "devenv.exe"):
			build_cmd_line = [
				cmake_build_tool,
				os.path.join(options.build_dir, "OGLplus.sln"),
				"/Build",
				"Release"
			]
		else: build_cmd_line = [ "cmake", "--build", options.build_dir ]

		if build_cmd_line:
			try: subprocess.call(
				build_cmd_line,
				cwd=options.build_dir,
				env=cmake_env
			)
			except OSError as os_error:
				print( "# Build failed")
				print("# Failed to execute '%(cmd)s': %(error)s" % {
					"cmd": str(" ").join(build_cmd_line),
					"error": str(os_error)
				})
				sys.exit(4)
		else: print("# --build is not supported with the current build tool")


	# print the configuration info if requested
	if options.info_only:
		try:
			info_py_path=os.path.join(options.build_dir, 'config', 'info.py')
			info_py=open(info_py_path).read()
			exec(info_py) in locals()

			key_descs = {
				"GL_INIT_LIBS": "Possible values for --gl-init-lib",
				"GL_API_LIBS": "Possible values for --gl-api-lib",
			}
			for key, value in oglplus_config_info.items():

				try: desc=key_descs[key]
				except: desc=key

				if type(value) == list:
					value = "\n\t".join(value)

				print("%(desc)s:\n\t%(value)s" % {"desc": desc, "value": value})
		except: pass

	# print additional info if not supressed
	elif not options.quiet:

		if not options.install_prefix:
			options.install_prefix = cmake_info.get("CMAKE_INSTALL_PREFIX")

		if(options.install_prefix):

			if not os.access(options.install_prefix, os.W_OK):
				print(str())
				print("# NOTE: installing to '%(prefix)s' "\
					"may require administrative privilegues" % {
						"prefix": options.install_prefix
					}
				)
Beispiel #4
0
def main(argv):

    # parse and process the command-line arguments
    argparser = get_argument_parser()
    options = argparser.parse_args()
    cmake_env = os.environ.copy()
    if sys.platform == 'win32':
        env_list_sep = str(";")
    else:
        env_list_sep = str(":")

    # if we just wanted to generate the bash completion script
    if options.generate_bash_complete:
        args.print_bash_complete_script(argparser)
        return 0

    # if we just wanted to generate the bash completion script
    if options.generate_manual:
        args.print_manual(argparser)
        return 0

    # if we are in quiet mode we may also go to quick mode
    if options.quiet: options.quick = True

    # if we also want to build the project disable quick mode
    if options.build: options.quick = False

    # get the info from cmake if we are not in a hurry
    if not options.quick:
        cmake_info = cmake_system_info(options)
    else:
        cmake_info = list()

    # the search prefix
    for search_dir in options.search_dirs:
        subdir = os.path.join(search_dir, "include")
        if os.path.exists(subdir):
            options.include_dirs.append(subdir)
        subdir = os.path.join(search_dir, "lib")
        if os.path.exists(subdir):
            options.library_dirs.append(subdir)
            subdir = os.path.join(subdir, "pkgconfig")
            pkg_config_path = cmake_env.get("PKG_CONFIG_PATH", None)
            if pkg_config_path:
                pc_paths = pkg_config_path.split(env_list_sep)
                pc_paths.append(subdir)
                pkg_config_path = env_list_sep.join(pc_paths)
            else:
                pkg_config_path = subdir
            cmake_env["PKG_CONFIG_PATH"] = pkg_config_path

    # search the LD_LIBRARY_PATH
    options.library_dirs += search_ld_library_path()
    # search the CXX and LD FLAGS if requested
    if (options.use_cxxflags): options.include_dirs += search_cxxflags()
    if (options.use_ldflags): options.library_dirs += search_ldflags()

    # additional options for cmake
    cmake_options = list()

    # add the installation prefix if provided
    if (options.install_prefix):
        cmake_options.append("-DCMAKE_INSTALL_PREFIX=" +
                             options.install_prefix)

    # add paths for reflexpr header lookop
    if (options.reflexpr_include_dir):
        cmake_options.append("-DREFLEXPR_INCLUDE_DIR=" +
                             options.reflexpr_include_dir)

    # add paths for header lookop
    if (options.include_dirs):
        cmake_options.append("-DHEADER_SEARCH_PATHS=" +
                             ";".join(options.include_dirs))

    # add paths for library lookup
    if (options.library_dirs):
        cmake_options.append("-DLIBRARY_SEARCH_PATHS=" +
                             ";".join(options.library_dirs))

    # add configuration options
    if (len(options.config_types) == 1):
        cmake_options.append("-DCMAKE_BUILD_TYPE=" + options.config_types[0])
    elif (len(options.config_types) > 1):
        cmake_options.append("-DCMAKE_CONFIGURATION_TYPES=" +
                             ";".join(options.config_types))

    # enable/disable external libraries
    for ext_dep in external_deps:
        try:
            val = vars(options)["with_%s" % ext_dep]
            cmake_options.append("-DMIRROR_NO_%(EXT)s=%(VAL)s" % {
                "EXT": ext_dep.upper(),
                "VAL": ("Off" if val else "On")
            })
        except KeyError:
            pass

    # remove the build dir if it was requested
    if (options.clean and os.path.exists(options.build_dir)):
        try:
            shutil.rmtree(options.build_dir)
        except OSError as os_error:
            print("Warning failed to remove build directory")

    # configure the test suite
    if (options.no_tests):
        cmake_options.append("-DNO_TESTS=On")

    # set the generator if specified
    if (options.generator):
        cmake_options += ['-G', options.generator]

    if (options.debug_config):
        cmake_options += ["--debug-output", "--debug-trycompile"]

    # get the work directory path
    workdir = os.path.abspath(os.path.dirname(sys.argv[0]))

    # create the build directory if necessary
    if (not os.path.isdir(options.build_dir)):
        os.makedirs(options.build_dir)

    # compose the command line for calling cmake
    cmake_cmd_line = ["cmake"
                      ] + cmake_options + options.cmake_options + [workdir]

    # call cmake
    try:
        ret = subprocess.call(cmake_cmd_line,
                              cwd=options.build_dir,
                              env=cmake_env)
        if ret < 0:
            print("# Configuration killed by signal %d" % -ret)
            sys.exit(-ret)
        elif ret > 0:
            print("# Configuration failed with code %d" % ret)
            sys.exit(ret)
    # handle errors
    except OSError as os_error:
        print("# Configuration failed")
        print("# Failed to execute '%(cmd)s': %(error)s" % {
            "cmd": str(" ").join(cmake_cmd_line),
            "error": str(os_error)
        })
        sys.exit(3)

    # use the specified number of jobs
    if options.jobs is not None:
        job_count = options.jobs
    else:
        # else try to get the processor count (use below)
        try:
            import multiprocessing
            job_count = multiprocessing.cpu_count() + 1
        except:
            job_count = None

    # print some info if not supressed
    if not options.quiet:
        print("# Configuration completed successfully.")

        cmake_build_tool = cmake_info.get("CMAKE_BUILD_TOOL")
        if (cmake_build_tool):
            cmake_build_tool = paths.shorten_command(cmake_build_tool)
            path_to_build_dir = paths.shortest_path_from_to(
                os.getcwd(), options.build_dir)

            if (not options.build):
                if (cmake_build_tool == "make"):
                    print("# To build Mirror do the following:")
                    print(str())
                    print("cd " + path_to_build_dir)
                    if job_count:
                        print("%(tool)s -j %(jobs)d" % {
                            "tool": cmake_build_tool,
                            "jobs": job_count
                        })
                    else:
                        print(cmake_build_tool)
                    print(cmake_build_tool + " install")

    # if the user requested build after config is done
    if options.build:
        cmake_build_tool = cmake_info.get("CMAKE_BUILD_TOOL")

        if cmake_build_tool:
            build_tool_name = os.path.basename(cmake_build_tool)
        else:
            build_tool_name = str()

        if build_tool_name in ("make", ):
            build_cmd_line = [cmake_build_tool]
            if job_count:
                build_cmd_line += ["-j", str(job_count)]
        elif build_tool_name in ("devenv.com", "devenv.exe"):
            build_cmd_line = [
                cmake_build_tool,
                os.path.join(options.build_dir, "Mirror.sln"), "/Build",
                "Release"
            ]
        else:
            build_cmd_line = ["cmake", "--build", options.build_dir]

        if build_cmd_line:
            try:
                subprocess.call(build_cmd_line,
                                cwd=options.build_dir,
                                env=cmake_env)
            except OSError as os_error:
                print("# Build failed")
                print("# Failed to execute '%(cmd)s': %(error)s" % {
                    "cmd": str(" ").join(build_cmd_line),
                    "error": str(os_error)
                })
                sys.exit(4)
        else:
            print("# --build is not supported with the current build tool")

    # print additional info if not supressed
    if not options.quiet:

        if not options.install_prefix:
            options.install_prefix = cmake_info.get("CMAKE_INSTALL_PREFIX")

        if (options.install_prefix):

            if not os.access(options.install_prefix, os.W_OK):
                print(str())
                print("# NOTE: installing to '%(prefix)s' "\
                 "may require administrative privilegues" % {
                  "prefix": options.install_prefix
                 }
                )