[CMake] Variable availability from the FindXXX modules

Tyler Roscoe tyler at cryptio.net
Fri Jun 12 15:29:00 EDT 2009


On Fri, Jun 12, 2009 at 02:42:28PM -0400, Michael Jackson wrote:
> think is a kludge to get it to work. In my top level CMakeLists.txt  
> file I "include" another CMake file which calls another project via  
> add_subdirectory(). With in that last call is a call to "FindBoost"  
> which goes just fine. Now work our way all the way back to the top of  
> the CMake file hierarchy and when I do "message(STATUS  
> "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}") I get an empty statement.

When you do add_subdirectory(), you create a new scope. The Boost
variables are only defined in that scope, which is why you can't see
them from your top-level CMakeLists.

>     I had to put in another call to:
> FIND_PACKAGE(Boost 1.36 COMPONENTS )
> INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
> message (STATUS "Boost_INCLUDE_DIRS: ${Boost_INCLUDE_DIRS}")
> 
> and now I get the proper print out. So effectively I have called  
> FindBoost at least twice. Would something like this be normal?

Can you just do find_package() from the top level?

If you're trying to preserve the independence of your subdir CMakeList,
maybe move the find_package() call to a common location where each
project can include() it independently? You could then use a re-entry
guard (if(NOT BOOST_ALREADY_FOUND)) to prevent multiple calls.

tyler


More information about the CMake mailing list