The example CMakeLists.txt
in
PCL’s doc
is a bit outdated.
Commands like include_directories
, link_directories
, add_definitions
should be replaced or avoid.
Instead, in modern CMake we should use target-specific commands like target_include_directories
, target_link_libraries
.
File tree:
. ├── CMakeLists.txt └── main.cpp
CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(PCL_TEST)
find_package(PCL REQUIRED)
add_executable(main)
target_sources(main PRIVATE main.cpp)
target_include_directories(main PRIVATE ${PCL_INCLUDE_DIRS})
target_link_libraries(main PRIVATE ${PCL_LIBRARIES})
target_compile_options(main PRIVATE ${PCL_DEFINITIONS})
main.cpp
(from this page)
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
int
main (int argc, char** argv)
{
pcl::PointCloud<pcl::PointXYZ> cloud;
// Fill in the cloud data
cloud.width = 5;
cloud.height = 1;
cloud.is_dense = false;
cloud.points.resize (cloud.width * cloud.height);
for (auto& point: cloud)
{
point.x = 1024 * rand () / (RAND_MAX + 1.0f);
point.y = 1024 * rand () / (RAND_MAX + 1.0f);
point.z = 1024 * rand () / (RAND_MAX + 1.0f);
}
pcl::io::savePCDFileASCII ("test_pcd.pcd", cloud);
std::cerr << "Saved " << cloud.size () << " data points to test_pcd.pcd." << std::endl;
for (const auto& point: cloud)
std::cerr << " " << point.x << " " << point.y << " " << point.z << std::endl;
return (0);
}
A cli example:
cmake -B build /path/to/dir/contains/CMakeListsTXT
cd build
make