FindBoost.cmake needs Boost::atomic for Boost::thread even if my Boost was configured without --with-atomic
I have a Boost library that was configured as following:
./b2\
-d+2\
cflags="-mcpu=cortex-a9 -mfloat-abi=softfp -mfpu=neon -mno-unaligned-access -fno-aggressive-loop-optimizations"\
target-os=linux\
toolset=gcc-arm\
variant=release\
include="${PREFIX}/../openssl/include"\
linkflags="-L${PREFIX}/../openssl/lib -lssl -lcrypto"\
link=shared\
runtime-link=shared\
optimization=speed\
--prefix=${PREFIX}\
--disable-long-double\
--ignore-site-config\
--with-date_time\
--with-exception\
--with-filesystem\
--with-regex\
--with-system\
--with-thread\
--with-chrono\
--with-iostreams\
install
As a result, I have libboost_thread.so
but no libboost_atomic.so
.
My application uses threads and atomics presented in headers and works just fine. However when FindBoost.cmake
finds this installation of Boost, it doesn't create / cannot find Boost::atomic
IMPORTED
target, but makes Boost::thread
dependant on it anyway. As a result target_link_libraries(app Boost::thread)
causes error:
Target "netmgr" links to target "Boost::atomic" but the target was not found.
If I explicitly specify atomic
in find_package(Boost COMPONENTS regex thread atomic)
, I get
Could not find the following Boost libraries: boost_atomic
A silly but seemingly working workaround I came up with:
add_library(dummy dummy.cpp)
add_library(Boost::atomic UNKNOWN IMPORTED)
add_dependencies(Boost::atomic dummy)
set_target_properties(Boost::atomic PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_BINARY_DIR}/libdummy.a)
endif()```