Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ endif ()
if (POLICY CMP0079)
cmake_policy(SET CMP0079 NEW)
endif ()
include(GNUInstallDirs)
set(TsFile_CPP_VERSION 2.3.2.dev)

if (MSVC)
Expand Down Expand Up @@ -305,3 +306,5 @@ else()
endif ()

add_subdirectory(examples)

include(${CMAKE_SOURCE_DIR}/cmake/TsFileCPack.cmake)
62 changes: 61 additions & 1 deletion cpp/README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,15 @@ https://github.com/apache/tsfile/issues/94

```bash
sudo apt-get update
sudo apt-get install -y cmake make g++ clang-format libuuid-dev
sudo apt-get install -y cmake make g++ clang-format libuuid-dev dpkg-dev
```

在 RHEL/CentOS/Fedora 系统上,可使用 `yum` 或 `dnf` 安装对应依赖:

```bash
sudo yum install -y cmake make gcc-c++ clang-tools-extra libuuid-devel rpm-build
# 或
sudo dnf install -y cmake make gcc-c++ clang-tools-extra libuuid-devel rpm-build
```

构建 tsfile:
Expand All @@ -115,6 +123,58 @@ mvn package -P with-cpp clean verify

在向 GitHub 提交代码之前,请确保 `mvn` 编译通过。

### 构建 Linux 安装包

C++ CMake 构建可以生成 Linux 发行版可安装包:

- Debian/Ubuntu:`libtsfile`、`libtsfile-dev`、`tsfile-cli` DEB 包
- RHEL/CentOS/Fedora:`libtsfile`、`libtsfile-devel`、`tsfile-cli` RPM 包

在仓库根目录下,Maven 会先构建 C++ 模块,然后调用 CPack:

```bash
./mvnw package -P with-cpp
```

如果只需要快速生成安装包、不运行 C++ 测试:

```bash
./mvnw package -P with-cpp -Dbuild.test=OFF -DskipTests
```

也可以在 `cpp/` 目录下直接调用 CMake:

```bash
cmake -S . -B build/package -DCMAKE_BUILD_TYPE=Release
cmake --build build/package --target package
```

如果只需要生成其中一种包格式,可以在构建目录下直接运行 `cpack`:

```bash
cd build/package
cpack -G DEB
cpack -G RPM
```

使用 `apt` 安装生成的 DEB 包:

```bash
sudo apt install ./libtsfile_*.deb ./libtsfile-dev_*.deb ./tsfile-cli_*.deb
```

使用 `yum` 或 `dnf` 安装生成的 RPM 包:

```bash
sudo yum install ./libtsfile-*.rpm ./libtsfile-devel-*.rpm ./tsfile-cli-*.rpm
# 或
sudo dnf install ./libtsfile-*.rpm ./libtsfile-devel-*.rpm ./tsfile-cli-*.rpm
```

安装包会把共享库安装到系统库目录,头文件安装到 `/usr/include/tsfile`,
CMake 包配置安装到 `/usr/lib/cmake/tsfile` 或 `/usr/lib64/cmake/tsfile`,
命令行工具安装为 `/usr/bin/tsfile-cli`。

---

### Windows 下 MinGW 编译问题
Expand Down
64 changes: 63 additions & 1 deletion cpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,16 @@ TsFile C++ supports three toolchains:
**Linux (GCC/Clang):**
```bash
sudo apt-get update
sudo apt-get install -y cmake make g++ clang-format libuuid-dev
sudo apt-get install -y cmake make g++ clang-format libuuid-dev dpkg-dev
```

On RHEL/CentOS/Fedora systems, install the equivalent packages with `yum` or
`dnf`:

```bash
sudo yum install -y cmake make gcc-c++ clang-tools-extra libuuid-devel rpm-build
# or
sudo dnf install -y cmake make gcc-c++ clang-tools-extra libuuid-devel rpm-build
```

**Windows (MSVC):**
Expand Down Expand Up @@ -136,6 +145,59 @@ Then you can find the shared library at `./cpp/target/build/lib`.

Before you submit your code to GitHub, please ensure that the compilation is correct.

### Build Linux Packages

The C++ CMake build can generate installable packages for Linux distributions:

- Debian/Ubuntu: `libtsfile`, `libtsfile-dev`, `tsfile-cli` DEB packages
- RHEL/CentOS/Fedora: `libtsfile`, `libtsfile-devel`, `tsfile-cli` RPM packages

From the repository root, Maven builds the C++ module and then invokes CPack:

```bash
./mvnw package -P with-cpp
```

For a faster package-only build without running C++ tests:

```bash
./mvnw package -P with-cpp -Dbuild.test=OFF -DskipTests
```

To invoke CMake directly from the `cpp/` directory:

```bash
cmake -S . -B build/package -DCMAKE_BUILD_TYPE=Release
cmake --build build/package --target package
```

To generate only one package format, run `cpack` from the build directory:

```bash
cd build/package
cpack -G DEB
cpack -G RPM
```

Install the generated DEB packages with `apt`:

```bash
sudo apt install ./libtsfile_*.deb ./libtsfile-dev_*.deb ./tsfile-cli_*.deb
```

Install the generated RPM packages with `yum` or `dnf`:

```bash
sudo yum install ./libtsfile-*.rpm ./libtsfile-devel-*.rpm ./tsfile-cli-*.rpm
# or
sudo dnf install ./libtsfile-*.rpm ./libtsfile-devel-*.rpm ./tsfile-cli-*.rpm
```

The packages install the shared library under the system library directory,
headers under `/usr/include/tsfile`, CMake package files under
`/usr/lib/cmake/tsfile` or `/usr/lib64/cmake/tsfile`, and the CLI as
`/usr/bin/tsfile-cli`.

### configure the cross-compilation toolchain

Modify the Toolchain File `cmake/ToolChain.cmake`, define the following variables:
Expand Down
97 changes: 97 additions & 0 deletions cpp/cmake/TsFileCPack.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#[[
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
]]

set(TSFILE_ROOT_DIR ${CMAKE_SOURCE_DIR}/..)
set(TSFILE_DOC_FILES "")
foreach(doc_file LICENSE NOTICE)
if (EXISTS ${TSFILE_ROOT_DIR}/${doc_file})
list(APPEND TSFILE_DOC_FILES ${TSFILE_ROOT_DIR}/${doc_file})
endif()
endforeach()

if (TSFILE_DOC_FILES)
install(FILES ${TSFILE_DOC_FILES}
DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/libtsfile
COMPONENT runtime)
install(FILES ${TSFILE_DOC_FILES}
DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/libtsfile-dev
COMPONENT development)
install(FILES ${TSFILE_DOC_FILES}
DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/tsfile-cli
COMPONENT tools)
endif()

set(CPACK_PACKAGE_NAME "apache-tsfile")
set(CPACK_PACKAGE_VENDOR "Apache Software Foundation")
set(CPACK_PACKAGE_CONTACT "Apache TsFile Developers <dev@tsfile.apache.org>")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://tsfile.apache.org/")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Apache TsFile C++ library and command-line tools")
set(CPACK_PACKAGE_VERSION ${TsFile_CPP_VERSION})
if (TsFile_CPP_VERSION MATCHES "^([0-9]+)\\.([0-9]+)\\.([0-9]+)")
set(CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_MATCH_1})
set(CPACK_PACKAGE_VERSION_MINOR ${CMAKE_MATCH_2})
set(CPACK_PACKAGE_VERSION_PATCH ${CMAKE_MATCH_3})
endif()
set(CPACK_PACKAGE_FILE_NAME
"apache-tsfile-${CPACK_PACKAGE_VERSION}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}")
if (EXISTS ${TSFILE_ROOT_DIR}/LICENSE)
set(CPACK_RESOURCE_FILE_LICENSE ${TSFILE_ROOT_DIR}/LICENSE)
endif()

set(CPACK_COMPONENTS_ALL runtime development tools)
set(CPACK_COMPONENT_RUNTIME_DISPLAY_NAME "libtsfile")
set(CPACK_COMPONENT_RUNTIME_DESCRIPTION "Apache TsFile shared library.")
set(CPACK_COMPONENT_DEVELOPMENT_DISPLAY_NAME "libtsfile development files")
set(CPACK_COMPONENT_DEVELOPMENT_DESCRIPTION
"Apache TsFile C/C++ headers and CMake package files.")
set(CPACK_COMPONENT_DEVELOPMENT_DEPENDS runtime)
set(CPACK_COMPONENT_TOOLS_DISPLAY_NAME "tsfile-cli")
set(CPACK_COMPONENT_TOOLS_DESCRIPTION "Apache TsFile command-line tool.")
set(CPACK_COMPONENT_TOOLS_DEPENDS runtime)

set(CPACK_GENERATOR "TGZ")
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
list(APPEND CPACK_GENERATOR "DEB" "RPM")
endif()
set(CPACK_PACKAGING_INSTALL_PREFIX "/usr")

set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS ON)
set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT})
set(CPACK_DEBIAN_RUNTIME_PACKAGE_NAME "libtsfile")
set(CPACK_DEBIAN_RUNTIME_PACKAGE_SECTION "libs")
set(CPACK_DEBIAN_RUNTIME_PACKAGE_SHLIBDEPS ON)
set(CPACK_DEBIAN_DEVELOPMENT_PACKAGE_NAME "libtsfile-dev")
set(CPACK_DEBIAN_DEVELOPMENT_PACKAGE_SECTION "libdevel")
set(CPACK_DEBIAN_TOOLS_PACKAGE_NAME "tsfile-cli")
set(CPACK_DEBIAN_TOOLS_PACKAGE_SECTION "database")

set(CPACK_RPM_COMPONENT_INSTALL ON)
set(CPACK_RPM_FILE_NAME "RPM-DEFAULT")
set(CPACK_RPM_PACKAGE_LICENSE "Apache-2.0")
set(CPACK_RPM_PACKAGE_VENDOR ${CPACK_PACKAGE_VENDOR})
set(CPACK_RPM_RUNTIME_PACKAGE_NAME "libtsfile")
set(CPACK_RPM_RUNTIME_PACKAGE_GROUP "System Environment/Libraries")
set(CPACK_RPM_DEVELOPMENT_PACKAGE_NAME "libtsfile-devel")
set(CPACK_RPM_DEVELOPMENT_PACKAGE_GROUP "Development/Libraries")
set(CPACK_RPM_TOOLS_PACKAGE_NAME "tsfile-cli")
set(CPACK_RPM_TOOLS_PACKAGE_GROUP "Applications/Databases")

include(CPack)
25 changes: 25 additions & 0 deletions cpp/cmake/TsFileConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#[[
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
]]

@PACKAGE_INIT@

include(CMakeFindDependencyMacro)
find_dependency(Threads)

include("${CMAKE_CURRENT_LIST_DIR}/TsFileTargets.cmake")
17 changes: 17 additions & 0 deletions cpp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@
<config>${build.type}</config>
</configuration>
</execution>
<!-- Build the CPack package target during the Maven package phase. -->
<execution>
<id>cmake-package</id>
<phase>package</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<!--
Build configuration for multi-config generators
(Visual Studio). Ignored by single-config
generators such as the Makefile generators.
-->
<config>${build.type}</config>
<target>package</target>
</configuration>
</execution>
<!-- Execute the tests -->
<execution>
<id>cmake-run-tests</id>
Expand Down
Loading
Loading