From fb0b900a805095586945b0bb0af8b8fcaf0a6b0e Mon Sep 17 00:00:00 2001 From: feihongxu0824 Date: Wed, 4 Mar 2026 20:01:52 +0800 Subject: [PATCH] fix(build): replace CMAKE_SOURCE_DIR with PROJECT_ROOT_DIR for subproject builds (#195) --- CMakeLists.txt | 2 +- src/binding/python/CMakeLists.txt | 2 +- src/db/CMakeLists.txt | 1 + src/db/index/CMakeLists.txt | 2 +- tests/CMakeLists.txt | 4 ++-- tests/ailego/CMakeLists.txt | 4 ++-- tests/core/CMakeLists.txt | 4 ++-- tests/core/algorithm/CMakeLists.txt | 4 ++-- tests/core/algorithm/cluster/CMakeLists.txt | 4 ++-- tests/core/algorithm/flat/CMakeLists.txt | 4 ++-- tests/core/algorithm/flat_sparse/CMakeLists.txt | 4 ++-- tests/core/algorithm/hnsw/CMakeLists.txt | 4 ++-- tests/core/algorithm/hnsw_sparse/CMakeLists.txt | 4 ++-- tests/core/algorithm/ivf/CMakeLists.txt | 4 ++-- tests/core/framework/CMakeLists.txt | 2 +- tests/core/interface/CMakeLists.txt | 4 ++-- tests/core/metric/CMakeLists.txt | 4 ++-- tests/core/quantizer/CMakeLists.txt | 4 ++-- tests/core/utility/CMakeLists.txt | 6 +++--- tests/db/CMakeLists.txt | 4 ++-- tests/db/common/CMakeLists.txt | 4 ++-- tests/db/index/CMakeLists.txt | 4 ++-- tests/db/sqlengine/CMakeLists.txt | 6 +++--- tools/CMakeLists.txt | 4 ++-- tools/core/CMakeLists.txt | 4 ++-- 25 files changed, 47 insertions(+), 46 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 190a645..a9a2c9a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") endif() if(NOT DEFINED PROJECT_ROOT_DIR OR NOT PROJECT_ROOT_DIR) - set(PROJECT_ROOT_DIR ${CMAKE_SOURCE_DIR} CACHE PATH "Root directory of the project" FORCE) + set(PROJECT_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE PATH "Root directory of the project" FORCE) endif() message(STATUS "PROJECT_ROOT_DIR = ${PROJECT_ROOT_DIR}") diff --git a/src/binding/python/CMakeLists.txt b/src/binding/python/CMakeLists.txt index 83bfd4c..160b25e 100644 --- a/src/binding/python/CMakeLists.txt +++ b/src/binding/python/CMakeLists.txt @@ -56,4 +56,4 @@ elseif (APPLE) ) endif () -target_include_directories(_zvec PRIVATE ${PYBIND11_INCLUDE_DIR} ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/binding/python/include) +target_include_directories(_zvec PRIVATE ${PYBIND11_INCLUDE_DIR} ${PROJECT_ROOT_DIR}/src ${PROJECT_ROOT_DIR}/src/binding/python/include) diff --git a/src/db/CMakeLists.txt b/src/db/CMakeLists.txt index fd95c1d..765a1b4 100644 --- a/src/db/CMakeLists.txt +++ b/src/db/CMakeLists.txt @@ -17,6 +17,7 @@ cc_library( NAME zvec_db STATIC STRICT SRCS_NO_GLOB SRCS ${ALL_DB_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/proto/zvec.pb.cc INCS . ${CMAKE_CURRENT_BINARY_DIR} + PUBINCS ${PROJECT_ROOT_DIR}/src/include LIBS zvec_ailego zvec_core diff --git a/src/db/index/CMakeLists.txt b/src/db/index/CMakeLists.txt index b2a6415..4420050 100644 --- a/src/db/index/CMakeLists.txt +++ b/src/db/index/CMakeLists.txt @@ -11,6 +11,6 @@ cc_library( Arrow::arrow_static Arrow::arrow_compute Arrow::arrow_dataset - INCS . ${CMAKE_SOURCE_DIR}/src + INCS . ${PROJECT_ROOT_DIR}/src VERSION "${PROXIMA_ZVEC_VERSION}" ) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 0d2b953..03250f1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,5 +1,5 @@ -include(${CMAKE_SOURCE_DIR}/cmake/bazel.cmake) -include(${CMAKE_SOURCE_DIR}/cmake/option.cmake) +include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) +include(${PROJECT_ROOT_DIR}/cmake/option.cmake) cc_directories(ailego) cc_directories(db) diff --git a/tests/ailego/CMakeLists.txt b/tests/ailego/CMakeLists.txt index 12fdfd9..9165643 100644 --- a/tests/ailego/CMakeLists.txt +++ b/tests/ailego/CMakeLists.txt @@ -1,6 +1,6 @@ -include(${CMAKE_SOURCE_DIR}/cmake/bazel.cmake) -include(${CMAKE_SOURCE_DIR}/cmake/option.cmake) +include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) +include(${PROJECT_ROOT_DIR}/cmake/option.cmake) file(GLOB_RECURSE ALL_TEST_SRCS *_test.cc) diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt index 49f4e6e..73562c8 100644 --- a/tests/core/CMakeLists.txt +++ b/tests/core/CMakeLists.txt @@ -1,5 +1,5 @@ -include(${CMAKE_SOURCE_DIR}/cmake/bazel.cmake) -include(${CMAKE_SOURCE_DIR}/cmake/option.cmake) +include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) +include(${PROJECT_ROOT_DIR}/cmake/option.cmake) cc_directories(algorithm) cc_directories(framework) diff --git a/tests/core/algorithm/CMakeLists.txt b/tests/core/algorithm/CMakeLists.txt index 0e9aa72..b960f72 100644 --- a/tests/core/algorithm/CMakeLists.txt +++ b/tests/core/algorithm/CMakeLists.txt @@ -1,5 +1,5 @@ -include(${CMAKE_SOURCE_DIR}/cmake/bazel.cmake) -include(${CMAKE_SOURCE_DIR}/cmake/option.cmake) +include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) +include(${PROJECT_ROOT_DIR}/cmake/option.cmake) cc_directories(cluster) cc_directories(flat) diff --git a/tests/core/algorithm/cluster/CMakeLists.txt b/tests/core/algorithm/cluster/CMakeLists.txt index f665cd4..868ff7b 100644 --- a/tests/core/algorithm/cluster/CMakeLists.txt +++ b/tests/core/algorithm/cluster/CMakeLists.txt @@ -1,4 +1,4 @@ -include(${CMAKE_SOURCE_DIR}/cmake/bazel.cmake) +include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) file(GLOB_RECURSE ALL_TEST_SRCS *_test.cc) @@ -9,6 +9,6 @@ foreach(CC_SRCS ${ALL_TEST_SRCS}) STRICT LIBS zvec_ailego core_framework core_utility core_metric core_knn_cluster SRCS ${CC_SRCS} - INCS . ${CMAKE_SOURCE_DIR}/src/core ${CMAKE_SOURCE_DIR}/src/core/algorithm + INCS . ${PROJECT_ROOT_DIR}/src/core ${PROJECT_ROOT_DIR}/src/core/algorithm ) endforeach() \ No newline at end of file diff --git a/tests/core/algorithm/flat/CMakeLists.txt b/tests/core/algorithm/flat/CMakeLists.txt index 166106a..d18d49e 100644 --- a/tests/core/algorithm/flat/CMakeLists.txt +++ b/tests/core/algorithm/flat/CMakeLists.txt @@ -1,4 +1,4 @@ -include(${CMAKE_SOURCE_DIR}/cmake/bazel.cmake) +include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) file(GLOB_RECURSE ALL_TEST_SRCS *_test.cc) @@ -9,6 +9,6 @@ foreach(CC_SRCS ${ALL_TEST_SRCS}) STRICT LIBS zvec_ailego core_framework core_utility core_metric core_quantizer core_knn_flat SRCS ${CC_SRCS} - INCS . ${CMAKE_SOURCE_DIR}/src/core ${CMAKE_SOURCE_DIR}/src/core/algorithm + INCS . ${PROJECT_ROOT_DIR}/src/core ${PROJECT_ROOT_DIR}/src/core/algorithm ) endforeach() \ No newline at end of file diff --git a/tests/core/algorithm/flat_sparse/CMakeLists.txt b/tests/core/algorithm/flat_sparse/CMakeLists.txt index 68818b8..99c85ec 100644 --- a/tests/core/algorithm/flat_sparse/CMakeLists.txt +++ b/tests/core/algorithm/flat_sparse/CMakeLists.txt @@ -1,4 +1,4 @@ -include(${CMAKE_SOURCE_DIR}/cmake/bazel.cmake) +include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) file(GLOB_RECURSE ALL_TEST_SRCS *_test.cc) @@ -9,6 +9,6 @@ foreach(CC_SRCS ${ALL_TEST_SRCS}) STRICT LIBS zvec_ailego core_framework core_utility core_metric core_quantizer core_knn_flat_sparse SRCS ${CC_SRCS} - INCS . ${CMAKE_SOURCE_DIR}/src/core ${CMAKE_SOURCE_DIR}/src/core/algorithm + INCS . ${PROJECT_ROOT_DIR}/src/core ${PROJECT_ROOT_DIR}/src/core/algorithm ) endforeach() \ No newline at end of file diff --git a/tests/core/algorithm/hnsw/CMakeLists.txt b/tests/core/algorithm/hnsw/CMakeLists.txt index 3f85fc6..10c71d0 100644 --- a/tests/core/algorithm/hnsw/CMakeLists.txt +++ b/tests/core/algorithm/hnsw/CMakeLists.txt @@ -1,4 +1,4 @@ -include(${CMAKE_SOURCE_DIR}/cmake/bazel.cmake) +include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) file(GLOB_RECURSE ALL_TEST_SRCS *_test.cc) @@ -9,6 +9,6 @@ foreach(CC_SRCS ${ALL_TEST_SRCS}) STRICT LIBS zvec_ailego core_framework core_utility core_metric core_quantizer core_knn_hnsw core_knn_flat SRCS ${CC_SRCS} - INCS . ${CMAKE_SOURCE_DIR}/src/core ${CMAKE_SOURCE_DIR}/src/core/algorithm/hnsw + INCS . ${PROJECT_ROOT_DIR}/src/core ${PROJECT_ROOT_DIR}/src/core/algorithm/hnsw ) endforeach() \ No newline at end of file diff --git a/tests/core/algorithm/hnsw_sparse/CMakeLists.txt b/tests/core/algorithm/hnsw_sparse/CMakeLists.txt index a9180a7..97e5afd 100644 --- a/tests/core/algorithm/hnsw_sparse/CMakeLists.txt +++ b/tests/core/algorithm/hnsw_sparse/CMakeLists.txt @@ -1,4 +1,4 @@ -include(${CMAKE_SOURCE_DIR}/cmake/bazel.cmake) +include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) file(GLOB_RECURSE ALL_TEST_SRCS *_test.cc) @@ -9,6 +9,6 @@ foreach(CC_SRCS ${ALL_TEST_SRCS}) STRICT LIBS zvec_ailego core_framework core_utility core_metric core_quantizer core_knn_hnsw_sparse SRCS ${CC_SRCS} - INCS . ${CMAKE_SOURCE_DIR}/src/core ${CMAKE_SOURCE_DIR}/src/core/algorithm/hnsw_sparse + INCS . ${PROJECT_ROOT_DIR}/src/core ${PROJECT_ROOT_DIR}/src/core/algorithm/hnsw_sparse ) endforeach() \ No newline at end of file diff --git a/tests/core/algorithm/ivf/CMakeLists.txt b/tests/core/algorithm/ivf/CMakeLists.txt index e6a3e76..8f65783 100644 --- a/tests/core/algorithm/ivf/CMakeLists.txt +++ b/tests/core/algorithm/ivf/CMakeLists.txt @@ -1,4 +1,4 @@ -include(${CMAKE_SOURCE_DIR}/cmake/bazel.cmake) +include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) file(GLOB_RECURSE ALL_TEST_SRCS *_test.cc) @@ -9,6 +9,6 @@ foreach(CC_SRCS ${ALL_TEST_SRCS}) STRICT LIBS zvec_ailego core_framework core_utility core_metric core_quantizer core_knn_cluster core_knn_flat core_knn_ivf SRCS ${CC_SRCS} - INCS . ${CMAKE_SOURCE_DIR}/src/core ${CMAKE_SOURCE_DIR}/src/core/algorithm/ivf + INCS . ${PROJECT_ROOT_DIR}/src/core ${PROJECT_ROOT_DIR}/src/core/algorithm/ivf ) endforeach() \ No newline at end of file diff --git a/tests/core/framework/CMakeLists.txt b/tests/core/framework/CMakeLists.txt index 71fb2ec..74e0c15 100644 --- a/tests/core/framework/CMakeLists.txt +++ b/tests/core/framework/CMakeLists.txt @@ -1,4 +1,4 @@ -include(${CMAKE_SOURCE_DIR}/cmake/bazel.cmake) +include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) file(GLOB_RECURSE ALL_TEST_SRCS *_test.cc) diff --git a/tests/core/interface/CMakeLists.txt b/tests/core/interface/CMakeLists.txt index 462df19..074653c 100644 --- a/tests/core/interface/CMakeLists.txt +++ b/tests/core/interface/CMakeLists.txt @@ -1,4 +1,4 @@ -include(${CMAKE_SOURCE_DIR}/cmake/bazel.cmake) +include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) file(GLOB_RECURSE ALL_TEST_SRCS *_test.cc) @@ -10,6 +10,6 @@ foreach(CC_SRCS ${ALL_TEST_SRCS}) LIBS zvec_ailego core_framework core_metric core_interface core_knn_flat core_utility core_quantizer sparsehash core_knn_hnsw core_mix_reducer core_knn_flat_sparse core_knn_hnsw_sparse core_knn_ivf SRCS ${CC_SRCS} - INCS . ${CMAKE_SOURCE_DIR}/src/core ${CMAKE_SOURCE_DIR}/src/core/algorithm + INCS . ${PROJECT_ROOT_DIR}/src/core ${PROJECT_ROOT_DIR}/src/core/algorithm ) endforeach() \ No newline at end of file diff --git a/tests/core/metric/CMakeLists.txt b/tests/core/metric/CMakeLists.txt index 09e55d9..0e86485 100644 --- a/tests/core/metric/CMakeLists.txt +++ b/tests/core/metric/CMakeLists.txt @@ -1,4 +1,4 @@ -include(${CMAKE_SOURCE_DIR}/cmake/bazel.cmake) +include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) file(GLOB_RECURSE ALL_TEST_SRCS *_test.cc) @@ -9,6 +9,6 @@ foreach(CC_SRCS ${ALL_TEST_SRCS}) STRICT LIBS zvec_ailego core_framework core_metric core_quantizer SRCS ${CC_SRCS} - INCS . ${CMAKE_SOURCE_DIR}/src/core/ + INCS . ${PROJECT_ROOT_DIR}/src/core/ ) endforeach() \ No newline at end of file diff --git a/tests/core/quantizer/CMakeLists.txt b/tests/core/quantizer/CMakeLists.txt index 57f826a..d28e9e5 100644 --- a/tests/core/quantizer/CMakeLists.txt +++ b/tests/core/quantizer/CMakeLists.txt @@ -1,4 +1,4 @@ -include(${CMAKE_SOURCE_DIR}/cmake/bazel.cmake) +include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) file(GLOB_RECURSE ALL_TEST_SRCS *_test.cc) @@ -9,6 +9,6 @@ foreach(CC_SRCS ${ALL_TEST_SRCS}) STRICT LIBS zvec_ailego core_framework core_quantizer SRCS ${CC_SRCS} - INCS . ${CMAKE_SOURCE_DIR}/src/core/ + INCS . ${PROJECT_ROOT_DIR}/src/core/ ) endforeach() \ No newline at end of file diff --git a/tests/core/utility/CMakeLists.txt b/tests/core/utility/CMakeLists.txt index 6920776..9c7b10a 100644 --- a/tests/core/utility/CMakeLists.txt +++ b/tests/core/utility/CMakeLists.txt @@ -1,6 +1,6 @@ -include(${CMAKE_SOURCE_DIR}/cmake/bazel.cmake) -include(${CMAKE_SOURCE_DIR}/cmake/option.cmake) +include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) +include(${PROJECT_ROOT_DIR}/cmake/option.cmake) file(GLOB_RECURSE ALL_TEST_SRCS *_test.cc) @@ -12,7 +12,7 @@ foreach(CC_SRCS ${ALL_TEST_SRCS}) Arrow::arrow_depends Arrow::parquet_static SRCS ${CC_SRCS} - INCS . ${CMAKE_SOURCE_DIR}/src/core/ + INCS . ${PROJECT_ROOT_DIR}/src/core/ ) cc_test_suite(zvec_ailego ${CC_TARGET}) endforeach() diff --git a/tests/db/CMakeLists.txt b/tests/db/CMakeLists.txt index 29f7fcc..8de3089 100644 --- a/tests/db/CMakeLists.txt +++ b/tests/db/CMakeLists.txt @@ -1,5 +1,5 @@ -include(${CMAKE_SOURCE_DIR}/cmake/bazel.cmake) -include(${CMAKE_SOURCE_DIR}/cmake/option.cmake) +include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) +include(${PROJECT_ROOT_DIR}/cmake/option.cmake) cc_directory(common) cc_directory(sqlengine) diff --git a/tests/db/common/CMakeLists.txt b/tests/db/common/CMakeLists.txt index 2cb9107..fa9278e 100644 --- a/tests/db/common/CMakeLists.txt +++ b/tests/db/common/CMakeLists.txt @@ -1,5 +1,5 @@ -include(${CMAKE_SOURCE_DIR}/cmake/bazel.cmake) -include(${CMAKE_SOURCE_DIR}/cmake/option.cmake) +include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) +include(${PROJECT_ROOT_DIR}/cmake/option.cmake) if(APPLE) set(APPLE_FRAMEWORK_LIBS diff --git a/tests/db/index/CMakeLists.txt b/tests/db/index/CMakeLists.txt index e06e736..22a2932 100644 --- a/tests/db/index/CMakeLists.txt +++ b/tests/db/index/CMakeLists.txt @@ -1,6 +1,6 @@ -include(${CMAKE_SOURCE_DIR}/cmake/bazel.cmake) -include(${CMAKE_SOURCE_DIR}/cmake/option.cmake) +include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) +include(${PROJECT_ROOT_DIR}/cmake/option.cmake) if(APPLE) set(APPLE_FRAMEWORK_LIBS diff --git a/tests/db/sqlengine/CMakeLists.txt b/tests/db/sqlengine/CMakeLists.txt index 7cdb502..dbba718 100644 --- a/tests/db/sqlengine/CMakeLists.txt +++ b/tests/db/sqlengine/CMakeLists.txt @@ -1,6 +1,6 @@ -include(${CMAKE_SOURCE_DIR}/cmake/bazel.cmake) -include(${CMAKE_SOURCE_DIR}/cmake/option.cmake) +include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) +include(${PROJECT_ROOT_DIR}/cmake/option.cmake) if(APPLE) set(APPLE_FRAMEWORK_LIBS @@ -35,7 +35,7 @@ foreach(CC_SRCS ${ALL_TEST_SRCS}) ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS} SRCS ${CC_SRCS} - INCS . ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/db ${CMAKE_SOURCE_DIR}/src/db/common + INCS . ${PROJECT_ROOT_DIR}/src ${PROJECT_ROOT_DIR}/src/db ${PROJECT_ROOT_DIR}/src/db/common LDFLAGS ${APPLE_FRAMEWORK_LIBS} ) cc_test_suite(zvec_sqlengine ${CC_TARGET}) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index a358760..4e17f1e 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -1,5 +1,5 @@ -include(${CMAKE_SOURCE_DIR}/cmake/bazel.cmake) -include(${CMAKE_SOURCE_DIR}/cmake/option.cmake) +include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) +include(${PROJECT_ROOT_DIR}/cmake/option.cmake) # Retrieve version from git repository git_version(ZVEC_VERSION ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/tools/core/CMakeLists.txt b/tools/core/CMakeLists.txt index 46efc39..dbbd206 100644 --- a/tools/core/CMakeLists.txt +++ b/tools/core/CMakeLists.txt @@ -1,5 +1,5 @@ -include(${CMAKE_SOURCE_DIR}/cmake/bazel.cmake) -include(${CMAKE_SOURCE_DIR}/cmake/option.cmake) +include(${PROJECT_ROOT_DIR}/cmake/bazel.cmake) +include(${PROJECT_ROOT_DIR}/cmake/option.cmake) cc_binary( NAME txt2vecs