(build_dir: PathLike, trt_dir: PathLike,
enable_multi_device: str, loglevel: int)
| 21 | |
| 22 | |
| 23 | def build_cpp_examples(build_dir: PathLike, trt_dir: PathLike, |
| 24 | enable_multi_device: str, loglevel: int) -> None: |
| 25 | logging.basicConfig(level=loglevel, |
| 26 | format='%(asctime)s - %(levelname)s - %(message)s') |
| 27 | # Convert input paths to pathlib.Path objects |
| 28 | build_dir = Path(build_dir) |
| 29 | trt_dir = Path(trt_dir) |
| 30 | |
| 31 | assert trt_dir.is_dir() |
| 32 | |
| 33 | def cmake_parse(path: PathLike) -> str: |
| 34 | return str(path).replace("\\", "/") |
| 35 | |
| 36 | # Remove the build directory if it exists |
| 37 | if build_dir.exists(): |
| 38 | logging.info(f"Removed directory: {build_dir}") |
| 39 | shutil.rmtree(build_dir) |
| 40 | |
| 41 | # Create the build directory |
| 42 | build_dir.mkdir(parents=True, exist_ok=True) |
| 43 | |
| 44 | # Change to the build directory |
| 45 | with working_directory(build_dir): |
| 46 | # Run CMake with the specified TensorRT directories |
| 47 | generator = ["-GNinja"] if platform.system() == "Windows" else [] |
| 48 | generate_command = [ |
| 49 | 'cmake', |
| 50 | '-S', |
| 51 | '..', |
| 52 | '-B', |
| 53 | '.', |
| 54 | f'-DTensorRT_ROOT={cmake_parse(trt_dir)}', |
| 55 | f'-DENABLE_MULTI_DEVICE={enable_multi_device}', |
| 56 | ] + generator |
| 57 | logging.info(f"Executing {generate_command}") |
| 58 | subprocess.run(generate_command, check=True) |
| 59 | |
| 60 | # Build the project using make |
| 61 | build_command = ["cmake", "--build", ".", "--config", "Release"] |
| 62 | logging.info(f"Executing {build_command}") |
| 63 | subprocess.run(build_command, check=True) |
| 64 | |
| 65 | |
| 66 | if __name__ == '__main__': |
no test coverage detected