Skip to content

Commit a90ec5d

Browse files
authored
Feature/cmake tests (#120)
adds `ctest` support
1 parent c4e6713 commit a90ec5d

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

AGENTS.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,27 @@
44
- A bug in some LLM coding environments makes Bazel difficult to use, so agents should rely on CMake.
55
- Keep both the CMake and Bazel builds working at all times.
66

7+
## Building with CMake
8+
9+
When building with CMake, use parallel flags to speed up the process.
10+
11+
- When using `cmake --build`, add the `--parallel` flag.
12+
- When using `make`, add the `-j` flag (e.g., `make -j$(nproc)`).
13+
14+
## Running Tests with CMake
15+
16+
To run the tests, execute the following commands from the root of the repository:
17+
18+
```bash
19+
mkdir -p build
20+
cd build
21+
cmake ..
22+
cmake --build . --parallel
23+
ctest
24+
```
25+
26+
27+
728
## Building the Python Wheel
829

930
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.

CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ FetchContent_Declare(
5858
set(PYBIND11_TEST OFF CACHE BOOL "" FORCE)
5959
FetchContent_MakeAvailable(pybind11)
6060

61+
# Google Test
62+
FetchContent_Declare(
63+
googletest
64+
GIT_REPOSITORY https://github.com/google/googletest.git
65+
GIT_TAG release-1.12.1
66+
)
67+
FetchContent_MakeAvailable(googletest)
68+
69+
6170
set(OPT_COPTS -Ofast -fno-fast-math -march=native)
6271

6372
set(TESSERACT_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
@@ -111,3 +120,14 @@ set_target_properties(tesseract_decoder PROPERTIES
111120
LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${PROJECT_SOURCE_DIR}/src
112121
)
113122

123+
# === Tests ===
124+
enable_testing()
125+
126+
add_executable(common_test ${TESSERACT_SRC_DIR}/common.test.cc)
127+
target_link_libraries(common_test PRIVATE common GTest::gtest_main)
128+
add_test(NAME common_test COMMAND common_test)
129+
130+
add_executable(tesseract_test ${TESSERACT_SRC_DIR}/tesseract.test.cc)
131+
target_link_libraries(tesseract_test PRIVATE tesseract_lib simplex GTest::gtest_main)
132+
add_test(NAME tesseract_test COMMAND tesseract_test)
133+

src/tesseract.pybind.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,6 @@ void add_tesseract_module(py::module& root) {
199199
`TesseractConfig` object.
200200
)pbdoc");
201201

202-
203-
204202
py::class_<TesseractDecoder>(m, "TesseractDecoder", R"pbdoc(
205203
A class that implements the Tesseract decoding algorithm.
206204

0 commit comments

Comments
 (0)