diff --git a/AGENTS.md b/AGENTS.md index c0b30ad..dc7ddb2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -4,6 +4,27 @@ - A bug in some LLM coding environments makes Bazel difficult to use, so agents should rely on CMake. - Keep both the CMake and Bazel builds working at all times. +## Building with CMake + +When building with CMake, use parallel flags to speed up the process. + +- When using `cmake --build`, add the `--parallel` flag. +- When using `make`, add the `-j` flag (e.g., `make -j$(nproc)`). + +## Running Tests with CMake + +To run the tests, execute the following commands from the root of the repository: + +```bash +mkdir -p build +cd build +cmake .. +cmake --build . --parallel +ctest +``` + + + ## Building the Python Wheel To build the Python wheel for `tesseract_decoder` locally, you will need to use the `bazel build` command and provide the version and Python target version as command-line arguments. This is because the `py_wheel` rule in the `BUILD` file uses "Make" variable substitution, which expects these values to be defined at build time. diff --git a/CMakeLists.txt b/CMakeLists.txt index 10e5ea6..817ccda 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,6 +58,15 @@ FetchContent_Declare( set(PYBIND11_TEST OFF CACHE BOOL "" FORCE) FetchContent_MakeAvailable(pybind11) +# Google Test +FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG release-1.12.1 +) +FetchContent_MakeAvailable(googletest) + + set(OPT_COPTS -Ofast -fno-fast-math -march=native) set(TESSERACT_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) @@ -111,3 +120,14 @@ set_target_properties(tesseract_decoder PROPERTIES LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${PROJECT_SOURCE_DIR}/src ) +# === Tests === +enable_testing() + +add_executable(common_test ${TESSERACT_SRC_DIR}/common.test.cc) +target_link_libraries(common_test PRIVATE common GTest::gtest_main) +add_test(NAME common_test COMMAND common_test) + +add_executable(tesseract_test ${TESSERACT_SRC_DIR}/tesseract.test.cc) +target_link_libraries(tesseract_test PRIVATE tesseract_lib simplex GTest::gtest_main) +add_test(NAME tesseract_test COMMAND tesseract_test) + diff --git a/src/tesseract.pybind.h b/src/tesseract.pybind.h index df17a0c..5a68648 100644 --- a/src/tesseract.pybind.h +++ b/src/tesseract.pybind.h @@ -199,8 +199,6 @@ void add_tesseract_module(py::module& root) { `TesseractConfig` object. )pbdoc"); - - py::class_(m, "TesseractDecoder", R"pbdoc( A class that implements the Tesseract decoding algorithm.