Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to using ament_vendor_package for lz4. #1583

Merged
merged 3 commits into from Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 26 additions & 0 deletions liblz4_vendor/CMakeLists.txt
@@ -0,0 +1,26 @@
cmake_minimum_required(VERSION 3.10)
project(liblz4_vendor)

find_package(ament_cmake REQUIRED)
find_package(ament_cmake_vendor_package REQUIRED)

ament_add_default_options()

list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
find_package(lz4 QUIET)

ament_vendor(liblz4_vendor
SATISFIED ${lz4_FOUND}
VCS_URL https://github.com/lz4/lz4.git
VCS_VERSION v1.9.4
SOURCE_SUBDIR build/cmake
CMAKE_ARGS
-DBUILD_STATIC_LIBS:BOOL=OFF
-DBUILD_SHARED_LIBS:BOOL=${BUILD_SHARED_LIBS}
-DLZ4_BUILD_LEGACY_LZ4C:BOOL=OFF
-DLZ4_BUILD_CLI:BOOL=OFF
)

install(DIRECTORY cmake DESTINATION share/${PROJECT_NAME})

ament_package(CONFIG_EXTRAS liblz4_vendor-extras.cmake)
12 changes: 12 additions & 0 deletions liblz4_vendor/README.md
@@ -0,0 +1,12 @@
# liblz4_vendor

Vendor package for the [LZ4](https://github.com/lz4/lz4) library.

The licensing on lz4 is complicated; see
https://github.com/lz4/lz4/blob/a3be31154f2e4c928ae6dcba9fe7e89e7678c74b/LICENSE
for details. In short, the library itself (everything in the lib directory)
is BSD, while everything else in the package is GPLv2.

ROS 2 only wants to depend on the BSD-licensed portion, so the name of this
package is very specifically chosen to emphasize that we are only vendoring
the library.
54 changes: 54 additions & 0 deletions liblz4_vendor/cmake/Modules/Findlz4.cmake
@@ -0,0 +1,54 @@
# Get package location hint from environment variable (if any)
if(NOT lz4_ROOT_DIR AND DEFINED ENV{lz4_ROOT_DIR})
set(lz4_ROOT_DIR "$ENV{lz4_ROOT_DIR}" CACHE PATH
"lz4 base directory location (optional, used for nonstandard installation paths)")
endif()

# Search path for nonstandard package locations
if(lz4_ROOT_DIR)
set(lz4_INCLUDE_PATH PATHS "${lz4_ROOT_DIR}/include" NO_DEFAULT_PATH)
set(lz4_LIBRARY_PATH PATHS "${lz4_ROOT_DIR}/lib" NO_DEFAULT_PATH)
else()
set(lz4_INCLUDE_PATH "")
set(lz4_LIBRARY_PATH "")
endif()

# Find headers and libraries
find_path(lz4_INCLUDE_DIR NAMES lz4.h PATH_SUFFIXES "lz4" ${lz4_INCLUDE_PATH})
find_library(lz4_LIBRARY NAMES lz4 PATH_SUFFIXES "lz4" ${lz4_LIBRARY_PATH})

if (lz4_INCLUDE_DIR)
file(STRINGS "${lz4_INCLUDE_DIR}/lz4.h" version-file
REGEX "#define[ \t]+LZ4_VERSION_(MAJOR|MINOR|RELEASE).*")
list(GET version-file 0 major-line)
list(GET version-file 1 minor-line)
list(GET version-file 2 release-line)
string(REGEX REPLACE "^#define[ \t]+LZ4_VERSION_MAJOR[ \t]+([0-9]+).*$" "\\1" LZ4_VERSION_MAJOR ${major-line})
string(REGEX REPLACE "^#define[ \t]+LZ4_VERSION_MINOR[ \t]+([0-9]+).*$" "\\1" LZ4_VERSION_MINOR ${minor-line})
string(REGEX REPLACE "^#define[ \t]+LZ4_VERSION_RELEASE[ \t]+([0-9]+).*$" "\\1" LZ4_VERSION_RELEASE ${release-line})
set(lz4_VERSION ${LZ4_VERSION_MAJOR}.${LZ4_VERSION_MINOR}.${LZ4_VERSION_RELEASE})
endif()

mark_as_advanced(lz4_INCLUDE_DIR lz4_LIBRARY)

# Output variables generation
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(lz4 REQUIRED_VARS lz4_LIBRARY lz4_INCLUDE_DIR
VERSION_VAR lz4_VERSION)

set(lz4_FOUND ${LZ4_FOUND}) # Enforce case-correctness: Set appropriately cased variable...
unset(LZ4_FOUND) # ...and unset uppercase variable generated by find_package_handle_standard_args

if(lz4_FOUND)
set(lz4_INCLUDE_DIRS ${lz4_INCLUDE_DIR})
set(lz4_LIBRARIES ${lz4_LIBRARY})

if(NOT TARGET LZ4::lz4)
add_library(LZ4::lz4 UNKNOWN IMPORTED)
set_property(TARGET LZ4::lz4 PROPERTY IMPORTED_LOCATION ${lz4_LIBRARY})
set_property(TARGET LZ4::lz4 PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${lz4_INCLUDE_DIR})
endif()
list(APPEND lz4_TARGETS LZ4::lz4)
elseif(lz4_FIND_REQUIRED)
message(FATAL_ERROR "Unable to find lz4")
endif()
1 change: 1 addition & 0 deletions liblz4_vendor/liblz4_vendor-extras.cmake
@@ -0,0 +1 @@
list(INSERT CMAKE_MODULE_PATH 0 "${liblz4_vendor_DIR}/Modules")
25 changes: 25 additions & 0 deletions liblz4_vendor/package.xml
@@ -0,0 +1,25 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
<name>liblz4_vendor</name>
<version>0.24.0</version>
<description>LZ4 compression vendor package, providing a dependency for LZ4.</description>
<maintainer email="michael.orlov@apex.ai">Michael Orlov</maintainer>
<maintainer email="me@emersonknapp.com">Emerson Knapp</maintainer>
<maintainer email="ros-tooling@googlegroups.com">ROS Tooling Working Group</maintainer>
<license>Apache License 2.0</license> <!-- the contents of this package are Apache 2.0 -->
<license>BSD</license> <!-- The LZ4 library is BSD; see README.md for more information -->
<license>GPLv2</license> <!-- All other LZ4 files are GPLv2; see README.md for more information -->

<url type="website">https://github.com/lz4/lz4/</url>

<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>ament_cmake_vendor_package</buildtool_depend>

<build_depend>liblz4-dev</build_depend>
<exec_depend>liblz4</exec_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
25 changes: 7 additions & 18 deletions mcap_vendor/CMakeLists.txt
@@ -1,8 +1,10 @@
cmake_minimum_required(VERSION 3.5)
project(mcap_vendor LANGUAGES C CXX ASM)
cmake_minimum_required(VERSION 3.14)
project(mcap_vendor LANGUAGES C CXX)

## Dependencies
find_package(ament_cmake REQUIRED)
find_package(liblz4_vendor REQUIRED)
find_package(lz4 REQUIRED)
find_package(zstd_vendor REQUIRED)
find_package(zstd REQUIRED)

Expand All @@ -18,7 +20,7 @@ if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic -Werror)
add_compile_options(-Wall -Wextra -Wpedantic)
clalancette marked this conversation as resolved.
Show resolved Hide resolved
endif()
if (MSVC)
add_compile_options(/W4 /WX
Expand All @@ -37,31 +39,18 @@ macro(build_mcap_vendor)
)
fetchcontent_makeavailable(mcap)

fetchcontent_declare(lz4
GIT_REPOSITORY https://github.com/lz4/lz4.git
GIT_TAG d44371841a2f1728a3f36839fd4b7e872d0927d3 # v1.9.3
)
fetchcontent_makeavailable(lz4)

file(GLOB _lz4_srcs
${lz4_SOURCE_DIR}/lib/*.c)

add_library(mcap SHARED
src/main.cpp
${_lz4_srcs}
)

set(_mcap_include_dir ${mcap_SOURCE_DIR}/cpp/mcap/include)
file(GLOB _mcap_installed_headers ${_mcap_include_dir}/mcap/*.hpp)

target_include_directories(mcap PRIVATE
${lz4_SOURCE_DIR}/lib
)
target_include_directories(mcap PUBLIC
"$<BUILD_INTERFACE:${_mcap_include_dir}>"
"$<INSTALL_INTERFACE:include/${PROJECT_NAME}>"
)
target_link_libraries(mcap zstd::zstd)
target_link_libraries(mcap LZ4::lz4 zstd::zstd)

install(
FILES ${_mcap_installed_headers}
Expand All @@ -82,7 +71,7 @@ build_mcap_vendor()

ament_export_include_directories(include/${PROJECT_NAME})
ament_export_targets(mcap HAS_LIBRARY_TARGET)
ament_export_dependencies(zstd_vendor zstd)
ament_export_dependencies(liblz4_vendor lz4 zstd_vendor zstd)

## Package
ament_package()
1 change: 1 addition & 0 deletions mcap_vendor/package.xml
Expand Up @@ -12,6 +12,7 @@
<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>git</buildtool_depend>

<depend>liblz4_vendor</depend>
<depend>zstd_vendor</depend>

<export>
Expand Down