cmake: build as many source files as possible
authorAdam Simpkins <simpkins@fb.com>
Fri, 19 Jan 2018 04:43:18 +0000 (20:43 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 19 Jan 2018 05:04:33 +0000 (21:04 -0800)
Summary:
The CMakeLists.txt file finds the sources and headers for the main folly
library by finding all *.cpp and *.h files, and then excluding specific ones.

The CMakeLists.txt file was originally written for Windows builds, and it was
hard-coded to exclude a number of files that do not build on Windows.   This
updates the file to properly check for the dependencies, and build these files
if their required third-party dependencies are available.

Reviewed By: meyering

Differential Revision: D6745368

fbshipit-source-id: 3ee04d54147a68c482aab50d30bc9fe2a4134eef

CMake/FindLibAIO.cmake [new file with mode: 0644]
CMake/FindLibDwarf.cmake [new file with mode: 0644]
CMake/FindLibURCU.cmake [new file with mode: 0644]
CMake/FindLibiberty.cmake [new file with mode: 0644]
CMake/folly-deps.cmake
CMakeLists.txt

diff --git a/CMake/FindLibAIO.cmake b/CMake/FindLibAIO.cmake
new file mode 100644 (file)
index 0000000..cd62156
--- /dev/null
@@ -0,0 +1,15 @@
+find_path(LIBAIO_INCLUDE_DIR NAMES libaio.h)
+mark_as_advanced(LIBAIO_INCLUDE_DIR)
+
+find_library(LIBAIO_LIBRARY NAMES aio)
+mark_as_advanced(LIBAIO_LIBRARY)
+
+include(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(
+  LIBAIO
+  REQUIRED_VARS LIBAIO_LIBRARY LIBAIO_INCLUDE_DIR)
+
+if(LIBAIO_FOUND)
+  set(LIBAIO_LIBRARIES ${LIBAIO_LIBRARY})
+  set(LIBAIO_INCLUDE_DIRS ${LIBAIO_INCLUDE_DIR})
+endif()
diff --git a/CMake/FindLibDwarf.cmake b/CMake/FindLibDwarf.cmake
new file mode 100644 (file)
index 0000000..2b1fc8d
--- /dev/null
@@ -0,0 +1,15 @@
+find_path(LIBDWARF_INCLUDE_DIR NAMES libdwarf/dwarf.h)
+mark_as_advanced(LIBDWARF_INCLUDE_DIR)
+
+find_library(LIBDWARF_LIBRARY NAMES dwarf)
+mark_as_advanced(LIBDWARF_LIBRARY)
+
+include(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(
+  LIBDWARF
+  REQUIRED_VARS LIBDWARF_LIBRARY LIBDWARF_INCLUDE_DIR)
+
+if(LIBDWARF_FOUND)
+  set(LIBDWARF_LIBRARIES ${LIBDWARF_LIBRARY})
+  set(LIBDWARF_INCLUDE_DIRS ${LIBDWARF_INCLUDE_DIR})
+endif()
diff --git a/CMake/FindLibURCU.cmake b/CMake/FindLibURCU.cmake
new file mode 100644 (file)
index 0000000..50a2b00
--- /dev/null
@@ -0,0 +1,15 @@
+find_path(LIBURCU_INCLUDE_DIR NAMES urcu.h)
+mark_as_advanced(LIBURCU_INCLUDE_DIR)
+
+find_library(LIBURCU_LIBRARY NAMES urcu)
+mark_as_advanced(LIBURCU_LIBRARY)
+
+include(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(
+  LIBURCU
+  REQUIRED_VARS LIBURCU_LIBRARY LIBURCU_INCLUDE_DIR)
+
+if(LIBURCU_FOUND)
+  set(LIBURCU_LIBRARIES ${LIBURCU_LIBRARY})
+  set(LIBURCU_INCLUDE_DIRS ${LIBURCU_INCLUDE_DIR})
+endif()
diff --git a/CMake/FindLibiberty.cmake b/CMake/FindLibiberty.cmake
new file mode 100644 (file)
index 0000000..880d391
--- /dev/null
@@ -0,0 +1,15 @@
+find_path(LIBIBERTY_INCLUDE_DIR NAMES libiberty/libiberty.h)
+mark_as_advanced(LIBIBERTY_INCLUDE_DIR)
+
+find_library(LIBIBERTY_LIBRARY NAMES iberty)
+mark_as_advanced(LIBIBERTY_LIBRARY)
+
+include(FindPackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(
+  LIBIBERTY
+  REQUIRED_VARS LIBIBERTY_LIBRARY LIBIBERTY_INCLUDE_DIR)
+
+if(LIBIBERTY_FOUND)
+  set(LIBIBERTY_LIBRARIES ${LIBIBERTY_LIBRARY})
+  set(LIBIBERTY_INCLUDE_DIRS ${LIBIBERTY_INCLUDE_DIR})
+endif()
index 409fa55..2d0a8be 100755 (executable)
@@ -115,28 +115,22 @@ if (FOLLY_HAVE_LIBLZ4)
   list(APPEND FOLLY_LINK_LIBRARIES lz4)
 endif()
 
-message(STATUS "Looking for libdwarf")
-find_library(LIBDWARF_LIBRARIES NAMES dwarf)
-if (LIBDWARF_LIBRARIES)
-  message(STATUS "Looking for libdwarf - found: ${LIBDWARF_LIBRARIES}")
-  set(LIBDWARF_FOUND ON)
-  CHECK_INCLUDE_FILE_CXX(libdwarf/dwarf.h FOLLY_HAVE_LIBDWARF_DWARF_H)
-  list(APPEND FOLLY_LINK_LIBRARIES ${LIBDWARF_LIBRARIES})
-else()
-  message(STATUS "Looking for libdwarf - not found")
-endif()
+find_package(LibDwarf)
+list(APPEND FOLLY_LINK_LIBRARIES ${LIBDWARF_LIBRARIES})
+list(APPEND FOLLY_INCLUDE_DIRECTORIES ${LIBDWARF_INCLUDE_DIRS})
+CHECK_INCLUDE_FILE_CXX(libdwarf/dwarf.h FOLLY_HAVE_LIBDWARF_DWARF_H)
 
-message(STATUS "Looking for libiberty")
-find_library(LIBIBERTY_LIBRARIES NAMES iberty_pic iberty)
-if (LIBIBERTY_LIBRARIES)
-  message(STATUS "Looking for libiberty - found: ${LIBIBERTY_LIBRARIES}")
-  set(LIBIBERTY_FOUND ON)
-  list(APPEND FOLLY_LINK_LIBRARIES ${LIBIBERTY_LIBRARIES})
-  list(APPEND CMAKE_REQUIRED_LIBRARIES ${LIBIBERTY_LIBRARIES})
-else()
-  message(STATUS "Looking for libiberty - not found")
-  set(LIBIBERTY_FOUND OFF)
-endif()
+find_package(Libiberty)
+list(APPEND FOLLY_LINK_LIBRARIES ${LIBIBERTY_LIBRARIES})
+list(APPEND FOLLY_INCLUDE_DIRECTORIES ${LIBIBERTY_INCLUDE_DIRS})
+
+find_package(LibAIO)
+list(APPEND FOLLY_LINK_LIBRARIES ${LIBAIO_LIBRARIES})
+list(APPEND FOLLY_INCLUDE_DIRECTORIES ${LIBAIO_INCLUDE_DIRS})
+
+find_package(LibURCU)
+list(APPEND FOLLY_LINK_LIBRARIES ${LIBURCU_LIBRARIES})
+list(APPEND FOLLY_INCLUDE_DIRECTORIES ${LIBURCU_INCLUDE_DIRS})
 
 list(APPEND FOLLY_LINK_LIBRARIES ${CMAKE_DL_LIBS})
 list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_DL_LIBS})
index e8d1b41..b0982f9 100755 (executable)
@@ -96,11 +96,11 @@ configure_file(
 auto_sources(files "*.cpp" "RECURSE" "${FOLLY_DIR}")
 auto_sources(hfiles "*.h" "RECURSE" "${FOLLY_DIR}")
 
-# No need for tests or benchmarks, and we can't build most experimental stuff.
+# Exclude tests, benchmarks, and other standalone utility executables from the
+# library sources.  Test sources are listed separately below.
 REMOVE_MATCHES_FROM_LISTS(files hfiles
   MATCHES
     "/build/"
-    "/experimental/exception_tracer/"
     "/experimental/hazptr/bench/"
     "/experimental/hazptr/example/"
     "/experimental/logging/example/"
@@ -113,39 +113,58 @@ REMOVE_MATCHES_FROM_LISTS(files hfiles
     "/Benchmark.cpp$"
 )
 list(REMOVE_ITEM files
-  ${FOLLY_DIR}/Poly.cpp
-  ${FOLLY_DIR}/SingletonStackTrace.cpp
   ${FOLLY_DIR}/experimental/JSONSchemaTester.cpp
-  ${FOLLY_DIR}/experimental/RCUUtils.cpp
-  ${FOLLY_DIR}/experimental/io/AsyncIO.cpp
   ${FOLLY_DIR}/experimental/io/HugePageUtil.cpp
   ${FOLLY_DIR}/experimental/symbolizer/ElfUtil.cpp
   ${FOLLY_DIR}/futures/test/Benchmark.cpp
 )
 list(REMOVE_ITEM hfiles
-  ${FOLLY_DIR}/Fingerprint.h
-  ${FOLLY_DIR}/Poly.h
-  ${FOLLY_DIR}/Poly-inl.h
-  ${FOLLY_DIR}/detail/PolyDetail.h
-  ${FOLLY_DIR}/detail/TypeList.h
   ${FOLLY_DIR}/detail/SlowFingerprint.h
   ${FOLLY_DIR}/detail/FingerprintPolynomial.h
-  ${FOLLY_DIR}/experimental/RCURefCount.h
-  ${FOLLY_DIR}/experimental/RCUUtils.h
-  ${FOLLY_DIR}/experimental/io/AsyncIO.h
-  ${FOLLY_DIR}/poly/Nullable.h
-  ${FOLLY_DIR}/poly/Regular.h
 )
+
+# Exclude specific sources if we do not have third-party libraries
+# required to build them.
 if (NOT FOLLY_USE_SYMBOLIZER)
   REMOVE_MATCHES_FROM_LISTS(files hfiles
     MATCHES
+      "/experimental/exception_tracer/"
       "/experimental/symbolizer/"
   )
+  list(REMOVE_ITEM files
+    ${FOLLY_DIR}/SingletonStackTrace.cpp
+  )
+endif()
+if (NOT ${LIBURCU_FOUND})
+  list(REMOVE_ITEM files
+    ${FOLLY_DIR}/experimental/RCUUtils.cpp
+  )
+  list(REMOVE_ITEM hfiles
+    ${FOLLY_DIR}/experimental/RCURefCount.h
+    ${FOLLY_DIR}/experimental/RCUUtils.h
+  )
+endif()
+if (NOT ${LIBAIO_FOUND})
+  list(REMOVE_ITEM files
+    ${FOLLY_DIR}/experimental/io/AsyncIO.cpp
+  )
+  list(REMOVE_ITEM hfiles
+    ${FOLLY_DIR}/experimental/io/AsyncIO.h
+  )
 endif()
 if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
-list(REMOVE_ITEM files
-  ${FOLLY_DIR}/Subprocess.cpp
-)
+  list(REMOVE_ITEM files
+    ${FOLLY_DIR}/Poly.cpp
+    ${FOLLY_DIR}/Subprocess.cpp
+  )
+  list(REMOVE_ITEM hfiles
+    ${FOLLY_DIR}/Poly.h
+    ${FOLLY_DIR}/Poly-inl.h
+    ${FOLLY_DIR}/detail/PolyDetail.h
+    ${FOLLY_DIR}/detail/TypeList.h
+    ${FOLLY_DIR}/poly/Nullable.h
+    ${FOLLY_DIR}/poly/Regular.h
+  )
 endif()
 
 add_library(folly_base OBJECT