|
| 1 | +cmake_minimum_required(VERSION 3.16) |
| 2 | +project(tesseract_decoder LANGUAGES CXX) |
| 3 | + |
| 4 | +set(CMAKE_CXX_STANDARD 20) |
| 5 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 6 | + |
| 7 | +include(FetchContent) |
| 8 | +find_package(Threads REQUIRED) |
| 9 | + |
| 10 | +# === External dependencies === |
| 11 | +# Stim |
| 12 | +FetchContent_Declare( |
| 13 | + stim |
| 14 | + GIT_REPOSITORY https://github.com/quantumlib/stim.git |
| 15 | + GIT_TAG bd60b73525fd5a9b30839020eb7554ad369e4337 |
| 16 | +) |
| 17 | +FetchContent_MakeAvailable(stim) |
| 18 | + |
| 19 | +# HiGHS |
| 20 | +FetchContent_Declare( |
| 21 | + highs |
| 22 | + URL https://github.com/ERGO-Code/HiGHS/archive/refs/tags/v1.9.0.tar.gz |
| 23 | + URL_HASH SHA256=dff575df08d88583c109702c7c5c75ff6e51611e6eacca8b5b3fdfba8ecc2cb4 |
| 24 | +) |
| 25 | +FetchContent_MakeAvailable(highs) |
| 26 | + |
| 27 | +# argparse (header only) |
| 28 | +FetchContent_Declare( |
| 29 | + argparse |
| 30 | + URL https://github.com/p-ranav/argparse/archive/refs/tags/v3.1.zip |
| 31 | + URL_HASH SHA256=3e5a59ab7688dcd1f918bc92051a10564113d4f36c3bbed3ef596c25e519a062 |
| 32 | +) |
| 33 | +FetchContent_MakeAvailable(argparse) |
| 34 | + |
| 35 | +# nlohmann_json (header only) |
| 36 | +FetchContent_Declare( |
| 37 | + nlohmann_json |
| 38 | + URL https://github.com/nlohmann/json/archive/9cca280a4d0ccf0c08f47a99aa71d1b0e52f8d03.zip |
| 39 | +) |
| 40 | +FetchContent_MakeAvailable(nlohmann_json) |
| 41 | + |
| 42 | +# Boost headers |
| 43 | +FetchContent_Declare( |
| 44 | + boost |
| 45 | + URL https://archives.boost.io/release/1.83.0/source/boost_1_83_0.tar.gz |
| 46 | + URL_HASH SHA256=c0685b68dd44cc46574cce86c4e17c0f611b15e195be9848dfd0769a0a207628 |
| 47 | +) |
| 48 | +FetchContent_MakeAvailable(boost) |
| 49 | +add_library(boost_headers INTERFACE) |
| 50 | +target_include_directories(boost_headers INTERFACE ${boost_SOURCE_DIR}) |
| 51 | + |
| 52 | +# pybind11 |
| 53 | +FetchContent_Declare( |
| 54 | + pybind11 |
| 55 | + GIT_REPOSITORY https://github.com/pybind/pybind11.git |
| 56 | + GIT_TAG v2.11.1 |
| 57 | +) |
| 58 | +set(PYBIND11_TEST OFF CACHE BOOL "" FORCE) |
| 59 | +FetchContent_MakeAvailable(pybind11) |
| 60 | + |
| 61 | +set(OPT_COPTS -Ofast -fno-fast-math -march=native) |
| 62 | + |
| 63 | +set(TESSERACT_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src) |
| 64 | + |
| 65 | +# === Libraries === |
| 66 | +add_library(common ${TESSERACT_SRC_DIR}/common.cc ${TESSERACT_SRC_DIR}/common.h) |
| 67 | +target_include_directories(common PUBLIC ${TESSERACT_SRC_DIR}) |
| 68 | +target_compile_options(common PRIVATE ${OPT_COPTS}) |
| 69 | +target_link_libraries(common PUBLIC libstim Threads::Threads) |
| 70 | + |
| 71 | +add_library(utils ${TESSERACT_SRC_DIR}/utils.cc ${TESSERACT_SRC_DIR}/utils.h) |
| 72 | +target_include_directories(utils PUBLIC ${TESSERACT_SRC_DIR}) |
| 73 | +target_compile_options(utils PRIVATE ${OPT_COPTS}) |
| 74 | +target_link_libraries(utils PUBLIC common libstim Threads::Threads) |
| 75 | + |
| 76 | +add_library(tesseract_lib ${TESSERACT_SRC_DIR}/tesseract.cc ${TESSERACT_SRC_DIR}/tesseract.h) |
| 77 | +target_include_directories(tesseract_lib PUBLIC ${TESSERACT_SRC_DIR}) |
| 78 | +target_compile_options(tesseract_lib PRIVATE ${OPT_COPTS}) |
| 79 | +target_link_libraries(tesseract_lib PUBLIC utils boost_headers) |
| 80 | + |
| 81 | +add_library(simplex ${TESSERACT_SRC_DIR}/simplex.cc ${TESSERACT_SRC_DIR}/simplex.h) |
| 82 | +target_include_directories(simplex PUBLIC ${TESSERACT_SRC_DIR}) |
| 83 | +target_compile_options(simplex PRIVATE ${OPT_COPTS}) |
| 84 | +target_link_libraries(simplex PUBLIC common utils tesseract_lib highs libstim Threads::Threads) |
| 85 | + |
| 86 | +# === Executables === |
| 87 | +add_executable(tesseract ${TESSERACT_SRC_DIR}/tesseract_main.cc) |
| 88 | +target_compile_options(tesseract PRIVATE ${OPT_COPTS}) |
| 89 | +target_link_libraries(tesseract PRIVATE tesseract_lib argparse::argparse nlohmann_json::nlohmann_json) |
| 90 | + |
| 91 | +add_executable(simplex_bin ${TESSERACT_SRC_DIR}/simplex_main.cc) |
| 92 | +set_target_properties(simplex_bin PROPERTIES OUTPUT_NAME simplex) |
| 93 | +target_compile_options(simplex_bin PRIVATE ${OPT_COPTS}) |
| 94 | +target_link_libraries(simplex_bin PRIVATE common simplex argparse::argparse nlohmann_json::nlohmann_json) |
| 95 | + |
| 96 | +# === Python module === |
| 97 | +pybind11_add_module(tesseract_decoder MODULE ${TESSERACT_SRC_DIR}/tesseract.pybind.cc) |
| 98 | +target_compile_options(tesseract_decoder PRIVATE ${OPT_COPTS}) |
| 99 | +target_include_directories(tesseract_decoder PRIVATE ${TESSERACT_SRC_DIR}) |
| 100 | +target_link_libraries(tesseract_decoder PRIVATE common utils simplex tesseract_lib) |
| 101 | + |
0 commit comments