Skip to content

Commit 23efdab

Browse files
committed
ORC-1622: [C++] Support conan packaging
### What changes were proposed in this pull request? Add conan recipe for the C++ library. The latest release of supported versions are added by default. ### Why are the changes needed? Conan is a popular C++ package manager: https://docs.conan.io/2/index.html. It would be good to support conan recipe on our end. ### How was this patch tested? Test it locally using conan command. ### Was this patch authored or co-authored using generative AI tooling? No Closes #1805 from wgtmac/conan. Authored-by: Gang Wu <[email protected]> Signed-off-by: Gang Wu <[email protected]>
1 parent 39368b5 commit 23efdab

10 files changed

+843
-15
lines changed

CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ option(BUILD_ENABLE_AVX512
7676
"Enable build with AVX512 at compile time"
7777
OFF)
7878

79+
option(ORC_PACKAGE_KIND
80+
"Arbitrary string that identifies the kind of package"
81+
"")
82+
7983
# Make sure that a build type is selected
8084
if (NOT CMAKE_BUILD_TYPE)
8185
message(STATUS "No build type selected, default to ReleaseWithDebugInfo")

cmake_modules/ThirdpartyToolchain.cmake

+44-15
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ ExternalProject_Add (orc-format_ep
8383
# ----------------------------------------------------------------------
8484
# Snappy
8585

86-
if (NOT "${SNAPPY_HOME}" STREQUAL "")
86+
if (NOT "${SNAPPY_HOME}" STREQUAL "" OR ORC_PACKAGE_KIND STREQUAL "conan")
8787
find_package (Snappy REQUIRED)
8888
set(SNAPPY_VENDORED FALSE)
8989
else ()
@@ -109,12 +109,18 @@ endif ()
109109

110110
add_library (orc_snappy INTERFACE)
111111
add_library (orc::snappy ALIAS orc_snappy)
112-
if (ORC_PREFER_STATIC_SNAPPY AND ${SNAPPY_STATIC_LIB})
112+
if (ORC_PACKAGE_KIND STREQUAL "conan")
113+
target_link_libraries(orc_snappy INTERFACE ${Snappy_LIBRARIES})
114+
elseif (ORC_PREFER_STATIC_SNAPPY AND ${SNAPPY_STATIC_LIB})
113115
target_link_libraries(orc_snappy INTERFACE ${SNAPPY_STATIC_LIB})
114116
else ()
115117
target_link_libraries(orc_snappy INTERFACE ${SNAPPY_LIBRARY})
116118
endif ()
117-
target_include_directories (orc_snappy SYSTEM INTERFACE ${SNAPPY_INCLUDE_DIR})
119+
if (ORC_PACKAGE_KIND STREQUAL "conan")
120+
target_include_directories (orc_snappy SYSTEM INTERFACE ${Snappy_INCLUDE_DIR})
121+
else()
122+
target_include_directories (orc_snappy SYSTEM INTERFACE ${SNAPPY_INCLUDE_DIR})
123+
endif ()
118124

119125
if (SNAPPY_VENDORED)
120126
add_dependencies (orc_snappy snappy_ep)
@@ -127,7 +133,7 @@ endif ()
127133
# ----------------------------------------------------------------------
128134
# ZLIB
129135

130-
if (NOT "${ZLIB_HOME}" STREQUAL "")
136+
if (NOT "${ZLIB_HOME}" STREQUAL "" OR ORC_PACKAGE_KIND STREQUAL "conan")
131137
find_package (ZLIB REQUIRED)
132138
set(ZLIB_VENDORED FALSE)
133139
else ()
@@ -161,7 +167,9 @@ endif ()
161167

162168
add_library (orc_zlib INTERFACE)
163169
add_library (orc::zlib ALIAS orc_zlib)
164-
if (ORC_PREFER_STATIC_ZLIB AND ${ZLIB_STATIC_LIB})
170+
if (ORC_PACKAGE_KIND STREQUAL "conan")
171+
target_link_libraries (orc_zlib INTERFACE ${ZLIB_LIBRARIES})
172+
elseif (ORC_PREFER_STATIC_ZLIB AND ${ZLIB_STATIC_LIB})
165173
target_link_libraries (orc_zlib INTERFACE ${ZLIB_STATIC_LIB})
166174
else ()
167175
target_link_libraries (orc_zlib INTERFACE ${ZLIB_LIBRARY})
@@ -179,7 +187,7 @@ endif ()
179187
# ----------------------------------------------------------------------
180188
# Zstd
181189

182-
if (NOT "${ZSTD_HOME}" STREQUAL "")
190+
if (NOT "${ZSTD_HOME}" STREQUAL "" OR ORC_PACKAGE_KIND STREQUAL "conan")
183191
find_package (ZSTD REQUIRED)
184192
set(ZSTD_VENDORED FALSE)
185193
else ()
@@ -220,12 +228,18 @@ endif ()
220228

221229
add_library (orc_zstd INTERFACE)
222230
add_library (orc::zstd ALIAS orc_zstd)
223-
if (ORC_PREFER_STATIC_ZSTD AND ${ZSTD_STATIC_LIB})
231+
if (ORC_PACKAGE_KIND STREQUAL "conan")
232+
target_link_libraries (orc_zstd INTERFACE ${zstd_LIBRARIES})
233+
elseif (ORC_PREFER_STATIC_ZSTD AND ${ZSTD_STATIC_LIB})
224234
target_link_libraries (orc_zstd INTERFACE ${ZSTD_STATIC_LIB})
225235
else ()
226236
target_link_libraries (orc_zstd INTERFACE ${ZSTD_LIBRARY})
227237
endif ()
228-
target_include_directories (orc_zstd SYSTEM INTERFACE ${ZSTD_INCLUDE_DIR})
238+
if (ORC_PACKAGE_KIND STREQUAL "conan")
239+
target_include_directories (orc_zstd SYSTEM INTERFACE ${zstd_INCLUDE_DIR})
240+
else()
241+
target_include_directories (orc_zstd SYSTEM INTERFACE ${ZSTD_INCLUDE_DIR})
242+
endif ()
229243

230244
if (ZSTD_VENDORED)
231245
add_dependencies (orc_zstd zstd_ep)
@@ -238,7 +252,7 @@ endif ()
238252
# ----------------------------------------------------------------------
239253
# LZ4
240254

241-
if (NOT "${LZ4_HOME}" STREQUAL "")
255+
if (NOT "${LZ4_HOME}" STREQUAL "" OR ORC_PACKAGE_KIND STREQUAL "conan")
242256
find_package (LZ4 REQUIRED)
243257
set(LZ4_VENDORED FALSE)
244258
else ()
@@ -272,12 +286,18 @@ endif ()
272286

273287
add_library (orc_lz4 INTERFACE)
274288
add_library (orc::lz4 ALIAS orc_lz4)
275-
if (ORC_PREFER_STATIC_LZ4 AND ${LZ4_STATIC_LIB})
289+
if (ORC_PACKAGE_KIND STREQUAL "conan")
290+
target_link_libraries (orc_lz4 INTERFACE ${lz4_LIBRARIES})
291+
elseif (ORC_PREFER_STATIC_LZ4 AND ${LZ4_STATIC_LIB})
276292
target_link_libraries (orc_lz4 INTERFACE ${LZ4_STATIC_LIB})
277293
else ()
278294
target_link_libraries (orc_lz4 INTERFACE ${LZ4_LIBRARY})
279295
endif ()
280-
target_include_directories (orc_lz4 SYSTEM INTERFACE ${LZ4_INCLUDE_DIR})
296+
if (ORC_PACKAGE_KIND STREQUAL "conan")
297+
target_include_directories (orc_lz4 SYSTEM INTERFACE ${lz4_INCLUDE_DIR})
298+
else()
299+
target_include_directories (orc_lz4 SYSTEM INTERFACE ${LZ4_INCLUDE_DIR})
300+
endif ()
281301

282302
if (LZ4_VENDORED)
283303
add_dependencies (orc_lz4 lz4_ep)
@@ -393,7 +413,7 @@ endif ()
393413
# ----------------------------------------------------------------------
394414
# Protobuf
395415

396-
if (NOT "${PROTOBUF_HOME}" STREQUAL "")
416+
if (NOT "${PROTOBUF_HOME}" STREQUAL "" OR ORC_PACKAGE_KIND STREQUAL "conan")
397417
find_package (Protobuf REQUIRED)
398418
set(PROTOBUF_VENDORED FALSE)
399419
else ()
@@ -442,14 +462,23 @@ add_library (orc::protobuf ALIAS orc_protobuf)
442462
add_library (orc_protoc INTERFACE)
443463
add_library (orc::protoc ALIAS orc_protoc)
444464

445-
if (ORC_PREFER_STATIC_PROTOBUF AND ${PROTOBUF_STATIC_LIB})
465+
if (ORC_PACKAGE_KIND STREQUAL "conan")
466+
target_link_libraries (orc_protobuf INTERFACE ${protobuf_LIBRARIES})
467+
elseif (ORC_PREFER_STATIC_PROTOBUF AND ${PROTOBUF_STATIC_LIB})
446468
target_link_libraries (orc_protobuf INTERFACE ${PROTOBUF_STATIC_LIB})
447469
else ()
448470
target_link_libraries (orc_protobuf INTERFACE ${PROTOBUF_LIBRARY})
449471
endif()
450-
target_include_directories (orc_protobuf SYSTEM INTERFACE ${PROTOBUF_INCLUDE_DIR})
472+
if (ORC_PACKAGE_KIND STREQUAL "conan")
473+
target_include_directories (orc_protobuf SYSTEM INTERFACE ${protobuf_INCLUDE_DIR})
474+
else ()
475+
target_include_directories (orc_protobuf SYSTEM INTERFACE ${PROTOBUF_INCLUDE_DIR})
476+
endif ()
451477

452-
if (ORC_PREFER_STATIC_PROTOBUF AND ${PROTOC_STATIC_LIB})
478+
if (ORC_PACKAGE_KIND STREQUAL "conan")
479+
cmake_path(GET protobuf_INCLUDE_DIR PARENT_PATH PROTOBUF_HOME)
480+
set(PROTOBUF_EXECUTABLE ${PROTOBUF_HOME}/bin/protoc)
481+
elseif (ORC_PREFER_STATIC_PROTOBUF AND ${PROTOC_STATIC_LIB})
453482
target_link_libraries (orc_protoc INTERFACE ${PROTOC_STATIC_LIB})
454483
else ()
455484
target_link_libraries (orc_protoc INTERFACE ${PROTOC_LIBRARY})

conan/conandata.yml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
sources:
19+
"1.9.2":
20+
url: "https://dlcdn.apache.org/orc/orc-1.9.2/orc-1.9.2.tar.gz"
21+
sha256: "7f46f2c184ecefd6791f1a53fb062286818bd8710c3f08b94dd3cac365e240ee"
22+
"1.8.6":
23+
url: "https://dlcdn.apache.org/orc/orc-1.8.6/orc-1.8.6.tar.gz"
24+
sha256: "5675b18118df4dd7f86cc6ba859ed75b425ea1b7ddff805e1d671a17fd57d7f7"
25+
"1.7.10":
26+
url: "https://dlcdn.apache.org/orc/orc-1.7.10/orc-1.7.10.tar.gz"
27+
sha256: "85aef9368dc9bcdffaaf10010b66dfe053ce22f30b64854f63852248164686a3"
28+
patches:
29+
"1.9.2":
30+
- patch_file: "patches/0001-thirdparty-toolchain-1.9.x.patch"
31+
"1.8.6":
32+
- patch_file: "patches/0001-thirdparty-toolchain-1.8.x.patch"
33+
"1.7.10":
34+
- patch_file: "patches/0001-thirdparty-toolchain-1.7.x.patch"

conan/conanfile.py

+120
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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+
from conan import ConanFile
19+
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout, CMakeDeps
20+
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rmdir
21+
from conan.tools.scm import Version
22+
23+
import os
24+
25+
required_conan_version = ">=1.54.0"
26+
27+
class OrcRecipe(ConanFile):
28+
name = "orc"
29+
description = "The smallest, fastest columnar storage for Hadoop workloads"
30+
license = "Apache-2.0"
31+
url = "https://github.com/conan-io/conan-center-index"
32+
homepage = "https://orc.apache.org/"
33+
topics = ("orc", "columnar-storage", "hadoop")
34+
settings = "os", "compiler", "build_type", "arch"
35+
options = {
36+
"shared": [False],
37+
"fPIC": [True, False],
38+
}
39+
default_options = {
40+
"shared": False,
41+
"fPIC": True,
42+
}
43+
44+
@property
45+
def _minimum_cpp_standard(self):
46+
return 11 if Version(self.version) < "1.9.0" else 17
47+
48+
def source(self):
49+
if not self.version in self.conan_data.get("sources", {}):
50+
import shutil
51+
top_level = os.environ.get("ORC_HOME")
52+
shutil.copytree(os.path.join(top_level, "c++"),
53+
os.path.join(self.source_folder, "c++"))
54+
shutil.copytree(os.path.join(top_level, "cmake_modules"),
55+
os.path.join(self.source_folder, "cmake_modules"))
56+
top_level_files = [
57+
"CMakeLists.txt",
58+
"LICENSE",
59+
"NOTICE",
60+
]
61+
for top_level_file in top_level_files:
62+
shutil.copy(os.path.join(top_level, top_level_file),
63+
self.source_folder)
64+
return
65+
get(self, **self.conan_data["sources"][self.version], strip_root=True)
66+
67+
def config_options(self):
68+
if self.settings.os == "Windows":
69+
self.options.rm_safe("fPIC")
70+
71+
def configure(self):
72+
if self.options.shared:
73+
self.options.rm_safe("fPIC")
74+
75+
def export_sources(self):
76+
export_conandata_patches(self)
77+
78+
def requirements(self):
79+
self.requires("protobuf/3.19.4")
80+
self.requires("zlib/1.3")
81+
self.requires("snappy/1.1.9")
82+
self.requires("lz4/1.9.4")
83+
self.requires("zstd/1.5.5")
84+
85+
def layout(self):
86+
cmake_layout(self, src_folder="src", build_folder="build")
87+
88+
def generate(self):
89+
deps = CMakeDeps(self)
90+
deps.generate()
91+
tc = CMakeToolchain(self)
92+
tc.variables["ORC_PACKAGE_KIND"] = "conan"
93+
tc.variables["BUILD_JAVA"] = "OFF"
94+
tc.variables["BUILD_CPP_TESTS"] = "OFF"
95+
tc.variables["BUILD_TOOLS"] = "OFF"
96+
tc.variables["BUILD_LIBHDFSPP"] = "OFF"
97+
tc.variables["BUILD_POSITION_INDEPENDENT_LIB"] = bool(self.options.get_safe("fPIC", True))
98+
tc.variables["INSTALL_VENDORED_LIBS"] = "OFF"
99+
tc.generate()
100+
101+
def build(self):
102+
apply_conandata_patches(self)
103+
cmake = CMake(self)
104+
cmake.configure()
105+
cmake.build()
106+
107+
def package(self):
108+
copy(self, pattern="LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
109+
copy(self, pattern="NOTICE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
110+
cmake = CMake(self)
111+
cmake.install()
112+
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
113+
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
114+
rmdir(self, os.path.join(self.package_folder, "share"))
115+
116+
def package_info(self):
117+
self.cpp_info.set_property("cmake_file_name", "orc")
118+
self.cpp_info.set_property("cmake_target_name", "orc::orc")
119+
self.cpp_info.set_property("pkg_config_name", "liborc")
120+
self.cpp_info.libs = ["orc"]

0 commit comments

Comments
 (0)