Skip to content

Commit 9156e28

Browse files
suxiaogang223claude
andcommitted
feat: Add flexible third-party dependency management system
This commit implements a flexible dependency management system that allows users to control how third-party dependencies are resolved and built. Key features: - PAIMON_DEPENDENCY_SOURCE: Global control (AUTO/BUNDLED/SYSTEM/CONDA) - Per-dependency source control via <PACKAGE>_SOURCE variables - Per-dependency location control via <PACKAGE>_ROOT variables - Unified path prefix via PAIMON_PACKAGE_PREFIX - Shared vs static library control - Find modules for Snappy, zstd, lz4, and glog Changes: - cmake_modules/DefineOptions.cmake: Add dependency management options - cmake_modules/ThirdpartyToolchain.cmake: Implement resolve_dependency() macro and build_dependency() macro - cmake_modules/Find*Alt.cmake: Add Find modules for major dependencies - docs/DependencyManagement.md: Complete documentation with examples Benefits: - Faster builds when reusing system libraries - Support for conda, vcpkg, brew, and system package managers - Better CI/CD integration - Backward compatible (defaults to AUTO mode) Relates to #103 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 60448b8 commit 9156e28

7 files changed

Lines changed: 907 additions & 12 deletions

File tree

cmake_modules/DefineOptions.cmake

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,53 @@ if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
127127
define_option(PAIMON_USE_TSAN "Enable Thread Sanitizer checks" OFF)
128128
define_option(PAIMON_USE_UBSAN "Enable Undefined Behaviour Sanitizer checks" OFF)
129129

130+
#----------------------------------------------------------------------
131+
set_option_category("Thirdparty dependencies")
132+
133+
if(NOT "$ENV{CONDA_PREFIX}" STREQUAL "")
134+
set(PAIMON_DEPENDENCY_SOURCE_DEFAULT "CONDA")
135+
else()
136+
set(PAIMON_DEPENDENCY_SOURCE_DEFAULT "AUTO")
137+
endif()
138+
139+
define_option_string(PAIMON_DEPENDENCY_SOURCE
140+
"Method to use for acquiring Paimon's build dependencies"
141+
"${PAIMON_DEPENDENCY_SOURCE_DEFAULT}"
142+
"AUTO"
143+
"BUNDLED"
144+
"SYSTEM"
145+
"CONDA"
146+
"VCPKG"
147+
"BREW")
148+
149+
define_option(PAIMON_VERBOSE_THIRDPARTY_BUILD
150+
"Show output from ExternalProjects rather than just logging to files"
151+
OFF)
152+
153+
define_option(PAIMON_DEPENDENCY_USE_SHARED
154+
"Link to shared libraries for dependencies where available"
155+
ON)
156+
157+
define_option(PAIMON_SNAPPY_USE_SHARED
158+
"Rely on Snappy shared libraries where relevant"
159+
${PAIMON_DEPENDENCY_USE_SHARED})
160+
161+
define_option(PAIMON_ZSTD_USE_SHARED
162+
"Rely on zstd shared libraries where relevant"
163+
${PAIMON_DEPENDENCY_USE_SHARED})
164+
165+
define_option(PAIMON_LZ4_USE_SHARED
166+
"Rely on lz4 shared libraries where relevant"
167+
${PAIMON_DEPENDENCY_USE_SHARED})
168+
169+
define_option(PAIMON_ZLIB_USE_SHARED
170+
"Rely on zlib shared libraries where relevant"
171+
${PAIMON_DEPENDENCY_USE_SHARED})
172+
173+
define_option(PAIMON_GLOG_USE_SHARED
174+
"Rely on glog shared libraries where relevant"
175+
${PAIMON_DEPENDENCY_USE_SHARED})
176+
130177
#----------------------------------------------------------------------
131178
set_option_category("Advanced developer")
132179

cmake_modules/FindSnappyAlt.cmake

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
if(SnappyAlt_FOUND)
19+
return()
20+
endif()
21+
22+
set(find_package_args)
23+
if(SnappyAlt_FIND_VERSION)
24+
list(APPEND find_package_args ${SnappyAlt_FIND_VERSION})
25+
endif()
26+
if(SnappyAlt_FIND_QUIETLY)
27+
list(APPEND find_package_args QUIET)
28+
endif()
29+
30+
# Try to find Snappy using standard find_package first
31+
find_package(Snappy ${find_package_args})
32+
if(Snappy_FOUND)
33+
if(PAIMON_SNAPPY_USE_SHARED)
34+
set(Snappy_TARGET Snappy::snappy)
35+
set(SnappyAlt_FOUND TRUE)
36+
return()
37+
else()
38+
if(TARGET Snappy::snappy-static)
39+
set(Snappy_TARGET Snappy::snappy-static)
40+
set(SnappyAlt_FOUND TRUE)
41+
return()
42+
else()
43+
get_target_property(Snappy_TYPE Snappy::snappy TYPE)
44+
if(Snappy_TYPE STREQUAL "STATIC_LIBRARY" OR Snappy_TYPE STREQUAL "INTERFACE_LIBRARY")
45+
set(Snappy_TARGET Snappy::snappy)
46+
set(SnappyAlt_FOUND TRUE)
47+
return()
48+
endif()
49+
endif()
50+
endif()
51+
endif()
52+
53+
# Manual search if standard find_package didn't work
54+
set(PAIMON_LIBRARY_PATH_SUFFIXES
55+
lib
56+
lib64
57+
lib/${CMAKE_LIBRARY_ARCHITECTURE})
58+
set(PAIMON_INCLUDE_PATH_SUFFIXES include)
59+
60+
if(PAIMON_SNAPPY_USE_SHARED)
61+
set(SNAPPY_LIB_NAMES)
62+
if(CMAKE_IMPORT_LIBRARY_SUFFIX)
63+
list(APPEND SNAPPY_LIB_NAMES
64+
"${CMAKE_IMPORT_LIBRARY_PREFIX}snappy${CMAKE_IMPORT_LIBRARY_SUFFIX}")
65+
endif()
66+
list(APPEND SNAPPY_LIB_NAMES
67+
"${CMAKE_SHARED_LIBRARY_PREFIX}snappy${CMAKE_SHARED_LIBRARY_SUFFIX}")
68+
else()
69+
set(SNAPPY_LIB_NAMES
70+
"${CMAKE_STATIC_LIBRARY_PREFIX}snappy${CMAKE_STATIC_LIBRARY_SUFFIX}")
71+
endif()
72+
73+
if(Snappy_ROOT)
74+
find_library(Snappy_LIB
75+
NAMES ${SNAPPY_LIB_NAMES}
76+
PATHS ${Snappy_ROOT}
77+
PATH_SUFFIXES ${PAIMON_LIBRARY_PATH_SUFFIXES}
78+
NO_DEFAULT_PATH)
79+
find_path(Snappy_INCLUDE_DIR
80+
NAMES snappy.h
81+
PATHS ${Snappy_ROOT}
82+
NO_DEFAULT_PATH
83+
PATH_SUFFIXES ${PAIMON_INCLUDE_PATH_SUFFIXES})
84+
else()
85+
find_library(Snappy_LIB NAMES ${SNAPPY_LIB_NAMES}
86+
PATH_SUFFIXES ${PAIMON_LIBRARY_PATH_SUFFIXES})
87+
find_path(Snappy_INCLUDE_DIR
88+
NAMES snappy.h
89+
PATH_SUFFIXES ${PAIMON_INCLUDE_PATH_SUFFIXES})
90+
endif()
91+
92+
find_package_handle_standard_args(SnappyAlt REQUIRED_VARS Snappy_LIB Snappy_INCLUDE_DIR)
93+
94+
if(SnappyAlt_FOUND)
95+
if(PAIMON_SNAPPY_USE_SHARED)
96+
set(Snappy_TARGET Snappy::snappy)
97+
set(Snappy_TARGET_TYPE SHARED)
98+
else()
99+
set(Snappy_TARGET Snappy::snappy)
100+
set(Snappy_TARGET_TYPE STATIC)
101+
endif()
102+
103+
if(NOT TARGET ${Snappy_TARGET})
104+
add_library(${Snappy_TARGET} ${Snappy_TARGET_TYPE} IMPORTED)
105+
set_target_properties(${Snappy_TARGET}
106+
PROPERTIES IMPORTED_LOCATION "${Snappy_LIB}"
107+
INTERFACE_INCLUDE_DIRECTORIES "${Snappy_INCLUDE_DIR}")
108+
endif()
109+
endif()

cmake_modules/FindglogAlt.cmake

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
if(glogAlt_FOUND)
19+
return()
20+
endif()
21+
22+
set(find_package_args)
23+
if(glogAlt_FIND_VERSION)
24+
list(APPEND find_package_args ${glogAlt_FIND_VERSION})
25+
endif()
26+
if(glogAlt_FIND_QUIETLY)
27+
list(APPEND find_package_args QUIET)
28+
endif()
29+
30+
# Try to find glog using standard find_package first
31+
find_package(glog ${find_package_args})
32+
if(glog_FOUND)
33+
set(glogAlt_FOUND TRUE)
34+
if(TARGET glog::glog)
35+
return()
36+
endif()
37+
endif()
38+
39+
# Manual search
40+
set(PAIMON_LIBRARY_PATH_SUFFIXES
41+
lib
42+
lib64
43+
lib/${CMAKE_LIBRARY_ARCHITECTURE})
44+
set(PAIMON_INCLUDE_PATH_SUFFIXES include)
45+
46+
if(${UPPERCASE_BUILD_TYPE} STREQUAL "DEBUG")
47+
set(GLOG_LIB_SUFFIX "d")
48+
else()
49+
set(GLOG_LIB_SUFFIX "")
50+
endif()
51+
52+
if(PAIMON_GLOG_USE_SHARED)
53+
set(GLOG_LIB_NAMES)
54+
if(CMAKE_IMPORT_LIBRARY_SUFFIX)
55+
list(APPEND GLOG_LIB_NAMES
56+
"${CMAKE_IMPORT_LIBRARY_PREFIX}glog${GLOG_LIB_SUFFIX}${CMAKE_IMPORT_LIBRARY_SUFFIX}")
57+
endif()
58+
list(APPEND GLOG_LIB_NAMES
59+
"${CMAKE_SHARED_LIBRARY_PREFIX}glog${GLOG_LIB_SUFFIX}${CMAKE_SHARED_LIBRARY_SUFFIX}")
60+
else()
61+
set(GLOG_LIB_NAMES
62+
"${CMAKE_STATIC_LIBRARY_PREFIX}glog${GLOG_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}")
63+
endif()
64+
65+
if(glog_ROOT)
66+
find_library(glog_LIB
67+
NAMES ${GLOG_LIB_NAMES}
68+
PATHS ${glog_ROOT}
69+
PATH_SUFFIXES ${PAIMON_LIBRARY_PATH_SUFFIXES}
70+
NO_DEFAULT_PATH)
71+
find_path(glog_INCLUDE_DIR
72+
NAMES glog/logging.h
73+
PATHS ${glog_ROOT}
74+
NO_DEFAULT_PATH
75+
PATH_SUFFIXES ${PAIMON_INCLUDE_PATH_SUFFIXES})
76+
else()
77+
find_library(glog_LIB NAMES ${GLOG_LIB_NAMES}
78+
PATH_SUFFIXES ${PAIMON_LIBRARY_PATH_SUFFIXES})
79+
find_path(glog_INCLUDE_DIR
80+
NAMES glog/logging.h
81+
PATH_SUFFIXES ${PAIMON_INCLUDE_PATH_SUFFIXES})
82+
endif()
83+
84+
find_package_handle_standard_args(glogAlt REQUIRED_VARS glog_LIB glog_INCLUDE_DIR)
85+
86+
if(glogAlt_FOUND)
87+
if(NOT TARGET glog::glog)
88+
if(PAIMON_GLOG_USE_SHARED)
89+
set(glog_TARGET_TYPE SHARED)
90+
else()
91+
set(glog_TARGET_TYPE STATIC)
92+
endif()
93+
add_library(glog::glog ${glog_TARGET_TYPE} IMPORTED)
94+
set_target_properties(glog::glog
95+
PROPERTIES IMPORTED_LOCATION "${glog_LIB}"
96+
INTERFACE_INCLUDE_DIRECTORIES "${glog_INCLUDE_DIR}"
97+
INTERFACE_COMPILE_DEFINITIONS "GLOG_USE_GLOG_EXPORT")
98+
endif()
99+
endif()

cmake_modules/Findlz4Alt.cmake

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
if(lz4Alt_FOUND)
19+
return()
20+
endif()
21+
22+
set(find_package_args)
23+
if(lz4Alt_FIND_VERSION)
24+
list(APPEND find_package_args ${lz4Alt_FIND_VERSION})
25+
endif()
26+
if(lz4Alt_FIND_QUIETLY)
27+
list(APPEND find_package_args QUIET)
28+
endif()
29+
30+
# Try to find lz4 using standard find_package first
31+
find_package(lz4 ${find_package_args})
32+
if(lz4_FOUND)
33+
set(lz4Alt_FOUND TRUE)
34+
if(TARGET LZ4::lz4)
35+
return()
36+
elseif(TARGET lz4::lz4)
37+
add_library(LZ4::lz4 ALIAS lz4::lz4)
38+
return()
39+
elseif(PAIMON_LZ4_USE_SHARED AND TARGET LZ4::lz4_shared)
40+
add_library(LZ4::lz4 ALIAS LZ4::lz4_shared)
41+
return()
42+
elseif(TARGET LZ4::lz4_static)
43+
add_library(LZ4::lz4 ALIAS LZ4::lz4_static)
44+
return()
45+
endif()
46+
endif()
47+
48+
# Manual search
49+
set(PAIMON_LIBRARY_PATH_SUFFIXES
50+
lib
51+
lib64
52+
lib/${CMAKE_LIBRARY_ARCHITECTURE})
53+
set(PAIMON_INCLUDE_PATH_SUFFIXES include)
54+
55+
if(MSVC_TOOLCHAIN AND NOT DEFINED LZ4_MSVC_LIB_PREFIX)
56+
set(LZ4_MSVC_LIB_PREFIX "lib")
57+
endif()
58+
set(LZ4_LIB_NAME_BASE "${LZ4_MSVC_LIB_PREFIX}lz4")
59+
60+
if(PAIMON_LZ4_USE_SHARED)
61+
set(LZ4_LIB_NAMES)
62+
if(CMAKE_IMPORT_LIBRARY_SUFFIX)
63+
list(APPEND LZ4_LIB_NAMES
64+
"${CMAKE_IMPORT_LIBRARY_PREFIX}${LZ4_LIB_NAME_BASE}${CMAKE_IMPORT_LIBRARY_SUFFIX}")
65+
endif()
66+
list(APPEND LZ4_LIB_NAMES
67+
"${CMAKE_SHARED_LIBRARY_PREFIX}${LZ4_LIB_NAME_BASE}${CMAKE_SHARED_LIBRARY_SUFFIX}")
68+
else()
69+
if(MSVC AND NOT DEFINED LZ4_MSVC_STATIC_LIB_SUFFIX)
70+
set(LZ4_MSVC_STATIC_LIB_SUFFIX "_static")
71+
endif()
72+
set(LZ4_STATIC_LIB_SUFFIX "${LZ4_MSVC_STATIC_LIB_SUFFIX}${CMAKE_STATIC_LIBRARY_SUFFIX}")
73+
set(LZ4_LIB_NAMES
74+
"${CMAKE_STATIC_LIBRARY_PREFIX}${LZ4_LIB_NAME_BASE}${LZ4_STATIC_LIB_SUFFIX}")
75+
endif()
76+
77+
if(lz4_ROOT)
78+
find_library(LZ4_LIB
79+
NAMES ${LZ4_LIB_NAMES}
80+
PATHS ${lz4_ROOT}
81+
PATH_SUFFIXES ${PAIMON_LIBRARY_PATH_SUFFIXES}
82+
NO_DEFAULT_PATH)
83+
find_path(LZ4_INCLUDE_DIR
84+
NAMES lz4.h
85+
PATHS ${lz4_ROOT}
86+
NO_DEFAULT_PATH
87+
PATH_SUFFIXES ${PAIMON_INCLUDE_PATH_SUFFIXES})
88+
else()
89+
# Try pkg-config first
90+
find_package(PkgConfig QUIET)
91+
pkg_check_modules(LZ4_PC liblz4 QUIET)
92+
if(LZ4_PC_FOUND)
93+
set(LZ4_INCLUDE_DIR "${LZ4_PC_INCLUDEDIR}")
94+
list(APPEND LZ4_PC_LIBRARY_DIRS "${LZ4_PC_LIBDIR}")
95+
find_library(LZ4_LIB
96+
NAMES ${LZ4_LIB_NAMES}
97+
PATHS ${LZ4_PC_LIBRARY_DIRS}
98+
NO_DEFAULT_PATH
99+
PATH_SUFFIXES ${PAIMON_LIBRARY_PATH_SUFFIXES})
100+
else()
101+
find_library(LZ4_LIB NAMES ${LZ4_LIB_NAMES}
102+
PATH_SUFFIXES ${PAIMON_LIBRARY_PATH_SUFFIXES})
103+
find_path(LZ4_INCLUDE_DIR
104+
NAMES lz4.h
105+
PATH_SUFFIXES ${PAIMON_INCLUDE_PATH_SUFFIXES})
106+
endif()
107+
endif()
108+
109+
find_package_handle_standard_args(lz4Alt REQUIRED_VARS LZ4_LIB LZ4_INCLUDE_DIR)
110+
111+
if(lz4Alt_FOUND)
112+
if(NOT TARGET LZ4::lz4)
113+
add_library(LZ4::lz4 UNKNOWN IMPORTED)
114+
set_target_properties(LZ4::lz4
115+
PROPERTIES IMPORTED_LOCATION "${LZ4_LIB}"
116+
INTERFACE_INCLUDE_DIRECTORIES "${LZ4_INCLUDE_DIR}")
117+
endif()
118+
endif()

0 commit comments

Comments
 (0)