[CMake] FindBoost.cmake updated on the bugtracker

Matthew Woehlke mw_triad at users.sourceforge.net
Tue Apr 1 17:37:42 EDT 2008


Andreas Pakulat wrote:
> On 31.03.08 20:14:00, Matthew Woehlke wrote:
>> Andreas Pakulat wrote:
>>> Hi,
>>>
>>> just wanted to let interested parties know that I've added a new version
>>> of FindBoost.cmake to bug #6257. It fixes a few bugs I still had in
>>> v2.
>>>
>>> I'd delete the existing versions, but unfortunately CMake's bugtracker
>>> doesn't allow to do that.
>>>
>>> Last but not least: Is there any chance of getting this into CMake
>>> 2.6.0? Or is it too late?
>> I cross-posted here with my own updates a few days ago, but only Andreas  
>> replied last time.
>>
>> I still have some issues with the current version (assuming it is the  
>> same as the one in KDE's trunk), due to the prefix searching. I guess  
>> this could be fixed by looping through the prefixes twice, once for  
>> NO_DEFAULT_PATHS and once without. My solution was to assign two  
>> different variables for each FIND_PATH type (with and without default  
>> paths) and prefer anything found by NO_DEFAULT_PATHS.
> 
> I don't understand why you need that, except if your locally installed
> version is older than the version in /usr/. Is that the case? Else the
> second find_path won't execute if before that your locally installed
> version has been found.

But it hasn't been, because the no_default fails the first time(s).

> Also note that those variables you use in
> find_path are automatically cached and I don't think they should appear
> in it.
> 
> Apart from that, you're iterating over all test versions, thats
> unecessary.

Um... no. Here's what happens without the patch:

find_path(no_default, prefix 1.35) -> no match
find_path(default, prefix 1.35) -> /usr/include
STOP <-- bad!

Here's what should happen:
find_path(no_default, prefix 1.35) -> no match
find_path(default, prefix 1.35) -> /usr/include
--> ok; we found a default but not a preferred
find_path(no_default, prefix 1.34.1) -> BOOST_ROOT
--> we found a preferred, so now we use that instead of default
--> find_path(default) skipped because that's already filled in
..iterate over other prefixes...

Note that the FIND_PATH won't be re-run once both fallback and preferred 
are filled in. It wouldn't be hard to add logic to skip doing anything 
else of importance (i.e. re-extract the version) unless you've changed 
what path you're looking at. In fact, since we no longer check the 
version inside the loop (not sure if that's good or bad, though), all 
that should be moved out of the loop anyway.

An alternative is to run the prefix list through no_default, then again 
through default, which is roughly the same thing once you take the 
version extraction out of the loop.

Here's an updated patch (note that I used --ignore-all-spaces to diff so 
the indentation changes don't make it noisier than it needs to be):

Index: cmake/modules/FindBoost.cmake
===================================================================
--- cmake/modules/FindBoost.cmake       (revision 792601)
+++ cmake/modules/FindBoost.cmake       (working copy)
@@ -235,7 +235,6 @@


    FOREACH(_boost_VER ${_boost_TEST_VERSIONS})
-    IF( NOT Boost_INCLUDE_DIR )

        # Add in a path suffix, based on the required version, ideally 
we could
        # read this from version.hpp, but for that to work we'd need to 
know the include
@@ -250,20 +249,28 @@
            STRING(REGEX REPLACE "([0-9]+)\\.([0-9]+)" "\\1_\\2" 
_boost_PATH_SUFFIX ${_boost_PATH_SUFFIX})
        ENDIF(_boost_PATH_SUFFIX MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")

-
        #Prefer our include search paths
-      FIND_PATH(Boost_INCLUDE_DIR
+      FIND_PATH(Boost_PREFERRED_INCLUDE_DIR
            NAMES         boost/config.hpp
            PATHS         ${_boost_INCLUDE_SEARCH_DIRS}
            PATH_SUFFIXES ${_boost_PATH_SUFFIX}
            NO_DEFAULT_PATH
        )
        #If nothing is found search again using system default paths
-      FIND_PATH(Boost_INCLUDE_DIR
+      FIND_PATH(Boost_FALLBACK_INCLUDE_DIR
            NAMES         boost/config.hpp
            PATH_SUFFIXES ${_boost_PATH_SUFFIX}
        )
+      IF( Boost_PREFERRED_INCLUDE_DIR )
+        SET( Boost_INCLUDE_DIR ${Boost_PREFERRED_INCLUDE_DIR} )
+      ELSEIF( Boost_FALLBACK_INCLUDE_DIR )
+        SET( Boost_INCLUDE_DIR ${Boost_FALLBACK_INCLUDE_DIR} )
+      ELSE( Boost_PREFERRED_INCLUDE_DIR )
+        SET( Boost_INCLUDE_DIR Boost_INCLUDE_DIR-NOTFOUND )
+      ENDIF( Boost_PREFERRED_INCLUDE_DIR )

+  ENDFOREACH(_boost_VER)
+
        IF(Boost_INCLUDE_DIR)
          # Extract Boost_VERSION and Boost_LIB_VERSION from version.hpp
          # Read the whole file:
@@ -282,13 +289,9 @@
            MATH(EXPR Boost_MAJOR_VERSION "${Boost_VERSION} / 100000")
            MATH(EXPR Boost_MINOR_VERSION "${Boost_VERSION} / 100 % 1000")
            MATH(EXPR Boost_SUBMINOR_VERSION "${Boost_VERSION} % 100")
-
          ENDIF(NOT "${Boost_VERSION}" STREQUAL "0")
        ENDIF(Boost_INCLUDE_DIR)

-    ENDIF( NOT Boost_INCLUDE_DIR )
-  ENDFOREACH(_boost_VER)
-
    #Setting some more suffixes for the library
    SET (Boost_LIB_PREFIX "")
    IF ( WIN32 )

-- 
Matthew
Yesterday, I thought of the best .sig that has ever been contemplated. 
Alas, I forgot it before I could write it down.



More information about the CMake mailing list