cmake_minimum_required(VERSION 3.18) project(ImageSimilarityTracker LANGUAGES CXX CUDA) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED True) # --- vcpkg integration --- # If vcpkg.json is present in the root, and CMAKE_TOOLCHAIN_FILE is set (by build.sh or environment) # to point to vcpkg.cmake, dependencies listed in vcpkg.json (like opencv4) will be automatically # found and linked by CMake. We don't need explicit find_package(OpenCV) here anymore if vcpkg handles it. # Find LibTorch (should be set by build.sh via Torch_DIR or CMAKE_PREFIX_PATH) find_package(Torch REQUIRED) # OpenCV should be provided by vcpkg if vcpkg.json lists it and toolchain is used. # Remove explicit find_package for OpenCV as vcpkg will provide it. # find_package(OpenCV REQUIRED) message(STATUS "Found LibTorch: ${TORCH_LIBRARIES}") # message(STATUS "Found OpenCV: ${OpenCV_LIBS}") # OpenCV_LIBS will be available if vcpkg succeeds # Always use CUDA implementation (no CPU fallback) message(STATUS "Building with CUDA support") # Define source files for the libraries set(BB_REGRESSOR_SOURCES cimp/bb_regressor/bb_regressor.cpp cimp/bb_regressor/prroi_pooling/prroi_pooling_gpu_impl.cu cimp/bb_regressor/utils.cpp ) set(CLASSIFIER_SOURCES cimp/classifier/classifier.cpp ) set(RESNET_SOURCES cimp/resnet/resnet.cpp ) set(DIMP_TRACKER_SOURCES cimp/dimp_tracker.cpp ) # Create static libraries add_library(bb_regressor STATIC ${BB_REGRESSOR_SOURCES}) add_library(classifier STATIC ${CLASSIFIER_SOURCES}) add_library(resnet STATIC ${RESNET_SOURCES}) add_library(dimp_tracker STATIC ${DIMP_TRACKER_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) target_include_directories(resnet PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/cimp) target_include_directories(dimp_tracker PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/cimp) # Link with LibTorch target_link_libraries(bb_regressor PRIVATE ${TORCH_LIBRARIES}) target_link_libraries(classifier PRIVATE ${TORCH_LIBRARIES}) target_link_libraries(resnet PRIVATE ${TORCH_LIBRARIES}) target_link_libraries(dimp_tracker 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 resnet dimp_tracker ${TORCH_LIBRARIES}) # Create the test models executable add_executable(test_models test/test_models.cpp) # Link the test_models with the libraries target_link_libraries(test_models PRIVATE bb_regressor classifier resnet dimp_tracker ${TORCH_LIBRARIES}) # Create the test sample generator executable (without dependencies on our libraries) # add_executable(generate_test_samples ${CMAKE_CURRENT_SOURCE_DIR}/test/generate_test_samples.cpp) # COMMENTED OUT # target_link_libraries(generate_test_samples PRIVATE ${TORCH_LIBRARIES}) # COMMENTED OUT # Copy the executable to the binary directory install(TARGETS tracking_demo DESTINATION bin) install(TARGETS test_models DESTINATION bin) # install(TARGETS generate_test_samples DESTINATION bin) # COMMENTED OUT # Print some info during the build message(STATUS "LibTorch found at: ${TORCH_INCLUDE_DIRS}") message(STATUS "Using CUDA-enabled build") # --- Installation --- # Define where to install the executables and libraries set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install) # Install locally within the build directory install(TARGETS test_models # generate_test_samples # COMMENTED OUT RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib ) install(TARGETS resnet classifier bb_regressor dimp_tracker LIBRARY DESTINATION lib ARCHIVE DESTINATION lib ) # Install PyTorch and OpenCV shared libraries that our targets link against. if(TORCH_LIBRARIES) if(WIN32) set(LIBTORCH_DLL_DIR "${Torch_DIR}/../lib") else() set(LIBTORCH_DLL_DIR "${Torch_DIR}/../lib") # Usually $HOME/libtorch_version/libtorch/lib endif() message(STATUS "Attempting to install Torch shared libs from: ${LIBTORCH_DLL_DIR}") install(DIRECTORY ${LIBTORCH_DLL_DIR}/ DESTINATION lib USE_SOURCE_PERMISSIONS OPTIONAL FILES_MATCHING PATTERN "*.so*" PATTERN "*.dylib*" PATTERN "*.dll" PATTERN "c10*.dll" PATTERN "torch_cpu*.dll" PATTERN "torch_cuda*.dll" PATTERN "torch.dll" PATTERN "cudnn*.dll" # Add cuDNN if it's part of LibTorch distribution ) else() message(WARNING "TORCH_LIBRARIES not set, cannot install PyTorch shared libraries.") endif() # If using vcpkg, it usually handles its own dependencies' deployment or they are statically linked. # If OpenCV shared libraries need to be deployed and are not handled by vcpkg install component or not part of LibTorch distribution: # You might need to explicitly find OpenCV shared library paths and install them if vcpkg doesn't put them in a common place with Torch. # Example (very dependent on how OpenCV is found/provided): # if(OpenCV_FOUND AND OpenCV_SHARED_LIBS_DIR) # Assume OpenCV_SHARED_LIBS_DIR is set if needed # install(DIRECTORY ${OpenCV_SHARED_LIBS_DIR}/ # DESTINATION lib # FILES_MATCHING PATTERN "*.so*" PATTERN "*.dylib*" PATTERN "*.dll" # USE_SOURCE_PERMISSIONS # OPTIONAL) # endif() # Enable CTest enable_testing() # Define a simple test that runs the test_models executable # The actual test logic (passing arguments, checking output) is in run_tests.sh add_test( NAME RunCppModelTests COMMAND test_models dummy_arg1 dummy_arg2 dummy_arg3 # Dummy args, real ones from run_tests.sh WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin )