### Installing Main Target and C-Library Headers Source: https://github.com/rapidai/rapidocronnx/blob/main/CMakeLists.txt This snippet installs the `RapidOcrOnnx` target for export. If the `OCR_OUTPUT` is set to 'CLIB' (C-Library), it also collects all header files from the `include` directory and installs them to the `include` destination, making them available for other projects linking against the C-Library. ```CMake install(TARGETS RapidOcrOnnx EXPORT RapidOcrOnnx) if (OCR_OUTPUT STREQUAL "CLIB") # CLIB file(GLOB OCR_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h) install(FILES ${OCR_INCLUDE} DESTINATION include) endif () ``` -------------------------------- ### Installing Build Essentials on Linux (Ubuntu) Source: https://github.com/rapidai/rapidocronnx/blob/main/BUILD.md This command installs the build-essential package on Ubuntu, which includes compilers and other tools necessary for building software from source. ```Shell sudo apt-get install build-essential ``` -------------------------------- ### Installing libomp on macOS via HomeBrew Source: https://github.com/rapidai/rapidocronnx/blob/main/BUILD.md This command uses HomeBrew to install libomp, an OpenMP runtime library, which is a dependency for compilation on macOS. ```Shell brew install libomp ``` -------------------------------- ### Installing Xcode Command Line Tools on macOS Source: https://github.com/rapidai/rapidocronnx/blob/main/BUILD.md This command installs the Xcode Command Line Tools, which are essential for compilation on macOS. It should be run in the terminal. ```Shell xcode-select –install ``` -------------------------------- ### Compiling and Installing Benchmark Executable Source: https://github.com/rapidai/rapidocronnx/blob/main/CMakeLists.txt This conditional block compiles and installs a benchmark executable if `OCR_BENCHMARK` is enabled and `OCR_OUTPUT` is 'BIN'. It defines the `benchmark` executable with its specific source files, links OnnxRuntime and OpenCV, and adds an `__EXEC__` definition. If CUDA is the OnnxRuntime backend, `__CUDA__` is also defined for the benchmark. Finally, it installs the benchmark target to specified destinations. ```CMake if (OCR_BENCHMARK AND (OCR_OUTPUT STREQUAL "BIN")) add_executable(benchmark benchmark/benchmark.cpp src/AngleNet.cpp src/clipper.cpp src/CrnnNet.cpp src/DbNet.cpp src/getopt.cpp src/OcrLiteImpl.cpp src/OcrLite.cpp src/OcrUtils.cpp) target_link_libraries(benchmark ${OnnxRuntime_LIBS} ${OpenCV_LIBS}) target_compile_definitions(benchmark PRIVATE __EXEC__) if (OCR_ONNX STREQUAL "CUDA") target_compile_definitions(benchmark PRIVATE __CUDA__) endif () install(TARGETS benchmark EXPORT benchmark ARCHIVE DESTINATION staticlib LIBRARY DESTINATION sharedlib RUNTIME DESTINATION bin) endif () ``` -------------------------------- ### Setting JAVA_HOME Environment Variable on macOS Source: https://github.com/rapidai/rapidocronnx/blob/main/BUILD.md This command sets the JAVA_HOME environment variable in the .zshrc file, pointing to the Java installation directory. This is required for building the JNI dynamic library. ```Shell export JAVA_HOME=$(/usr/libexec/java_home) ``` -------------------------------- ### Building RapidOcrOnnx Executable on Linux Source: https://github.com/rapidai/rapidocronnx/blob/main/BUILD.md This command initiates the build process for the RapidOcrOnnx executable on Linux using the build.sh script. Users are prompted to select options, ultimately choosing 'BIN可执行文件' (BIN executable file). ```Shell ./build.sh ``` -------------------------------- ### Building RapidOcrOnnx Executable on Windows (nmake) Source: https://github.com/rapidai/rapidocronnx/blob/main/BUILD.md This command initiates the build process for the RapidOcrOnnx executable on Windows using the build.bat script. Users are prompted to select options, ultimately choosing 'BIN可执行文件' (BIN executable file). ```Batch build.bat ``` -------------------------------- ### Building RapidOcrOnnx Executable on macOS Source: https://github.com/rapidai/rapidocronnx/blob/main/BUILD.md This command initiates the build process for the RapidOcrOnnx executable on macOS using the build.sh script. Users are prompted to select options, ultimately choosing 'BIN可执行文件' (BIN executable file). ```Shell ./build.sh ``` -------------------------------- ### Configuring Project Includes and Source Files Source: https://github.com/rapidai/rapidocronnx/blob/main/CMakeLists.txt This snippet adds the project's `include` directory to the search paths for headers. It then uses `file(GLOB)` to collect all `.cpp` source files from the `src` directory and stores them in the `OCR_SRC` variable, which is then assigned to `OCR_COMPILE_CODE` for compilation. ```CMake include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) file(GLOB OCR_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp) set(OCR_COMPILE_CODE ${OCR_SRC}) ``` -------------------------------- ### Building RapidOcrOnnx JNI Library on Windows (nmake) Source: https://github.com/rapidai/rapidocronnx/blob/main/BUILD.md This command initiates the build process for the RapidOcrOnnx JNI dynamic library on Windows using the build.bat script. Users are prompted to select options, ultimately choosing 'JNI动态库' (JNI dynamic library). ```Batch build.bat ``` -------------------------------- ### Running Tests for RapidOcrOnnx on Windows (nmake) Source: https://github.com/rapidai/rapidocronnx/blob/main/BUILD.md This command executes the test script run-test.bat after compilation on Windows. Users must modify the script to specify the target image path for testing. ```Batch run-test.bat ``` -------------------------------- ### Defining Build Target Based on Output Type Source: https://github.com/rapidai/rapidocronnx/blob/main/CMakeLists.txt This crucial snippet defines the main build target `RapidOcrOnnx` based on the `OCR_OUTPUT` variable. It creates a shared library for JNI or C-Library outputs, adding specific compile definitions and linking JNI, OnnxRuntime, and OpenCV libraries. For 'BIN' output, it creates an executable with appropriate definitions and links OnnxRuntime and OpenCV. ```CMake if (OCR_OUTPUT STREQUAL "JNI") # JNI add_library(RapidOcrOnnx SHARED ${OCR_COMPILE_CODE}) target_compile_definitions(RapidOcrOnnx PRIVATE __JNI__) target_link_libraries(RapidOcrOnnx ${OnnxRuntime_LIBS} ${OpenCV_LIBS} ${JNI_LIBS}) elseif (OCR_OUTPUT STREQUAL "CLIB") # CLIB add_library(RapidOcrOnnx SHARED ${OCR_COMPILE_CODE}) target_compile_definitions(RapidOcrOnnx PRIVATE __CLIB__) target_link_libraries(RapidOcrOnnx ${OnnxRuntime_LIBS} ${OpenCV_LIBS}) elseif (OCR_OUTPUT STREQUAL "BIN") # BIN add_executable(RapidOcrOnnx ${OCR_COMPILE_CODE}) target_compile_definitions(RapidOcrOnnx PRIVATE __EXEC__) target_link_libraries(RapidOcrOnnx ${OnnxRuntime_LIBS} ${OpenCV_LIBS}) endif () ``` -------------------------------- ### Configuring Build Output Type and Benchmark Option Source: https://github.com/rapidai/rapidocronnx/blob/main/CMakeLists.txt This section initializes the `OCR_OUTPUT` variable to 'BIN' if it's not already defined, determining the final build artifact type (e.g., executable, shared library). It also defines and enables the `OCR_BENCHMARK` option, allowing for the compilation of a benchmark executable. ```CMake if (NOT DEFINED OCR_OUTPUT) set(OCR_OUTPUT "BIN") message(STATUS "No OCR_OUTPUT, defaulting to BIN") endif () option(OCR_BENCHMARK "build benchmark" ON) set(OCR_BENCHMARK ON) ``` -------------------------------- ### Running Tests for RapidOcrOnnx on Linux Source: https://github.com/rapidai/rapidocronnx/blob/main/BUILD.md This command executes the test script run-test.sh after compilation on Linux. Users must modify the script to specify the target image path for testing. ```Shell ./run-test.sh ``` -------------------------------- ### Integrating and Verifying OnnxRuntime Dependency Source: https://github.com/rapidai/rapidocronnx/blob/main/CMakeLists.txt This snippet conditionally includes the appropriate OnnxRuntime wrapper CMake file based on the selected backend (CPU, CUDA, or DIRECTML). It then attempts to find the OnnxRuntime package and, if found, prints its library and include directories; otherwise, it terminates with a fatal error. ```CMake if (OCR_ONNX STREQUAL "CPU") include(${CMAKE_CURRENT_SOURCE_DIR}/onnxruntime-static/OnnxRuntimeWrapper.cmake) elseif (OCR_ONNX STREQUAL "CUDA") # CUDA include(${CMAKE_CURRENT_SOURCE_DIR}/onnxruntime-gpu/OnnxRuntimeWrapper.cmake) elseif (OCR_ONNX STREQUAL "DIRECTML") # DIRECTML include(${CMAKE_CURRENT_SOURCE_DIR}/onnxruntime-DirectML/OnnxRuntimeWrapper.cmake) endif () find_package(OnnxRuntime REQUIRED) if (OnnxRuntime_FOUND) message(STATUS "OnnxRuntime_LIBS: ${OnnxRuntime_LIBS}") message(STATUS "OnnxRuntime_INCLUDE_DIRS: ${OnnxRuntime_INCLUDE_DIRS}") else () message(FATAL_ERROR "onnxruntime Not Found!") endif (OnnxRuntime_FOUND) ``` -------------------------------- ### Onnxruntime Static Library Directory Structure Source: https://github.com/rapidai/rapidocronnx/blob/main/BUILD.md This snippet illustrates the expected directory structure after extracting the Onnxruntime static library package. It shows the OnnxRuntimeWrapper.cmake file and platform-specific subdirectories for Linux, macOS, Windows-x64, and Windows-x86. ```Directory Structure onnxruntime-static ├── OnnxRuntimeWrapper.cmake ├── linux ├── macos ├── windows-x64 └── windows-x86 ``` -------------------------------- ### Running Tests for RapidOcrOnnx on macOS Source: https://github.com/rapidai/rapidocronnx/blob/main/BUILD.md This command executes the test script run-test.sh after compilation on macOS. Users must modify the script to specify the target image path for testing. ```Shell ./run-test.sh ``` -------------------------------- ### Integrating and Verifying OpenCV Dependency Source: https://github.com/rapidai/rapidocronnx/blob/main/CMakeLists.txt This section sets `BUILD_SHARED_LIBS` to false, ensuring static linking for OpenCV. It includes a custom OpenCV wrapper configuration and then attempts to find the OpenCV package. If found, it displays the library and include paths; otherwise, it halts the build with an error. ```CMake set(BUILD_SHARED_LIBS false) include(${CMAKE_CURRENT_SOURCE_DIR}/opencv-static/OpenCVWrapperConfig.cmake) find_package(OpenCV REQUIRED) if (OpenCV_FOUND) message(STATUS "OpenCV_LIBS: ${OpenCV_LIBS}") message(STATUS "OpenCV_INCLUDE_DIRS: ${OpenCV_INCLUDE_DIRS}") else () message(FATAL_ERROR "opencv Not Found!") endif (OpenCV_FOUND) ``` -------------------------------- ### Building RapidOcrOnnx JNI Library on Linux Source: https://github.com/rapidai/rapidocronnx/blob/main/BUILD.md This command initiates the build process for the RapidOcrOnnx JNI dynamic library on Linux using the build.sh script. Users are prompted to select options, ultimately choosing 'JNI动态库' (JNI dynamic library). Note that g++ version 6 or higher is required for JNI compilation. ```Shell build.sh ``` -------------------------------- ### Building RapidOcrOnnx JNI Library on macOS Source: https://github.com/rapidai/rapidocronnx/blob/main/BUILD.md This command initiates the build process for the RapidOcrOnnx JNI dynamic library on macOS using the build.sh script. Users are prompted to select options, ultimately choosing 'JNI动态库' (JNI dynamic library). ```Shell build.sh ``` -------------------------------- ### Adding Compiler Definitions and Build Type Flags Source: https://github.com/rapidai/rapidocronnx/blob/main/CMakeLists.txt This section adds global compiler definitions for Unicode support (`-DUNICODE -D_UNICODE`). It then conditionally adds build flags: for 'Debug' builds, it includes warnings, debug info, and no optimization; for other build types, it only includes warnings. ```CMake add_definitions(-DUNICODE -D_UNICODE) if (CMAKE_BUILD_TYPE STREQUAL "Debug") add_definitions("-Wall -g -O0") else () add_definitions("-Wall") endif () ``` -------------------------------- ### OpenCV Static Library Directory Structure Source: https://github.com/rapidai/rapidocronnx/blob/main/BUILD.md This snippet illustrates the expected directory structure after extracting the OpenCV static library package. It shows the OpenCVWrapperConfig.cmake file and platform-specific subdirectories for Linux, macOS, Windows-x64, and Windows-x86. ```Directory Structure opencv-static ├── OpenCVWrapperConfig.cmake ├── linux ├── macos ├── windows-x64 └── windows-x86 ``` -------------------------------- ### Adding OnnxRuntime Backend Specific Compile Definitions Source: https://github.com/rapidai/rapidocronnx/blob/main/CMakeLists.txt This snippet adds specific private compile definitions to the `RapidOcrOnnx` target based on the chosen OnnxRuntime backend. If `OCR_ONNX` is 'CUDA', `__CUDA__` is defined; if 'DIRECTML', `__DIRECTML__` is defined. These definitions enable backend-specific code paths within the project. ```CMake if (OCR_ONNX STREQUAL "CUDA") target_compile_definitions(RapidOcrOnnx PRIVATE __CUDA__) elseif(OCR_ONNX STREQUAL "DIRECTML") target_compile_definitions(RapidOcrOnnx PRIVATE __DIRECTML__) endif () ``` -------------------------------- ### Setting Default OnnxRuntime Backend Source: https://github.com/rapidai/rapidocronnx/blob/main/CMakeLists.txt This snippet checks if the `OCR_ONNX` variable is defined. If not, it defaults the OnnxRuntime backend to 'CPU', indicating that the CPU version of OnnxRuntime will be used for inference. This ensures a default operational mode if no specific backend is chosen. ```CMake if (NOT DEFINED OCR_ONNX) set(OCR_ONNX "CPU") message(STATUS "No OCR_ONNX, defaulting to CPU") endif () ``` -------------------------------- ### Configuring JNI Dependency for Java Native Interface Source: https://github.com/rapidai/rapidocronnx/blob/main/CMakeLists.txt This block handles the integration of JNI (Java Native Interface) if the `OCR_OUTPUT` is set to 'JNI'. It attempts to find the JNI package, and if successful, it prints the JNI library and include directories and adds them to the project's include paths. A fatal error is issued if JNI is not found. ```CMake if (OCR_OUTPUT STREQUAL "JNI") find_package(JNI REQUIRED) if (JNI_FOUND) message("JNI FOUND") message(STATUS "JNI_LIBS: ${JNI_LIBS}") message(STATUS "JNI_INCLUDE_DIRS: ${JNI_INCLUDE_DIRS}") include_directories(${JNI_INCLUDE_DIRS}) else () message(FATAL_ERROR "JNI Not Found!") endif () endif () ``` -------------------------------- ### Setting CMake Minimum Version and Project Name Source: https://github.com/rapidai/rapidocronnx/blob/main/CMakeLists.txt This snippet sets the minimum required CMake version based on the operating system (Windows, Apple, or Unix) to ensure compatibility. It then defines the project name as 'RapidOcrOnnx', which is crucial for CMake to manage the build system. ```CMake if (WIN32) cmake_minimum_required(VERSION 3.12) elseif (APPLE) cmake_minimum_required(VERSION 3.17) elseif (UNIX) cmake_minimum_required(VERSION 3.17) endif () project(RapidOcrOnnx) ``` -------------------------------- ### Conditional Windows CRT Linkage Source: https://github.com/rapidai/rapidocronnx/blob/main/CMakeLists.txt This snippet conditionally includes an external CMake file, `OcrCRTLinkage.cmake`, if the `OCR_BUILD_CRT` variable is explicitly set to 'True'. This is typically used on Windows to manage the C Runtime Library linkage, ensuring correct runtime behavior and avoiding conflicts. ```CMake if (OCR_BUILD_CRT STREQUAL "True") include(${CMAKE_CURRENT_SOURCE_DIR}/OcrCRTLinkage.cmake) endif () ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.