尽管使用了BOOST_ROOT,但找不到我当地的Boost发行版而不是已安装的发行版

时间:2012-03-15 03:36:59

标签: linux boost cmake

我对FindBoost有疑问。我正在尝试从已经安装了默认增强1.47的HPC(redhat)上的我自己的boost 1.49发行版中选择boost组件。 我想独家使用我的,我一直在尝试使用BOOST_ROOT作为缓存变量,内部缓存变量和使用set(ENV {BOOST_ROOT})的环境变量,但没有任何作用:我可以看到BOOST_ROOT已正确设置(指向1.49.0版本),但似乎它对FindBoost生成的库路径没有影响:它们都指向1.47.0版本中的库。 我正在尝试这个:

# I give a chance to the user to set BOOST_PATH to the local boost distribution before calling FindBoost
if( NOT DEFINED BOOST_PATH)
    message(STATUS " Set BOOST_PATH to a specific Boost distribution if needed.")
    set(BOOST_PATH "Default" CACHE PATH "Set the path to a specific Boost distribution if not default.")

# On the second pass, I use BOOST_PATH to initialize BOOST_ROOT, hoping that FindBoost will use it to find my local version.
else(   NOT DEFINED BOOST_PATH)
    if( NOT (BOOST_PATH MATCHES "Default"))
        set(BOOST_ROOT ${BOOST_PATH} CACHE PATH "path to the preferred boost distribution.")
    endif(NOT (BOOST_PATH MATCHES "Default"))

    # I test to make sure the path in   BOOST_ROOT is what I expect: it is on the console, as well as in the cache
    message("BOOST_ROOT = ${BOOST_ROOT}")

    set(Boost_USE_MULTITHREADED      ON)
    set(Boost_USE_STATIC_LIBS        ON)
    set(Boost_ADDITIONAL_VERSIONS    "1.42" "1.42.0" 
                             "1.43" "1.43.0" 
                             "1.44" "1.44.0" 
                             "1.45" "1.45.0" 
                             "1.46" "1.46.0" "1.46.1"
                             "1.47" "1.47.0"
                             "1.48" "1.48.0"
                             "1.49" "1.49.0"
                             ${BOOST_ADDITIONAL_VERSION}
    )
    set(Boost_DEBUG                  TRUE) # Debugging info output for FindBoost
    set(Boost_DETAILED_FAILURE_MSG   TRUE) # Set to FALSE by default


    # I invoke FindBoost here, but although BOOST_ROOT points to my local boost, all the paths of the 3 components points to the installed debug/release variants, not to my local distribution.  
    find_package( Boost COMPONENTS date_time filesystem system program_options )

# unimportant code
[...]

endif(  NOT DEFINED BOOST_PATH)

如果你能帮助我,我将不胜感激。非常感谢你提前。

尼古拉斯

1 个答案:

答案 0 :(得分:4)

在较新版本的FindBoost.cmake(CMake 2.8.x)中,有一个变量可以设置为影响脚本寻找Boost的搜索路径。

它被称为Boost_NO_SYSTEM_PATHS,如果它被设置为TRUE,则不会查看系统位置中安装的库。

我必须在我的一些项目中执行此操作,因为两个Boost安装的库被find_package()脚本混淆了。