Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find folly using its installed cmake config file #875

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 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,21 +77,28 @@ env:
eHz/lHAoLXWg/BhtgQbPmMYYKRrQaH7EKzBbqEHv6PhOk7vLMtdx5X7KmhVuFjpAMbaYoj
zwxxH0u+VAnVB5iazzyjhySjvzkvx6pGzZtTnjLJHxKcp9633z4OU=

cache:
directories:
- $HOME/folly

before_script:
- eval "$COMPILER_EVAL"
- export DEP_INSTALL_DIR=$PWD/build/dep-install
# Ubuntu trusty only comes with OpenSSL 1.0.1f, but we require
# at least OpenSSL 1.0.2 for ALPN support.
- curl -L https://github.com/openssl/openssl/archive/OpenSSL_1_1_1.tar.gz -o OpenSSL_1_1_1.tar.gz
- tar -xzf OpenSSL_1_1_1.tar.gz
- cd openssl-OpenSSL_1_1_1
- ./config --prefix=$DEP_INSTALL_DIR no-shared
- make -j4
- make install_sw install_ssldirs
- cd ..
# Install lcov to coveralls conversion + upload tool.
- gem install coveralls-lcov
- lcov --version
- eval "$COMPILER_EVAL"
# Build folly
- ./scripts/build_folly.sh build/folly-src $DEP_INSTALL_DIR

script:
- mkdir build
- cd build
- cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE
-DRSOCKET_ASAN=$ASAN -DRSOCKET_INSTALL_DEPS=True
- cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DRSOCKET_ASAN=$ASAN
-DCMAKE_PREFIX_PATH=$DEP_INSTALL_DIR
-DRSOCKET_BUILD_WITH_COVERAGE=ON ..
- make -j4
- lcov --directory . --zerocounters
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
6 changes: 6 additions & 0 deletions rsocket/transports/tcp/TcpConnectionFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,14 @@ class ConnectCallback : public folly::AsyncSocket::ConnectCallback {
DCHECK(evb);

if (sslContext) {
#if !FOLLY_OPENSSL_HAS_ALPN
// setAdvertisedNextProtocols() is unavailable
#error ALPN is required for rsockets. \
Your version of OpenSSL is likely too old.
#else
VLOG(3) << "Starting SSL socket";
sslContext->setAdvertisedNextProtocols({"rs"});
#endif
socket_.reset(new folly::AsyncSSLSocket(sslContext, evb));
} else {
VLOG(3) << "Starting socket";
Expand Down
48 changes: 48 additions & 0 deletions scripts/build_folly.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/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

# Convert INSTALL_DIR to an absolute path so it still refers to the same
# location after we cd into the build directory.
case "$INSTALL_DIR" in
/*) ;;
*) INSTALL_DIR="$PWD/$INSTALL_DIR"
esac

# 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"
if ! cmake \
"-DCMAKE_PREFIX_PATH=${INSTALL_DIR}" \
"-DCMAKE_INSTALL_PREFIX=${INSTALL_DIR}" \
..; then
echo "error configuring folly" >&2
tail -n 100 CMakeFiles/CMakeError.log >&2
exit 1
fi
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