Skip to content

Commit 90a1212

Browse files
hjmallonfacebook-github-bot
authored andcommitted
Add CMake option WDT_USE_SYSTEM_FOLLY to disable folly4wdt (facebook#197)
Summary: This is a proposed fix for facebook#194 Pull Request resolved: facebook#197 Reviewed By: filbranden Differential Revision: D24929345 Pulled By: davide125 fbshipit-source-id: 280fa841cbfff1ddde846b3116adbeb08d3bcd40
1 parent b4a1541 commit 90a1212

File tree

1 file changed

+56
-34
lines changed

1 file changed

+56
-34
lines changed

CMakeLists.txt

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ set(BUILD_SHARED_LIBS on CACHE BOOL "build shared libs")
3939
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
4040
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
4141

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

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

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

6871

69-
# The part of folly that isn't pure .h and we use:
70-
set (FOLLY_CPP_SRC
71-
"${FOLLY_SOURCE_DIR}/folly/Conv.cpp"
72-
"${FOLLY_SOURCE_DIR}/folly/Demangle.cpp"
73-
"${FOLLY_SOURCE_DIR}/folly/lang/CString.cpp"
74-
"${FOLLY_SOURCE_DIR}/folly/hash/Checksum.cpp"
75-
"${FOLLY_SOURCE_DIR}/folly/hash/detail/ChecksumDetail.cpp"
76-
"${FOLLY_SOURCE_DIR}/folly/hash/detail/Crc32cDetail.cpp"
77-
"${FOLLY_SOURCE_DIR}/folly/hash/detail/Crc32CombineDetail.cpp"
78-
"${FOLLY_SOURCE_DIR}/folly/ScopeGuard.cpp"
79-
)
72+
# The part of folly that isn't pure .h and we use:
73+
set (FOLLY_CPP_SRC
74+
"${FOLLY_SOURCE_DIR}/folly/Conv.cpp"
75+
"${FOLLY_SOURCE_DIR}/folly/Demangle.cpp"
76+
"${FOLLY_SOURCE_DIR}/folly/lang/CString.cpp"
77+
"${FOLLY_SOURCE_DIR}/folly/hash/Checksum.cpp"
78+
"${FOLLY_SOURCE_DIR}/folly/hash/detail/ChecksumDetail.cpp"
79+
"${FOLLY_SOURCE_DIR}/folly/hash/detail/Crc32cDetail.cpp"
80+
"${FOLLY_SOURCE_DIR}/folly/hash/detail/Crc32CombineDetail.cpp"
81+
"${FOLLY_SOURCE_DIR}/folly/ScopeGuard.cpp"
82+
)
83+
endif()
8084

8185
# WDT's library proper - comes from: ls -1 *.cpp | grep -iv test
8286
add_library(wdt_min
@@ -158,10 +162,18 @@ list(REMOVE_ITEM CMAKE_REQUIRED_LIBRARIES "${GFLAGS_LIBRARY}")
158162
# OpenSSL's crypto lib
159163
find_package(OpenSSL REQUIRED)
160164
include_directories(${OPENSSL_INCLUDE_DIR})
165+
# System Folly
166+
if (WDT_USE_SYSTEM_FOLLY)
167+
find_path(FOLLY_INCLUDE_DIR folly/Conv.h)
168+
find_library(FOLLY_LIBRARY folly)
169+
else()
170+
set(FOLLY_LIBRARY folly4wdt)
171+
set(FOLLY_INCLUDE_DIR "${FOLLY_SOURCE_DIR}")
172+
endif()
161173

162174
# You can also add jemalloc to the list if you have it/want it
163175
target_link_libraries(wdt_min
164-
folly4wdt
176+
${FOLLY_LIBRARY}
165177
${GLOG_LIBRARY}
166178
${GFLAGS_LIBRARY}
167179
${Boost_LIBRARIES}
@@ -212,19 +224,21 @@ configure_file(build/folly-config.h.in folly/folly-config.h)
212224
# Wdt's config/version
213225
configure_file(WdtConfig.h.in wdt/WdtConfig.h)
214226

215-
# Malloc stuff tied to not supporting weaksympbols
216-
if (NOT FOLLY_HAVE_WEAK_SYMBOLS)
217-
list(APPEND FOLLY_CPP_SRC "${FOLLY_SOURCE_DIR}/folly/memory/detail/MallocImpl.cpp")
218-
message(STATUS "no weak symbols, adding MallocImpl to folly src")
219-
endif()
227+
if (NOT WDT_USE_SYSTEM_FOLLY)
228+
# Malloc stuff tied to not supporting weaksympbols
229+
if (NOT FOLLY_HAVE_WEAK_SYMBOLS)
230+
list(APPEND FOLLY_CPP_SRC "${FOLLY_SOURCE_DIR}/folly/memory/detail/MallocImpl.cpp")
231+
message(STATUS "no weak symbols, adding MallocImpl to folly src")
232+
endif()
220233

221-
add_library(folly4wdt ${FOLLY_CPP_SRC})
222-
target_link_libraries(folly4wdt ${GLOG_LIBRARY} ${DOUBLECONV_LIBRARY})
234+
add_library(folly4wdt ${FOLLY_CPP_SRC})
235+
target_link_libraries(folly4wdt ${GLOG_LIBRARY} ${DOUBLECONV_LIBRARY})
236+
endif()
223237

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

238252
### Install rules
239253
set_target_properties(wdtbin PROPERTIES RUNTIME_OUTPUT_NAME "wdt")
240-
install(TARGETS wdtbin wdt wdt_min folly4wdt
254+
install(TARGETS wdtbin wdt wdt_min
241255
RUNTIME DESTINATION bin
242256
LIBRARY DESTINATION lib
243257
ARCHIVE DESTINATION lib
244258
)
245259

260+
if (NOT WDT_USE_SYSTEM_FOLLY)
261+
install(TARGETS folly4wdt
262+
RUNTIME DESTINATION bin
263+
LIBRARY DESTINATION lib
264+
ARCHIVE DESTINATION lib
265+
)
266+
endif()
267+
246268
### Install header files
247269

248270
# Find the . files in the root directory

0 commit comments

Comments
 (0)