View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0013439CMakeCMakepublic2012-07-25 17:332016-06-10 14:31
ReporterPieter Swinkels 
Assigned ToPhilip Lowman 
PrioritynormalSeverityminorReproducibilityalways
StatusclosedResolutionmoved 
PlatformLinuxOSUbuntuOS Version12.04
Product VersionCMake 2.8.7 
Target VersionFixed in Version 
Summary0013439: consecutive find_package(Boost ...) statements only find the static lib regardless of Boost_USE_STATIC_LIBS
DescriptionConsecutive find_package(Boost ...) statements for the same Boost component in the same file CMakeLists.txt but

  - the first time with Boost_USE_STATIC_LIBS to ON and
  - the second time with BOOST_USE_STATIC_LIBS to OFF

always finds the static library.
Steps To ReproduceTry something like this:

set(Boost_USE_STATIC_LIBS ON)

find_package(Boost COMPONENTS unit_test_framework REQUIRED)
if (Boost_FOUND)
  include_directories(${Boost_INCLUDE_DIRS})
endif (Boost_FOUND)

# ${BOOST_LIBRARIES} contains the static version of the library

add_executable(my-static-find-package-boost-test main-static.cpp)
target_link_libraries(my-static-find-package-boost-test ${Boost_LIBRARIES})

unset(Boost_LIBRARIES)
message("Boost_LIBRARIES: ${Boost_LIBRARIES}")

set(Boost_USE_STATIC_LIBS OFF)

find_package(Boost COMPONENTS unit_test_framework REQUIRED)
if (Boost_FOUND)
  include_directories(${Boost_INCLUDE_DIRS})
endif (Boost_FOUND)

# ${BOOST_LIBRARIES} still contains the static version of the library

add_executable(my-dynamic-find-package-boost-test main-dynamic.cpp)
target_link_libraries(my-dynamic-find-package-boost-test ${Boost_LIBRARIES})
Additional InformationIt is not that the dynamic library cannot be found. If I uncomment the first invocation, clear the cache (!) and run cmake, the dynamic library is found.
TagsNo tags attached.
Attached Files

 Relationships

  Notes
(0030151)
Rolf Eike Beer (developer)
2012-07-30 02:53

Your example can't work this way. You need to clear all the internal cache variables of Boost, otherwise it will just reconstruct BOOST_LIBRARIES from the stuff it already found.
(0030178)
Pieter Swinkels (reporter)
2012-08-06 15:30

Thank you for the reply. I would rather not make any assumptions about the internal cache variables so I better split up my CMake file list.

One thing, I found my approach on http://www.cmake.org/pipermail/cmake/2012-February/049175.html [^] so I was surprised to find it not working. On rereading that email, I see that it already warns me about this situation :(

  "IMO, FindBoost.cmake behaves bad in one regard: It accumulates results from different invocations within the same scope. For this reason, you must intermediately unset the Boost_LIBRARIES variable - and probably all further uncached result variables like Boost_INCLUDE_DIRS also."
(0030213)
Pieter Swinkels (reporter)
2012-08-10 16:35

There is a way to invalidate the Boost cache, see the answer to this question: http://stackoverflow.com/questions/11680168/how-can-i-optionally-link-against-static-or-dynamic-boost-library-using-cmake [^] I quote from that answer "To force the FindBoost CMake module to search for the desired libraries again, you have to clear the cache variables Boost_INCLUDE_DIR and Boost_LIBRARY_DIRS".

In my example, if I add the following statements after "set(Boost_USE_STATIC_LIBS OFF)",

unset(Boost_INCLUDE_DIR CACHE)
unset(Boost_LIBRARY_DIRS CACHE)

the shared library is indeed found.
(0031176)
Philip Lowman (developer)
2012-10-04 02:08

Hmm, did this issue go away when I removed the crazy caching behavior in 2.8.9?
(0042096)
Kitware Robot (administrator)
2016-06-10 14:28

Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.

 Issue History
Date Modified Username Field Change
2012-07-25 17:33 Pieter Swinkels New Issue
2012-07-30 02:53 Rolf Eike Beer Note Added: 0030151
2012-08-06 15:30 Pieter Swinkels Note Added: 0030178
2012-08-10 16:35 Pieter Swinkels Note Added: 0030213
2012-08-18 15:30 Philip Lowman Status new => assigned
2012-08-18 15:30 Philip Lowman Assigned To => Philip Lowman
2012-10-04 02:08 Philip Lowman Note Added: 0031176
2016-06-10 14:28 Kitware Robot Note Added: 0042096
2016-06-10 14:28 Kitware Robot Status assigned => resolved
2016-06-10 14:28 Kitware Robot Resolution open => moved
2016-06-10 14:31 Kitware Robot Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team