-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
find folly using its installed cmake config file
Summary: Find folly using its installed CMake configuration file, and delete the custom FindFolly.cmake file that was being used previously. The FindFolly.cmake file did not list all dependent libraries necessary to link statically against folly. Linking against folly as a shared library is not recommended, as folly provides no binary compatibility guarantees between changes. folly's current CMake-based build only builds it as a static library by default. When building with RSOCKET_INSTALL_DEPS enabled, this also changes the code to always build the latest version of folly (instead of pinning to an older release), and to build folly using CMake rather than the older autotools-based folly build which no longer exists in folly. Note that the build now happens as part of the `cmake` step, since folly must be installed before we call `find_package()` to find folly. Test Plan: Tested building rsocket-cpp on an Ubuntu 18.04 host. Confirmed it worked both with an existing folly installation, as well as when using `INSTALL_FOLLY` to have rsocket download and build folly as part of its build steps.
- Loading branch information
Showing
7 changed files
with
53 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,19 @@ | ||
if (NOT FOLLY_INSTALL_DIR) | ||
set(FOLLY_INSTALL_DIR $ENV{HOME}/folly) | ||
set(FOLLY_INSTALL_DIR ${CMAKE_BINARY_DIR}/folly-install) | ||
endif () | ||
|
||
# Check if the correct version of folly is already installed. | ||
set(FOLLY_VERSION v2018.06.25.00) | ||
set(FOLLY_VERSION_FILE ${FOLLY_INSTALL_DIR}/${FOLLY_VERSION}) | ||
if (RSOCKET_INSTALL_DEPS) | ||
if (NOT EXISTS ${FOLLY_VERSION_FILE}) | ||
# Remove the old version of folly. | ||
file(REMOVE_RECURSE ${FOLLY_INSTALL_DIR}) | ||
set(INSTALL_FOLLY True) | ||
endif () | ||
endif () | ||
|
||
if (INSTALL_FOLLY) | ||
# Build and install folly. | ||
ExternalProject_Add( | ||
folly-ext | ||
GIT_REPOSITORY https://github.com/facebook/folly | ||
GIT_TAG ${FOLLY_VERSION} | ||
BINARY_DIR folly-ext-prefix/src/folly-ext/folly | ||
CONFIGURE_COMMAND autoreconf -ivf | ||
COMMAND ./configure CXX=${CMAKE_CXX_COMPILER} | ||
--prefix=${FOLLY_INSTALL_DIR} | ||
BUILD_COMMAND make -j4 | ||
INSTALL_COMMAND make install | ||
COMMAND cmake -E touch ${FOLLY_VERSION_FILE}) | ||
|
||
set(FOLLY_INCLUDE_DIR ${FOLLY_INSTALL_DIR}/include) | ||
set(lib ${CMAKE_SHARED_LIBRARY_PREFIX}folly${CMAKE_SHARED_LIBRARY_SUFFIX}) | ||
set(benchlib ${CMAKE_SHARED_LIBRARY_PREFIX}follybenchmark${CMAKE_SHARED_LIBRARY_SUFFIX}) | ||
set(FOLLY_LIBRARY ${FOLLY_INSTALL_DIR}/lib/${lib}) | ||
set(FOLLY_BENCHMARK_LIBRARY ${FOLLY_INSTALL_DIR}/lib/${benchlib}) | ||
|
||
# CMake requires directories listed in INTERFACE_INCLUDE_DIRECTORIES to exist. | ||
file(MAKE_DIRECTORY ${FOLLY_INCLUDE_DIR}) | ||
else () | ||
# Use installed folly. | ||
find_package(Folly REQUIRED) | ||
execute_process( | ||
COMMAND | ||
${CMAKE_SOURCE_DIR}/scripts/build_folly.sh | ||
${CMAKE_BINARY_DIR}/folly-src | ||
${FOLLY_INSTALL_DIR} | ||
RESULT_VARIABLE folly_result | ||
) | ||
if (NOT "${folly_result}" STREQUAL "0") | ||
message(FATAL_ERROR "failed to build folly") | ||
endif() | ||
endif () | ||
|
||
find_package(Threads) | ||
find_library(EVENT_LIBRARY event) | ||
|
||
add_library(folly SHARED IMPORTED) | ||
set_property(TARGET folly PROPERTY IMPORTED_LOCATION ${FOLLY_LIBRARY}) | ||
set_property(TARGET folly | ||
APPEND PROPERTY INTERFACE_LINK_LIBRARIES | ||
${EXTRA_LINK_FLAGS} ${EVENT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) | ||
if (TARGET folly-ext) | ||
add_dependencies(folly folly-ext) | ||
endif () | ||
|
||
add_library(folly-benchmark SHARED IMPORTED) | ||
set_property(TARGET folly-benchmark PROPERTY IMPORTED_LOCATION ${FOLLY_BENCHMARK_LIBRARY}) | ||
set_property(TARGET folly-benchmark | ||
APPEND PROPERTY INTERFACE_LINK_LIBRARIES | ||
${EXTRA_LINK_FLAGS} ${EVENT_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) | ||
if (TARGET folly-ext) | ||
add_dependencies(folly-benchmark folly-ext) | ||
endif () | ||
|
||
# Folly includes are marked as system to prevent errors on non-standard | ||
# extensions when compiling with -pedantic and -Werror. | ||
set_property(TARGET folly | ||
APPEND PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${FOLLY_INCLUDE_DIR}) | ||
set_property(TARGET folly | ||
APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${FOLLY_INCLUDE_DIR}) | ||
set_property(TARGET folly-benchmark | ||
APPEND PROPERTY INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ${FOLLY_INCLUDE_DIR}) | ||
set_property(TARGET folly-benchmark | ||
APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${FOLLY_INCLUDE_DIR}) | ||
find_package(folly CONFIG REQUIRED PATHS ${FOLLY_INSTALL_DIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright 2004-present Facebook. All Rights Reserved. | ||
# | ||
CHECKOUT_DIR=$1 | ||
INSTALL_DIR=$2 | ||
if [[ -z $INSTALL_DIR ]]; then | ||
echo "usage: $0 CHECKOUT_DIR INSTALL_DIR" >&2 | ||
exit 1 | ||
fi | ||
|
||
# If folly was already installed, just return early | ||
INSTALL_MARKER_FILE="$INSTALL_DIR/folly.installed" | ||
if [[ -f $INSTALL_MARKER_FILE ]]; then | ||
echo "folly was previously built" | ||
exit 0 | ||
fi | ||
|
||
set -e | ||
set -x | ||
|
||
if [[ -d "$CHECKOUT_DIR" ]]; then | ||
git -C "$CHECKOUT_DIR" fetch | ||
git -C "$CHECKOUT_DIR" checkout master | ||
else | ||
git clone https://github.com/facebook/folly "$CHECKOUT_DIR" | ||
fi | ||
|
||
mkdir -p "$CHECKOUT_DIR/_build" | ||
cd "$CHECKOUT_DIR/_build" | ||
cmake "-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}" .. | ||
make -j4 | ||
make install | ||
touch "$INSTALL_MARKER_FILE" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters