CMake在同一台机器

时间:2016-09-26 08:18:32

标签: boost cmake

Boost编译库与x86和x64具有相同的名称。我的项目使用Boost,我希望它在使用CMake for x64或x86 target进行编译时自动链接正确的Boost库

我的CMakeFiles.txt使用简单的代码

find_package(Boost REQUIRED
    COMPONENTS
    coroutine context thread filesystem program_options system
)

My Boost是使用(MSVC2015)构建的

b2 address-model=32 --build-type=minimal stage --stagedir stage
b2 address-model=64 --build-type=minimal stage --stagedir stage64

我也试过"安装"目标并将boost版本放入单独的文件夹

我正在使用(Windows)

构建我的项目
md build32
cd build32
cmake .. -G"Visual Studio 14 2015"
cmake --build .
cd ..

md build
cb build
cmake .. -G"Visual Studio 14 2015 Win64"
cmake --build .
cd ..

x86 target是成功构建的,因为它的库(boost)正处于" stage" CMake的FindBoost模块众所周知的文件夹

但是x64目标无法构建,因为FindBoost使用Boost的x86库来构建进程,并且不会尝试使用来自" stage64"有这个错误:

  

D:\ lib \ boost_1_61_0 \ stage \ lib \ libboost_coroutine-vc140-mt-gd-1_61.lib:警告LNK4272:库机器类型' X86'与目标机器类型冲突' x64'

我的目标是在" Cmake"中排除任何额外的参数。调用构建我的项目,我希望它能自动找到x86或x64的正确升级库,具体取决于我使用的CMAKE -G参数

如何更改我的CMakeFiles.txt以使其自动找到正确的boost库?

Boost版本 - 1.61,MSVC 2015,CMAKE - 3.6.2(最新且有关于boost 1.61的知识),Windows 7 x64

1 个答案:

答案 0 :(得分:3)

我猜你已经在你的项目,缓存或环境变量中设置了BOOST_ROOT

查看sources,您可以通过设置Boost_LIBRARY_DIR来缩短查找过程。使用CMAKE_SIZEOF_VOID_P检测架构:

if(CMAKE_SIZEOF_VOID_P EQUAL 8)
    set(Boost_LIBRARY_DIR ${BOOST_ROOT}/stage64/lib
elseif(CMAKE_SIZEOF_VOID_P EQUAL 4)
    set(Boost_LIBRARY_DIR ${BOOST_ROOT}/stage/lib
endif()

find_package(...)

${BOOST_ROOT}可能会被$ENV{BOOST_ROOT}替换。

相关问题