Add DCHECKs for checking that underlying IOBuf wasn't modified
[folly.git] / CMakeLists.txt
index 6309aa0615710593305a907954455ab90ebc7c73..9f8573bfabaa92c2cd81fb56abac3ee0c127ef79 100755 (executable)
@@ -16,20 +16,30 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON)
 
 project(${PACKAGE_NAME} CXX)
 
-if (MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS 1920)
-  set(MSVC_IS_2017 ON)
-elseif (MSVC_VERSION EQUAL 1900)
-  set(MSVC_IS_2017 OFF)
+if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
+  # Check target architecture
+  if (NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
+    message(FATAL_ERROR "Folly requires a 64bit target architecture.")
+  endif()
+
+  if (MSVC_VERSION GREATER_EQUAL 1910 AND MSVC_VERSION LESS 1920)
+    set(MSVC_IS_2017 ON)
+  elseif (MSVC_VERSION EQUAL 1900)
+    set(MSVC_IS_2017 OFF)
+  else()
+    message(
+      FATAL_ERROR
+      "This build script only supports building Folly on 64-bit Windows with "
+      "Visual Studio 2015 or Visual Studio 2017. "
+      "MSVC version '${MSVC_VERSION}' is not supported."
+    )
+  endif()
 else()
-  message(FATAL_ERROR "This build script only supports building Folly on 64-bit Windows with Visual Studio 2015 or Visual Studio 2017. MSVC version '${MSVC_VERSION}' is not supported.")
-endif()
-
-# Check target architecture
-if (NOT CMAKE_SIZEOF_VOID_P EQUAL 8)
-  message(FATAL_ERROR "Folly requires a 64bit target architecture.")
-endif()
-if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
-  message(FATAL_ERROR "The CMake build should only be used on Windows. For every other platform, use the makefile.")
+  message(
+    FATAL_ERROR
+    "The CMake build should only be used on Windows. "
+    "For every other platform, use autoconf."
+  )
 endif()
 
 set(FOLLY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/folly")
@@ -38,23 +48,32 @@ set(FOLLY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/folly")
 find_package(PythonInterp REQUIRED)
 add_custom_command(
   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/folly/build/EscapeTables.cpp
-  COMMAND ${PYTHON_EXECUTABLE} "${FOLLY_DIR}/build/generate_escape_tables.py"
+  COMMAND
+    ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/folly/build
+  COMMAND
+    ${PYTHON_EXECUTABLE} "${FOLLY_DIR}/build/generate_escape_tables.py"
+    --install_dir ${CMAKE_CURRENT_BINARY_DIR}/folly/build
   DEPENDS ${FOLLY_DIR}/build/generate_escape_tables.py
-  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/folly/build/
   COMMENT "Generating the escape tables..." VERBATIM
 )
 add_custom_command(
   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/folly/build/FormatTables.cpp
-  COMMAND ${PYTHON_EXECUTABLE} "${FOLLY_DIR}/build/generate_format_tables.py"
+  COMMAND
+    ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/folly/build
+  COMMAND
+    ${PYTHON_EXECUTABLE} "${FOLLY_DIR}/build/generate_format_tables.py"
+    --install_dir ${CMAKE_CURRENT_BINARY_DIR}/folly/build
   DEPENDS ${FOLLY_DIR}/build/generate_format_tables.py
-  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/folly/build/
   COMMENT "Generating the format tables..." VERBATIM
 )
 add_custom_command(
   OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/folly/build/GroupVarintTables.cpp"
-  COMMAND ${PYTHON_EXECUTABLE} "${FOLLY_DIR}/build/generate_varint_tables.py"
+  COMMAND
+    ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/folly/build
+  COMMAND
+    ${PYTHON_EXECUTABLE} "${FOLLY_DIR}/build/generate_varint_tables.py"
+    --install_dir ${CMAKE_CURRENT_BINARY_DIR}/folly/build
   DEPENDS ${FOLLY_DIR}/build/generate_varint_tables.py
-  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/folly/build/
   COMMENT "Generating the group varint tables..." VERBATIM
 )
 
@@ -62,14 +81,20 @@ include(folly-deps) # Find the required packages
 if (LIBPTHREAD_FOUND)
   set(FOLLY_HAVE_PTHREAD ON)
 endif()
+
+if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
+  include(FollyCompilerMSVC)
+else()
+  include(FollyCompilerUnix)
+endif()
+include(FollyFunctions)
+
+include(FollyConfigChecks)
 configure_file(
   ${CMAKE_CURRENT_SOURCE_DIR}/CMake/folly-config.h.cmake
   ${CMAKE_CURRENT_BINARY_DIR}/folly/folly-config.h
 )
 
-include(FollyCompiler)
-include(FollyFunctions)
-
 # Main folly library files
 auto_sources(files "*.cpp" "RECURSE" "${FOLLY_DIR}")
 auto_sources(hfiles "*.h" "RECURSE" "${FOLLY_DIR}")
@@ -177,11 +202,21 @@ else()
 endif()
 
 
+if("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows")
+  set(FOLLY_LINK_LIBRARIES
+    ${FOLLY_LINK_LIBRARIES}
+    Iphlpapi.lib
+    Ws2_32.lib
+  )
+else()
+  set(FOLLY_LINK_LIBRARIES
+    ${FOLLY_LINK_LIBRARIES}
+    dl
+  )
+endif()
+
 set(FOLLY_LINK_LIBRARIES
   ${FOLLY_LINK_LIBRARIES}
-  Iphlpapi.lib
-  Ws2_32.lib
-
   ${FOLLY_SHINY_DEPENDENCIES}
 )
 
@@ -216,9 +251,12 @@ source_group("" FILES ${FOLLY_DIR}/build/GenerateFingerprintTables.cpp)
 # Compile the fingerprint tables.
 add_custom_command(
   OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/folly/build/FingerprintTables.cpp
-  COMMAND GenerateFingerprintTables
+  COMMAND
+    ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/folly/build
+  COMMAND
+    GenerateFingerprintTables
+    --install_dir ${CMAKE_CURRENT_BINARY_DIR}/folly/build
   DEPENDS GenerateFingerprintTables
-  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/folly/build/
   COMMENT "Generating the fingerprint tables..."
 )
 add_library(folly_fingerprint STATIC