Commit cdb9225b authored by Adam Simpkins's avatar Adam Simpkins Committed by Facebook Github Bot

cmake: support building with shared libraries enabled

Summary:
In general, building folly as a shared library is not recommended since the
library ABI changes frequently.

Nonetheless, this updates the CMake files to support building with
`BUILD_SHARED_LIBS=ON`.  Previously the build would fail when using this
option.

The main reason to support this for now is because some of the tests can only
be run when compiled with `-fPIC`.  Defining `FOLLY_SHARED_LIBRARY_SUPPORT` in
`folly-config.h` makes it possible to skip these tests when being compiled
without shared library support.

Reviewed By: yfeldblum

Differential Revision: D6805682

fbshipit-source-id: 098290c7405837350577f48ed224947fb62415db
parent 29a859ad
......@@ -81,3 +81,5 @@
#cmakedefine FOLLY_HAVE_LIBZ 1
#cmakedefine FOLLY_HAVE_LIBZSTD 1
#cmakedefine FOLLY_HAVE_LIBBZ2 1
#cmakedefine FOLLY_SUPPORT_SHARED_LIBRARY 1
......@@ -16,6 +16,17 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
project(${PACKAGE_NAME} CXX C)
option(BUILD_SHARED_LIBS
"If enabled, build folly as a shared library. \
This is generally discouraged, since folly does not commit to having \
a stable ABI."
OFF
)
# Mark BUILD_SHARED_LIBS as an "advanced" option, since enabling it
# is generally discouraged.
mark_as_advanced(BUILD_SHARED_LIBS)
set(FOLLY_SUPPORT_SHARED_LIBRARY "${BUILD_SHARED_LIBS}")
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
# Check target architecture
if (NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
......@@ -196,6 +207,9 @@ add_library(folly_base OBJECT
${CMAKE_CURRENT_BINARY_DIR}/folly/build/FormatTables.cpp
${CMAKE_CURRENT_BINARY_DIR}/folly/build/GroupVarintTables.cpp
)
if (BUILD_SHARED_LIBS)
set_property(TARGET folly_base PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()
auto_source_group(folly ${FOLLY_DIR} ${files} ${hfiles})
apply_folly_compile_options_to_target(folly_base)
target_include_directories(folly_base PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment