Handling multiple FIND_PACKAGE calls in CMake

I have a quick question about a function FIND_PACKAGEin CMake. I have a project that uses point cloud library (PCL). PCL is Boost dependent, and my project also works. So, at the top of my CMakeLists.txt, I have the following:

FIND_PACKAGE(Boost REQUIRED COMPONENTS program_options)

# Preserve project Boost required libraries
SET(Boost_PROJECT_LIBRARIES ${Boost_LIBRARIES})

FIND_PACKAGE(PCL 1.6 REQUIRED COMPONENTS common search)

My project uses the Boost.program_options library, and PCL uses a few others. When executed FIND_PACKAGE(PCL ...), it overwrites the previous one ${Boost_LIBRARIES}with its own required libraries. I came up with a job to save the Boost libraries needed for my project and then find the PCL package.

My question for CMake gurus is the best way to deal with such things in CMake? Or maybe this is an error in the FindBoost.cmake or FindPCL.cmake modules?

+4
source share
1 answer

The search package for Boost fills the local variable (Boost_LIBRARIES) with libraries for the components you select. Call securely

find_package(Boost REQUIRED COMPONENTS program_options)

(or anything else) right before you want to use it. This will ensure that the variable is populated correctly for your executable.

/ , -. Qt, VTK 6.0 , Boost_LIBRARIES, find_package .

+2

All Articles