Skip to content

Commit

Permalink
fix how folly and its downstream projects find boost
Browse files Browse the repository at this point in the history
Summary:
Folly links explicitly links against boost statically on Windows.  However,
many downstream projects that use folly independently performed their own
discovery of boost and normally used the default option of linking against it
dynamically.  This resulted in boost being listed twice on the link line on
Windows for some downstream projects: both its static libraries and dynamic
libraries would be present.  This ends up causing linking failures due to
duplicate definitions.

This updates folly's installed CMake file to correctly call
`find_dependency(Boost)` so that downstream projects don't need to perform
their own independent discovery.  This ensures that all downstream projects
use a consistent method of linking against Boost.  I updated many downstream
projects to remove their explicit separate discovery, and rely only on this
behavior from folly.

I also added a configuration setting to allow explicitly selecting whether to
link against boost statically at folly configure time.

Reviewed By: wez

Differential Revision: D21232164

fbshipit-source-id: 9ecc3ce988add48905252297e979403c42e7e148
  • Loading branch information
simpkins authored and facebook-github-bot committed Apr 27, 2020
1 parent 4162d2f commit 6e85117
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
12 changes: 12 additions & 0 deletions CMake/folly-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ set(FOLLY_LIBRARIES Folly::folly)
# Find folly's dependencies
find_dependency(fmt)

set(Boost_USE_STATIC_LIBS "@FOLLY_BOOST_LINK_STATIC@")
find_dependency(Boost 1.51.0 MODULE
COMPONENTS
context
filesystem
program_options
regex
system
thread
REQUIRED
)

if (NOT folly_FIND_QUIETLY)
message(STATUS "Found folly: ${FOLLY_PREFIX_DIR}")
endif()
20 changes: 17 additions & 3 deletions CMake/folly-deps.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,23 @@ include(CheckCXXSourceCompiles)
include(CheckIncludeFileCXX)
include(CheckFunctionExists)

if(MSVC)
set(Boost_USE_STATIC_LIBS ON) #Force static lib in msvc
endif(MSVC)
set(
BOOST_LINK_STATIC "auto"
CACHE STRING
"Whether to link against boost statically or dynamically."
)
if("${BOOST_LINK_STATIC}" STREQUAL "auto")
# Default to linking boost statically on Windows with MSVC
if(MSVC)
set(FOLLY_BOOST_LINK_STATIC ON)
else()
set(FOLLY_BOOST_LINK_STATIC OFF)
endif()
else()
set(FOLLY_BOOST_LINK_STATIC "${BOOST_LINK_STATIC}")
endif()
set(Boost_USE_STATIC_LIBS "${FOLLY_BOOST_LINK_STATIC}")

find_package(Boost 1.51.0 MODULE
COMPONENTS
context
Expand Down

0 comments on commit 6e85117

Please sign in to comment.