Skip to content

Commit

Permalink
Static library fixes (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
CCInc authored Jan 24, 2023
1 parent a6347ae commit bb5258c
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- **\[C++\]** Allow for building as static library with lazperf built externally

## [2.5.3] - 2022-10-27

### Fixed
Expand Down
16 changes: 12 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,21 @@ if(EXISTS "${CMAKE_SOURCE_DIR}/libs/laz-perf")
include_directories(libs/laz-perf/cpp)
set(WITH_TESTS ${WITH_TEST_TEMP})
set(LAZPERF_LIB_NAME "lazperf")
set(LAZPERF_IS_FOUND ON)
set(EXTRA_EXPORT_TARGETS "lazperf")
else()
# if not, assume lazperf is installed on the system
find_package(LAZPERF ${LAZPERF_VERSION} REQUIRED)
set(LAZPERF_LIB_NAME "LAZPERF::lazperf")
set(EXTRA_EXPORT_TARGETS "")
find_package(LAZPERF ${LAZPERF_VERSION})
if (LAZPERF_FOUND)
message("Using system-wide laz-perf")
# lazperf installed system-wide
set(LAZPERF_LIB_NAME "LAZPERF::lazperf")
set(EXTRA_EXPORT_TARGETS "")
else ()
# assume lazperf is compiled in tandem
message("Lazperf package not found, including ${LAZPERF_DIR}/cpp")
set(LAZPERF_LIB_NAME "lazperf")
set(EXTRA_EXPORT_TARGETS "lazperf")
endif ()
endif()

# Enable RPATH support for installed binaries and libraries
Expand Down
10 changes: 5 additions & 5 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ set(${LIBRARY_TARGET_NAME}_SRC
)

# Compile static library for pip wheels
if (WITH_PYTHON)
if (WITH_PYTHON OR NOT BUILD_SHARED_LIBS)
add_library(${LIBRARY_TARGET_NAME}-s STATIC ${${LIBRARY_TARGET_NAME}_SRC} ${${LIBRARY_TARGET_NAME}_HDR})
set_target_properties(${LIBRARY_TARGET_NAME}-s PROPERTIES VERSION ${${PROJECT_NAME}_VERSION})
target_include_directories(${LIBRARY_TARGET_NAME}-s PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
if (LAZPERF_IS_FOUND)
target_link_libraries(${LIBRARY_TARGET_NAME}-s PRIVATE lazperf_s)
else()
if (LAZPERF_FOUND)
target_link_libraries(${LIBRARY_TARGET_NAME}-s PRIVATE ${LAZPERF_LIB_NAME})
endif()
else ()
target_link_libraries(${LIBRARY_TARGET_NAME}-s PRIVATE lazperf_s)
endif ()
message(STATUS "Created target ${LIBRARY_TARGET_NAME}-s for export ${PROJECT_NAME}.")
endif()

Expand Down
3 changes: 3 additions & 0 deletions cpp/include/copc-lib/las/vlr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ namespace copc::las
using WktVlr = lazperf::wkt_vlr;
using EbVlr = lazperf::eb_vlr;

static const int VLR_HEADER_SIZE = 54;
static const int EVLR_HEADER_SIZE = 60;

// Gets the sum of the byte size the extra bytes will take up, for calculating point_record_len
int NumBytesFromExtraBytes(const std::vector<EbVlr::ebfield> &items);

Expand Down
5 changes: 3 additions & 2 deletions cpp/src/io/base_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "copc-lib/copc/copc_config.hpp"
#include "copc-lib/copc/extents.hpp"
#include "copc-lib/las/header.hpp"
#include "copc-lib/las/vlr.hpp"

#include <lazperf/readers.hpp>
#include <lazperf/vlr.hpp>
Expand Down Expand Up @@ -67,7 +68,7 @@ las::WktVlr BaseReader::ReadWktVlr(std::map<uint64_t, las::VlrHeader> &vlrs)
auto offset = FetchVlr(vlrs, "LASF_Projection", 2112);
if (offset != 0)
{
in_stream_->seekg(offset + lazperf::evlr_header::Size);
in_stream_->seekg(offset + las::EVLR_HEADER_SIZE);
return las::WktVlr::create(*in_stream_, static_cast<int>(vlrs[offset].data_length));
}
return las::WktVlr();
Expand All @@ -78,7 +79,7 @@ las::EbVlr BaseReader::ReadExtraBytesVlr(std::map<uint64_t, las::VlrHeader> &vlr
auto offset = FetchVlr(vlrs, "LASF_Spec", 4);
if (offset != 0)
{
in_stream_->seekg(offset + lazperf::vlr_header::Size);
in_stream_->seekg(offset + las::VLR_HEADER_SIZE);
return las::EbVlr::create(*in_stream_, static_cast<int>(vlrs[offset].data_length));
}
return las::EbVlr();
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/io/copc_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ CopcInfo Reader::ReadCopcInfoVlr(std::map<uint64_t, las::VlrHeader> &vlrs)
throw std::runtime_error("Reader::ReadCopcInfoVlr: COPC Info VLR was found in the wrong position, MUST be at "
"offset 375 as per COPC specs.");

in_stream_->seekg(offset + lazperf::vlr_header::Size);
in_stream_->seekg(offset + las::VLR_HEADER_SIZE);
return lazperf::copc_info_vlr::create(*in_stream_);
}

Expand All @@ -47,15 +47,15 @@ CopcExtents Reader::ReadCopcExtentsVlr(std::map<uint64_t, las::VlrHeader> &vlrs,
auto extended_offset = FetchVlr(vlrs, "rock_robotic", 10001);
if (offset != 0)
{
in_stream_->seekg(offset + lazperf::vlr_header::Size);
in_stream_->seekg(offset + las::VLR_HEADER_SIZE);
CopcExtents extents(las::CopcExtentsVlr::create(*in_stream_, static_cast<int>(vlrs[offset].data_length)),
static_cast<int8_t>(reader_->header().point_format_id),
static_cast<uint16_t>(eb_vlr.items.size()), extended_offset != 0);

// Load mean/var if they exist
if (extended_offset != 0)
{
in_stream_->seekg(extended_offset + lazperf::vlr_header::Size);
in_stream_->seekg(extended_offset + las::VLR_HEADER_SIZE);
extents.SetExtendedStats(
las::CopcExtentsVlr::create(*in_stream_, static_cast<int>(vlrs[extended_offset].data_length)));
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/io/copc_writer_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ size_t WriterInternal::OffsetToPointData() const
size_t base_laz_offset = laz::BaseWriter::OffsetToPointData();

// COPC VLR
size_t copc_info_vlr_size = (lazperf::vlr_header::Size + CopcInfo::VLR_SIZE_BYTES);
size_t copc_info_vlr_size = (las::VLR_HEADER_SIZE + CopcInfo::VLR_SIZE_BYTES);

// COPC Extents VLR
size_t copc_extents_vlr_size =
CopcExtents::ByteSize(GetConfig()->LasHeader()->PointFormatId(), GetConfig()->ExtraBytesVlr().items.size());
copc_extents_vlr_size += lazperf::vlr_header::Size;
copc_extents_vlr_size += las::VLR_HEADER_SIZE;
// If we store extended stats we need two extents VLRs
if (GetConfig()->CopcExtents()->HasExtendedStats())
copc_extents_vlr_size *= 2;
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/io/laz_base_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ size_t BaseWriter::OffsetToPointData() const
// LAS Extra Byte VLR
size_t las_eb_vlr_size = config_->ExtraBytesVlr().size();
if (las_eb_vlr_size > 0)
las_eb_vlr_size += lazperf::vlr_header::Size;
las_eb_vlr_size += las::VLR_HEADER_SIZE;

// LAZ VLR
size_t laz_vlr_size =
lazperf::laz_vlr(config_->LasHeader().PointFormatId(), config_->LasHeader().EbByteSize(), VARIABLE_CHUNK_SIZE)
.size();
laz_vlr_size += lazperf::vlr_header::Size;
laz_vlr_size += las::VLR_HEADER_SIZE;

return las::LasHeader::HEADER_SIZE_BYTES + las_eb_vlr_size + laz_vlr_size;
}
Expand Down
8 changes: 4 additions & 4 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ find_package(pybind11 CONFIG REQUIRED)

# add the python lib
pybind11_add_module(${COPC_PYTHON_LIB} bindings.cpp)
if (LAZPERF_IS_FOUND)
target_link_libraries(${COPC_PYTHON_LIB} PRIVATE lazperf_s copc-lib-s)
else()
if (LAZPERF_FOUND)
target_link_libraries(${COPC_PYTHON_LIB} PRIVATE ${LAZPERF_LIB_NAME} copc-lib-s)
endif()
else ()
target_link_libraries(${COPC_PYTHON_LIB} PRIVATE lazperf_s copc-lib-s)
endif ()

install(TARGETS ${COPC_PYTHON_LIB} DESTINATION .)

Expand Down

0 comments on commit bb5258c

Please sign in to comment.