Skip to content

Commit

Permalink
Add CMake option WDT_USE_SYSTEM_FOLLY to disable folly4wdt (#197)
Browse files Browse the repository at this point in the history
Summary:
This is a proposed fix for #194

Pull Request resolved: #197

Reviewed By: filbranden

Differential Revision: D24929345

Pulled By: davide125

fbshipit-source-id: 280fa841cbfff1ddde846b3116adbeb08d3bcd40
  • Loading branch information
hjmallon authored and facebook-github-bot committed Nov 12, 2020
1 parent b4a1541 commit 90a1212
Showing 1 changed file with 56 additions and 34 deletions.
90 changes: 56 additions & 34 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ set(BUILD_SHARED_LIBS on CACHE BOOL "build shared libs")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")

set(WDT_USE_SYSTEM_FOLLY Off CACHE BOOL "Use folly library from system (default off)")

# Optimized by default
# TODO: This doesn't seem to work / sets default to "" instead of Release...
Expand All @@ -51,32 +52,35 @@ set(CMAKE_CXX_FLAGS "-msse4.2 -mpclmul")
#set(CMAKE_CXX_FLAGS "-msse4.2 -mpclmul -Wextra -Wsign-compare -Wunused-variable -Wconversion -Wsign-conversion")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "_bin/wdt")

# Check that we have the Folly source tree
set(FOLLY_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../folly" CACHE PATH
"Folly source tree (folly/Conv.h should be reachable from there")
# Check for folly - TODO: this doesn't work well for relative paths
# (because of relative to build dir vs relative to source tree for -I)
if(NOT EXISTS "${FOLLY_SOURCE_DIR}/folly/Conv.h")
MESSAGE(FATAL_ERROR "${FOLLY_SOURCE_DIR}/folly/Conv.h not found
Fix using:
(in a sister directory of the wdt source tree - same level:)
git clone https://github.com/facebook/folly.git
or change FOLLY_SOURCE_DIR (use ccmake or -DFOLLY_SOURCE_DIR=...)
")
endif()
if (NOT WDT_USE_SYSTEM_FOLLY)
# Check that we have the Folly source tree
set(FOLLY_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../folly" CACHE PATH
"Folly source tree (folly/Conv.h should be reachable from there")
# Check for folly - TODO: this doesn't work well for relative paths
# (because of relative to build dir vs relative to source tree for -I)
if(NOT EXISTS "${FOLLY_SOURCE_DIR}/folly/Conv.h")
MESSAGE(FATAL_ERROR "${FOLLY_SOURCE_DIR}/folly/Conv.h not found
Fix using:
(in a sister directory of the wdt source tree - same level:)
git clone https://github.com/facebook/folly.git
or change FOLLY_SOURCE_DIR (use ccmake or -DFOLLY_SOURCE_DIR=...)
or change WDT_USE_SYSTEM_FOLLY (use ccmake or -DWDT_USE_SYSTEM_FOLLY=...)
")
endif()


# The part of folly that isn't pure .h and we use:
set (FOLLY_CPP_SRC
"${FOLLY_SOURCE_DIR}/folly/Conv.cpp"
"${FOLLY_SOURCE_DIR}/folly/Demangle.cpp"
"${FOLLY_SOURCE_DIR}/folly/lang/CString.cpp"
"${FOLLY_SOURCE_DIR}/folly/hash/Checksum.cpp"
"${FOLLY_SOURCE_DIR}/folly/hash/detail/ChecksumDetail.cpp"
"${FOLLY_SOURCE_DIR}/folly/hash/detail/Crc32cDetail.cpp"
"${FOLLY_SOURCE_DIR}/folly/hash/detail/Crc32CombineDetail.cpp"
"${FOLLY_SOURCE_DIR}/folly/ScopeGuard.cpp"
)
# The part of folly that isn't pure .h and we use:
set (FOLLY_CPP_SRC
"${FOLLY_SOURCE_DIR}/folly/Conv.cpp"
"${FOLLY_SOURCE_DIR}/folly/Demangle.cpp"
"${FOLLY_SOURCE_DIR}/folly/lang/CString.cpp"
"${FOLLY_SOURCE_DIR}/folly/hash/Checksum.cpp"
"${FOLLY_SOURCE_DIR}/folly/hash/detail/ChecksumDetail.cpp"
"${FOLLY_SOURCE_DIR}/folly/hash/detail/Crc32cDetail.cpp"
"${FOLLY_SOURCE_DIR}/folly/hash/detail/Crc32CombineDetail.cpp"
"${FOLLY_SOURCE_DIR}/folly/ScopeGuard.cpp"
)
endif()

# WDT's library proper - comes from: ls -1 *.cpp | grep -iv test
add_library(wdt_min
Expand Down Expand Up @@ -158,10 +162,18 @@ list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "${GFLAGS_LIBRARY}")
# OpenSSL's crypto lib
find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
# System Folly
if (WDT_USE_SYSTEM_FOLLY)
find_path(FOLLY_INCLUDE_DIR folly/Conv.h)
find_library(FOLLY_LIBRARY folly)
else()
set(FOLLY_LIBRARY folly4wdt)
set(FOLLY_INCLUDE_DIR "${FOLLY_SOURCE_DIR}")
endif()

# You can also add jemalloc to the list if you have it/want it
target_link_libraries(wdt_min
folly4wdt
${FOLLY_LIBRARY}
${GLOG_LIBRARY}
${GFLAGS_LIBRARY}
${Boost_LIBRARIES}
Expand Down Expand Up @@ -212,19 +224,21 @@ configure_file(build/folly-config.h.in folly/folly-config.h)
# Wdt's config/version
configure_file(WdtConfig.h.in wdt/WdtConfig.h)

# Malloc stuff tied to not supporting weaksympbols
if (NOT FOLLY_HAVE_WEAK_SYMBOLS)
list(APPEND FOLLY_CPP_SRC "${FOLLY_SOURCE_DIR}/folly/memory/detail/MallocImpl.cpp")
message(STATUS "no weak symbols, adding MallocImpl to folly src")
endif()
if (NOT WDT_USE_SYSTEM_FOLLY)
# Malloc stuff tied to not supporting weaksympbols
if (NOT FOLLY_HAVE_WEAK_SYMBOLS)
list(APPEND FOLLY_CPP_SRC "${FOLLY_SOURCE_DIR}/folly/memory/detail/MallocImpl.cpp")
message(STATUS "no weak symbols, adding MallocImpl to folly src")
endif()

add_library(folly4wdt ${FOLLY_CPP_SRC})
target_link_libraries(folly4wdt ${GLOG_LIBRARY} ${DOUBLECONV_LIBRARY})
add_library(folly4wdt ${FOLLY_CPP_SRC})
target_link_libraries(folly4wdt ${GLOG_LIBRARY} ${DOUBLECONV_LIBRARY})
endif()

# Order is important - inside fb we want the above
# folly-config.h to be picked up instead of the fbcode one
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${FOLLY_SOURCE_DIR})
include_directories(${FOLLY_INCLUDE_DIR})
include_directories(${DOUBLECONV_INCLUDE_DIR})
include_directories(${GLOG_INCLUDE_DIR})
include_directories(${GFLAGS_INCLUDE_DIR})
Expand All @@ -237,12 +251,20 @@ target_link_libraries(wdtbin wdt_min)

### Install rules
set_target_properties(wdtbin PROPERTIES RUNTIME_OUTPUT_NAME "wdt")
install(TARGETS wdtbin wdt wdt_min folly4wdt
install(TARGETS wdtbin wdt wdt_min
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)

if (NOT WDT_USE_SYSTEM_FOLLY)
install(TARGETS folly4wdt
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
endif()

### Install header files

# Find the . files in the root directory
Expand Down

0 comments on commit 90a1212

Please sign in to comment.