From 45b23b9ab864c569734fb7b4a1c48bd4e760fe5a Mon Sep 17 00:00:00 2001 From: Peter Spalthoff Date: Tue, 12 Jul 2022 14:04:17 +0900 Subject: [PATCH 1/5] Cmake include path fixes Avoid PROJECT_SOURCE_DIR in case library is used as subproject. --- CMakeLists.txt | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f20ebd8..92c8802 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,20 +26,18 @@ if(NOT EIGEN3_FOUND) message(FATAL_ERROR "Eigen > 3.3.0 not found.") endif() -include_directories( - ${PROJECT_SOURCE_DIR}/include - ${EIGEN3_INCLUDE_DIR} - ) - add_library(${PROJECT_NAME} SHARED - ${PROJECT_SOURCE_DIR}/src/BYTETracker.cpp - ${PROJECT_SOURCE_DIR}/src/KalmanFilter.cpp - ${PROJECT_SOURCE_DIR}/src/lapjv.cpp - ${PROJECT_SOURCE_DIR}/src/Object.cpp - ${PROJECT_SOURCE_DIR}/src/Rect.cpp - ${PROJECT_SOURCE_DIR}/src/STrack.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/BYTETracker.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/KalmanFilter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/lapjv.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/Object.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/Rect.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/STrack.cpp + ) +target_include_directories(${PROJECT_NAME} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${EIGEN3_INCLUDE_DIR} ) - target_link_libraries(${PROJECT_NAME} ${EIGEN3_LIBS} ) @@ -55,7 +53,7 @@ if(BUILD_BYTETRACK_TEST) endif() add_executable(${PROJECT_NAME}_test - ${PROJECT_SOURCE_DIR}/test/test_BYTETracker.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/test/test_BYTETracker.cpp ) target_link_libraries(${PROJECT_NAME}_test From 88c86f9ca77e1db28f1033a4475169ce7985fced Mon Sep 17 00:00:00 2001 From: Peter Spalthoff Date: Tue, 12 Jul 2022 14:28:43 +0900 Subject: [PATCH 2/5] Link to Eigen3::Eigen instead of manually --- CMakeLists.txt | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 92c8802..463ee6e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,11 +36,8 @@ add_library(${PROJECT_NAME} SHARED ) target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include - ${EIGEN3_INCLUDE_DIR} - ) -target_link_libraries(${PROJECT_NAME} - ${EIGEN3_LIBS} ) +target_link_libraries(${PROJECT_NAME} Eigen3::Eigen) # Build the tests if the 'BUILD_BYTETRACK_TEST' variable is set to 'ON' set(BUILD_BYTETRACK_TEST OFF CACHE BOOL "The flag whether to build the tests or not") From 16288be9d3056822b8a57a6ad94a523d0698c3f0 Mon Sep 17 00:00:00 2001 From: Peter Spalthoff Date: Tue, 12 Jul 2022 14:42:13 +0900 Subject: [PATCH 3/5] Download of Eigen dependency if needed --- CMakeLists.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 463ee6e..2fb0787 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,7 +23,15 @@ endif() find_package(Eigen3 3.3.0 QUIET) if(NOT EIGEN3_FOUND) - message(FATAL_ERROR "Eigen > 3.3.0 not found.") + set(BUILD_TESTING OFF CACHE INTERNAL "") + FetchContent_Declare(eigen + GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git + GIT_TAG 3.3 + GIT_SHALLOW ON) + FetchContent_MakeAvailable(eigen) + unset(BUILD_TESTING CACHE) + FetchContent_GetProperties(eigen BINARY_DIR Eigen3_DIR) + find_package(Eigen3 3.3.0 REQUIRED) endif() add_library(${PROJECT_NAME} SHARED From 6f73e8a0012ed05ce71f59e7158eb888ed7d3f80 Mon Sep 17 00:00:00 2001 From: Peter Spalthoff Date: Tue, 12 Jul 2022 14:46:13 +0900 Subject: [PATCH 4/5] Add EIGEN_VERSION variable --- CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2fb0787..d831eab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,17 +21,18 @@ else() message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++17 support. Please use a different C++ compiler.") endif() -find_package(Eigen3 3.3.0 QUIET) +set(EIGEN_VERSION 3.3) +find_package(Eigen3 ${EIGEN_VERSION} QUIET) if(NOT EIGEN3_FOUND) set(BUILD_TESTING OFF CACHE INTERNAL "") FetchContent_Declare(eigen GIT_REPOSITORY https://gitlab.com/libeigen/eigen.git - GIT_TAG 3.3 + GIT_TAG ${EIGEN_VERSION} GIT_SHALLOW ON) FetchContent_MakeAvailable(eigen) unset(BUILD_TESTING CACHE) FetchContent_GetProperties(eigen BINARY_DIR Eigen3_DIR) - find_package(Eigen3 3.3.0 REQUIRED) + find_package(Eigen3 ${EIGEN_VERSION} REQUIRED) endif() add_library(${PROJECT_NAME} SHARED From 9e13f48c352732ad5b8651aad93a6ba00ffef5ea Mon Sep 17 00:00:00 2001 From: Peter Spalthoff Date: Tue, 12 Jul 2022 14:57:03 +0900 Subject: [PATCH 5/5] Avoid using find_package after FetchContent --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d831eab..7ccd9b3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,8 +31,6 @@ if(NOT EIGEN3_FOUND) GIT_SHALLOW ON) FetchContent_MakeAvailable(eigen) unset(BUILD_TESTING CACHE) - FetchContent_GetProperties(eigen BINARY_DIR Eigen3_DIR) - find_package(Eigen3 ${EIGEN_VERSION} REQUIRED) endif() add_library(${PROJECT_NAME} SHARED