我有一个 CMake 项目,有时我想针对静态 boost 库进行编译,但我也想让使用 cmake GUI 中的动态库变得容易。在我的顶级 CMakeLists.txt 我有这个:
option(USE_STATIC_BOOST "Build with static BOOST libraries instead of dynamic" NO)
然后在另一个文件中,我设置了以下逻辑:
if(USE_STATIC_BOOST)
unset(Boost_LIBRARIES)
message(WARNING "Linking against boost static libraries")
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost REQUIRED COMPONENTS thread program_options system)
else(USE_STATIC_BOOST)
unset(Boost_LIBRARIES)
message(WARNING "Linking against boost dynamic libraries")
set(Boost_USE_STATIC_LIBS OFF)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost REQUIRED COMPONENTS thread program_options system)
endif(USE_STATIC_BOOST)
如果我从头开始并使用,这似乎工作正常:
cmake ../.. -DUSE_STATIC_BOOST=YES
但是,当我使用
ccmake ../..
无论我做什么,我都无法让它使用静态库。CMake 似乎在启动时将动态选项加载到缓存中,并且更改 USE_STATIC_BOOST 不会切换它。我什至试图 unset(Boost_LIBRARIES) 明确清除它。有没有办法做我想做的事?
使用 x86_64 Linux 和 g++ 编译。提前致谢!