def cmd_build(args): if not os.path.isfile(args.project_file): error_project_not_found(args.project_file) project = cryproject.CryProject() try: project.load(args.project_file) except Exception: error_project_json_decode(args.project_file) cmake_path = crypath.get_cmake_exe_path() if cmake_path is None: error_cmake_not_found() # --- cmake if project.cmakelists_dir() is not None: project_path = os.path.dirname(os.path.abspath(args.project_file)) solution_dir = get_project_solution_dir(project_path) if 'win32' in solution_dir: error_platform_deprecated('win32') subcmd = (cmake_path, '--build', solution_dir, '--config', args.config) print_subprocess(subcmd) errcode = subprocess.call(subcmd, cwd=project_path) if errcode != 0: sys.exit(errcode)
def open_cmake_gui(source_dir, build_dir): cmake_path = crypath.get_cmake_exe_path() if cmake_path is None: error_cmake_not_found() cmake_gui_path = cmake_path.replace('cmake.exe', 'cmake-gui.exe') if not os.path.isfile(cmake_gui_path): error_cmake_not_found() command_str = '"{}" -S"{}" -B"{}"'.format(cmake_gui_path, source_dir, build_dir) subprocess.Popen(command_str, cwd=source_dir)
def generate_solution(working_directory, cmakelists_dir, config, open_gui): cmake_dir = crypath.get_cmake_dir() cmake_path = crypath.get_cmake_exe_path() if cmake_path is None: error_cmake_not_found() # By default the CMake output is hidden. This is printed to make # sure the user knows it's not stuck. print("Generating solution...") # toolchain is relative path, e.g. toolchain/windows/WindowsPC-MSVC.cmake toolchain = config['cmake_toolchain'] solution_path = os.path.join(working_directory, config['cmake_builddir']) generator = config['cmake_generator'] print("Solution path: {}".format(solution_path)) check_cmake_cache(solution_path, generator) if not os.path.isdir(solution_path): os.makedirs(solution_path) if toolchain: toolchain = toolchain.replace('\\', '/') toolchain = os.path.join(cmake_dir, toolchain) cmake_command = [cmake_path, '-Wno-dev', '-G{}'.format(generator)] if toolchain: cmake_command.append('-DCMAKE_TOOLCHAIN_FILE={}'.format(toolchain)) cmake_command.append(cmakelists_dir) # Filter empty commands, and convert the list to a string. cmake_command = list(filter(bool, cmake_command)) try: print("Solution generation command '{}'".format(cmake_command)) subprocess.run(cmake_command, cwd=solution_path, stdout=None, stderr=None, check=True, universal_newlines=True) except subprocess.CalledProcessError as e: print("Encountered and error while running command '{}'!".format( e.cmd)) print("Look for errors in the output above.") print("Generating solution has failed!") sys.exit(1) if open_gui: open_cmake_gui(cmakelists_dir, solution_path)
def generate_solution(working_directory, cmakelists_dir, config, open_gui): cmake_dir = crypath.get_cmake_dir() cmake_path = crypath.get_cmake_exe_path() if cmake_path is None: error_cmake_not_found() # By default the CMake output is hidden. This is printed to make # sure the user knows it's not stuck. print("Generating solution...") # toolchain is relative path, e.g. toolchain/windows/WindowsPC-MSVC.cmake toolchain = config['cmake_toolchain'] solution_path = os.path.join(working_directory, config['cmake_builddir']) generator = config['cmake_generator'] # Due to a bug in CMake visual studio generation, we cannot have certain characters in the cmake path. # CMake will generate a command for the INSTALL project in visual studio, which reruns cmake on build. # However, the path in the command is not properly quoted by CMake which breaks the build. regex = re.compile('[{}]'.format(re.escape('[](){}#%^'))) if "Visual Studio" in generator and os.path.isabs( cmake_path) and regex.search(cmake_path) is not None: print("ERROR:") print( "Cannot generate a Visual Studio solution for projects outside the engine installation folder when the engine is installed in a path that contains the following characters: '[](){}#%^' due to a CMake bug." ) print("Engine path: {}".format(cmake_path)) print("Generating solution has failed!") sys.exit(1) print("Solution path: {}".format(solution_path)) check_cmake_cache(solution_path, generator) if not os.path.isdir(solution_path): os.makedirs(solution_path) if toolchain: toolchain = toolchain.replace('\\', '/') toolchain = os.path.join(cmake_dir, toolchain) cmake_command = [cmake_path, '-Wno-dev', '-G{}'.format(generator)] if toolchain: cmake_command.append('-DCMAKE_TOOLCHAIN_FILE={}'.format(toolchain)) cmake_command.append(cmakelists_dir) # Filter empty commands, and convert the list to a string. cmake_command = list(filter(bool, cmake_command)) try: print("Solution generation command '{}'".format(cmake_command)) subprocess.run(cmake_command, cwd=solution_path, stdout=None, stderr=None, check=True, universal_newlines=True) except subprocess.CalledProcessError as e: print("Encountered and error while running command '{}'!".format( e.cmd)) print("Look for errors in the output above.") print("Generating solution has failed!") sys.exit(1) if open_gui: open_cmake_gui(cmakelists_dir, solution_path)