Skip to content

Commit

Permalink
[folly] Fix static linking gflags and glog
Browse files Browse the repository at this point in the history
  • Loading branch information
KindDragon committed Oct 17, 2017
1 parent 9153ac7 commit c9d3512
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 4 deletions.
98 changes: 98 additions & 0 deletions ports/folly/fix-static-linking.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
diff --git a/CMake/folly-deps.cmake b/CMake/folly-deps.cmake
index 211c6fbf..fbcbddf0 100755
--- a/CMake/folly-deps.cmake
+++ b/CMake/folly-deps.cmake
@@ -10,9 +10,26 @@ find_package(Boost 1.55.0 MODULE
thread
REQUIRED
)
+
find_package(DoubleConversion MODULE REQUIRED)
-find_package(GFlags MODULE REQUIRED)
-find_package(GLog MODULE REQUIRED)
-find_package(LibEvent MODULE REQUIRED)
+
+find_package(gflags CONFIG)
+if(NOT TARGET gflags)
+ message(STATUS "MODULE: GFlags")
+ find_package(GFlags MODULE REQUIRED)
+endif()
+
+find_package(glog CONFIG)
+if(NOT TARGET glog::glog)
+ message(STATUS "MODULE: GLog")
+ find_package(GLog MODULE REQUIRED)
+endif()
+
+find_package(Libevent CONFIG)
+if(NOT TARGET event)
+ message(STATUS "MODULE: Libevent")
+ find_package(LibEvent MODULE REQUIRED)
+endif()
+
find_package(OpenSSL MODULE REQUIRED)
find_package(PThread MODULE)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cdc992a8..c0231402 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -141,9 +141,38 @@ set(FOLLY_SHINY_DEPENDENCIES

set(FOLLY_LINK_LIBRARIES
${DOUBLE_CONVERSION_LIBRARY}
- ${LIBEVENT_LIB}
- ${LIBGFLAGS_LIBRARY}
- ${LIBGLOG_LIBRARY}
+)
+
+set(FOLLY_INCLUDE_DIRECTORIES
+ ${DOUBLE_CONVERSION_INCLUDE_DIR}
+)
+
+if(TARGET gflags_static)
+ set(FOLLY_SHINY_DEPENDENCIES ${FOLLY_SHINY_DEPENDENCIES} gflags_static)
+elseif(TARGET gflags)
+ set(FOLLY_SHINY_DEPENDENCIES ${FOLLY_SHINY_DEPENDENCIES} gflags)
+else()
+ set(FOLLY_LINK_LIBRARIES ${FOLLY_LINK_LIBRARIES} ${LIBGFLAGS_LIBRARY})
+ set(FOLLY_INCLUDE_DIRECTORIES ${FOLLY_INCLUDE_DIRECTORIES} ${LIBGFLAGS_INCLUDE_DIR})
+endif()
+
+if(TARGET glog::glog)
+ set(FOLLY_SHINY_DEPENDENCIES ${FOLLY_SHINY_DEPENDENCIES} glog::glog)
+else()
+ set(FOLLY_LINK_LIBRARIES ${FOLLY_LINK_LIBRARIES} ${LIBGLOG_LIBRARY})
+ set(FOLLY_INCLUDE_DIRECTORIES ${FOLLY_INCLUDE_DIRECTORIES} ${LIBGLOG_INCLUDE_DIR})
+endif()
+
+if(TARGET event)
+ set(FOLLY_SHINY_DEPENDENCIES ${FOLLY_SHINY_DEPENDENCIES} event)
+else()
+ set(FOLLY_LINK_LIBRARIES ${FOLLY_LINK_LIBRARIES} ${LIBEVENT_LIB})
+ set(FOLLY_INCLUDE_DIRECTORIES ${FOLLY_INCLUDE_DIRECTORIES} ${LIBEVENT_INCLUDE_DIR})
+endif()
+
+
+set(FOLLY_LINK_LIBRARIES
+ ${FOLLY_LINK_LIBRARIES}
Iphlpapi.lib
Ws2_32.lib

@@ -152,15 +181,12 @@ set(FOLLY_LINK_LIBRARIES

target_include_directories(folly_base
PUBLIC
- ${DOUBLE_CONVERSION_INCLUDE_DIR}
- ${LIBGFLAGS_INCLUDE_DIR}
- ${LIBGLOG_INCLUDE_DIR}
- ${LIBEVENT_INCLUDE_DIR}
- $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
+ ${FOLLY_INCLUDE_DIRECTORIES}
)

foreach (LIB ${FOLLY_SHINY_DEPENDENCIES})
target_include_directories(folly_base PUBLIC $<TARGET_PROPERTY:${LIB},INCLUDE_DIRECTORIES>)
+ target_compile_definitions(folly_base PUBLIC $<TARGET_PROPERTY:${LIB},INTERFACE_COMPILE_DEFINITIONS>)
endforeach()

if (FOLLY_HAVE_PTHREAD)
5 changes: 1 addition & 4 deletions ports/folly/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ if(NOT VCPKG_TARGET_ARCHITECTURE STREQUAL x64)
message(FATAL_ERROR "Folly only supports the x64 architecture.")
endif()

if(VCPKG_LIBRARY_LINKAGE STREQUAL static)
message(FATAL_ERROR "Folly can't link with static libraries.")
endif()

if (VCPKG_LIBRARY_LINKAGE STREQUAL dynamic)
message(STATUS "Warning: Dynamic building not supported yet. Building static.")
set(VCPKG_LIBRARY_LINKAGE static)
Expand All @@ -30,6 +26,7 @@ vcpkg_apply_patches(
SOURCE_PATH
${SOURCE_PATH}
PATCHES
${CMAKE_CURRENT_LIST_DIR}/fix-static-linking.diff
${CMAKE_CURRENT_LIST_DIR}/fix-malloc.diff
${CMAKE_CURRENT_LIST_DIR}/fix-MSG_ERRQUEUE.diff
${CMAKE_CURRENT_LIST_DIR}/fix-histogram.diff
Expand Down

0 comments on commit c9d3512

Please sign in to comment.