Skip to content

Commit

Permalink
find folly using its installed cmake config file
Browse files Browse the repository at this point in the history
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
simpkins committed Oct 17, 2018
1 parent e9094fa commit 31ff2a2
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 95 deletions.
9 changes: 0 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ addons:
packages: &common_deps
- lcov
# Folly dependencies
- autoconf
- autoconf-archive
- automake
- binutils-dev
- g++
- libboost-all-dev
Expand All @@ -29,9 +26,7 @@ addons:
- liblzma-dev
- libsnappy-dev
- libssl-dev
- libtool
- make
- pkg-config
- zlib1g-dev

matrix:
Expand Down Expand Up @@ -82,10 +77,6 @@ env:
eHz/lHAoLXWg/BhtgQbPmMYYKRrQaH7EKzBbqEHv6PhOk7vLMtdx5X7KmhVuFjpAMbaYoj
zwxxH0u+VAnVB5iazzyjhySjvzkvx6pGzZtTnjLJHxKcp9633z4OU=
cache:
directories:
- $HOME/folly

before_script:
# Install lcov to coveralls conversion + upload tool.
- gem install coveralls-lcov
Expand Down
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ add_library(
rsocket/transports/tcp/TcpDuplexConnection.cpp
rsocket/transports/tcp/TcpDuplexConnection.h)

target_link_libraries(ReactiveSocket yarpl ${GFLAGS_LIBRARY} ${GLOG_LIBRARY})
target_link_libraries(ReactiveSocket
PUBLIC yarpl ${GFLAGS_LIBRARY} ${GLOG_LIBRARY}
INTERFACE ${EXTRA_LINK_FLAGS})

target_compile_options(
ReactiveSocket
Expand Down
15 changes: 0 additions & 15 deletions cmake/FindFolly.cmake

This file was deleted.

78 changes: 12 additions & 66 deletions cmake/InstallFolly.cmake
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})
4 changes: 2 additions & 2 deletions rsocket/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
add_library(fixture Fixture.cpp Fixture.h)
target_link_libraries(fixture ReactiveSocket folly)
target_link_libraries(fixture ReactiveSocket Folly::folly)

function(benchmark NAME FILE)
add_executable(${NAME} ${FILE} Benchmarks.cpp)
target_link_libraries(
${NAME}
fixture
ReactiveSocket
folly-benchmark
Folly::follybenchmark
${GFLAGS_LIBRARY}
${GLOG_LIBRARY})
endfunction()
Expand Down
34 changes: 34 additions & 0 deletions scripts/build_folly.sh
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"
4 changes: 2 additions & 2 deletions yarpl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ message("yarpl source dir: ${CMAKE_CURRENT_SOURCE_DIR}")

target_link_libraries(
yarpl
folly
${GLOG_LIBRARY})
PUBLIC Folly::folly ${GLOG_LIBRARY}
INTERFACE ${EXTRA_LINK_FLAGS})

install(TARGETS yarpl DESTINATION lib)
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION include FILES_MATCHING PATTERN "*.h")
Expand Down

0 comments on commit 31ff2a2

Please sign in to comment.