cmake_minimum_required(VERSION 3.18) project(cpp_tracker LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) # Look for existing LibTorch installation (for systems with PyTorch already installed) list(APPEND CMAKE_PREFIX_PATH "/usr/local/libtorch" "$ENV{HOME}/libtorch") # Find dependencies find_package(Torch REQUIRED) message(STATUS "Found LibTorch: ${TORCH_LIBRARIES}") # Determine whether to use CPU-only or CUDA implementation option(CPU_ONLY "Build without CUDA support" TRUE) if(CPU_ONLY) message(STATUS "Building in CPU-only mode") add_definitions(-DCPU_ONLY) else() message(STATUS "Building with CUDA support") endif() # Define source files for the libraries set(BB_REGRESSOR_SOURCES cimp/bb_regressor/bb_regressor.cpp ) set(CLASSIFIER_SOURCES cimp/classifier/classifier.cpp ) # Create static libraries add_library(bb_regressor STATIC ${BB_REGRESSOR_SOURCES}) add_library(classifier STATIC ${CLASSIFIER_SOURCES}) # Set include directories target_include_directories(bb_regressor PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/cimp ${CMAKE_CURRENT_SOURCE_DIR}/cimp/bb_regressor/prroi_pooling ${CMAKE_CURRENT_SOURCE_DIR}/ltr/external/PreciseRoIPooling/pytorch/prroi_pool/src ) target_include_directories(classifier PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/cimp) # Link with LibTorch target_link_libraries(bb_regressor PRIVATE ${TORCH_LIBRARIES}) target_link_libraries(classifier PRIVATE ${TORCH_LIBRARIES}) # Create the demo executable add_executable(tracking_demo cimp/demo.cpp) # Link the demo with the libraries target_link_libraries(tracking_demo PRIVATE bb_regressor classifier ${TORCH_LIBRARIES}) # Copy the executable to the binary directory install(TARGETS tracking_demo DESTINATION bin) # Print some info during the build message(STATUS "LibTorch found at: ${TORCH_INCLUDE_DIRS}") if(CPU_ONLY) message(STATUS "Using CPU-only build") else() message(STATUS "Using CUDA-enabled build") endif()