Fix static linking gflags and glog
authorArkady Shapkin <arkady.shapkin@gmail.com>
Wed, 8 Nov 2017 19:30:38 +0000 (11:30 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 8 Nov 2017 19:39:15 +0000 (11:39 -0800)
Summary:
gflags and glog require some compile definitions when linking statically
/cc Orvid
Closes https://github.com/facebook/folly/pull/693

Reviewed By: yfeldblum

Differential Revision: D6264382

Pulled By: Orvid

fbshipit-source-id: 60c8af429f10e778d9c313f40227892238829f63

CMake/folly-deps.cmake
CMakeLists.txt

index 211c6fb..37cd56f 100755 (executable)
@@ -10,9 +10,23 @@ find_package(Boost 1.55.0 MODULE
     thread\r
   REQUIRED\r
 )\r
+\r
 find_package(DoubleConversion MODULE REQUIRED)\r
-find_package(GFlags MODULE REQUIRED)\r
-find_package(GLog MODULE REQUIRED)\r
-find_package(LibEvent MODULE REQUIRED)\r
+\r
+find_package(gflags CONFIG)\r
+if(NOT TARGET gflags)\r
+  find_package(GFlags MODULE REQUIRED)\r
+endif()\r
+\r
+find_package(glog CONFIG)\r
+if(NOT TARGET glog::glog)\r
+  find_package(GLog MODULE REQUIRED)\r
+endif()\r
+\r
+find_package(Libevent CONFIG)\r
+if(NOT TARGET event)\r
+  find_package(LibEvent MODULE REQUIRED)\r
+endif()\r
+\r
 find_package(OpenSSL MODULE REQUIRED)\r
 find_package(PThread MODULE)\r
index 3715297..d390f06 100755 (executable)
@@ -149,9 +149,36 @@ 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)
+  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
 
@@ -160,15 +187,13 @@ set(FOLLY_LINK_LIBRARIES
 
 target_include_directories(folly_base
   PUBLIC
-    ${DOUBLE_CONVERSION_INCLUDE_DIR}
-    ${LIBGFLAGS_INCLUDE_DIR}
-    ${LIBGLOG_INCLUDE_DIR}
-    ${LIBEVENT_INCLUDE_DIR}
+    ${FOLLY_INCLUDE_DIRECTORIES}
     $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
 )
 
 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)