cmake: fix the test builds
[folly.git] / CMakeLists.txt
index 8669d265757322edefd402fa7904b498ab1a1861..dee718b87439bd541d0929041bae6c2e627e5bba 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
@@ -289,6 +327,7 @@ if (BUILD_TESTS)
     ${FOLLY_DIR}/test/SingletonTestStructs.cpp
     ${FOLLY_DIR}/test/SocketAddressTestHelper.cpp
     ${FOLLY_DIR}/test/SocketAddressTestHelper.h
+    ${FOLLY_DIR}/experimental/logging/test/TestLogHandler.cpp
     ${FOLLY_DIR}/experimental/logging/test/TestLogHandler.h
     ${FOLLY_DIR}/futures/test/TestExecutor.cpp
     ${FOLLY_DIR}/futures/test/TestExecutor.h
@@ -336,6 +375,7 @@ if (BUILD_TESTS)
     DIRECTORY container/test/
       TEST access_test SOURCES AccessTest.cpp
       TEST array_test SOURCES ArrayTest.cpp
+      TEST bit_iterator_test SOURCES BitIteratorTest.cpp
       TEST enumerate_test SOURCES EnumerateTest.cpp
       TEST evicting_cache_map_test SOURCES EvictingCacheMapTest.cpp
       TEST foreach_test SOURCES ForeachTest.cpp
@@ -386,6 +426,7 @@ if (BUILD_TESTS)
     DIRECTORY experimental/logging/test/
       TEST async_file_writer_test SOURCES AsyncFileWriterTest.cpp
       TEST config_parser_test SOURCES ConfigParserTest.cpp
+      TEST config_update_test SOURCES ConfigUpdateTest.cpp
       TEST file_handler_factory_test SOURCES FileHandlerFactoryTest.cpp
       TEST glog_formatter_test SOURCES GlogFormatterTest.cpp
       TEST immediate_file_writer_test SOURCES ImmediateFileWriterTest.cpp
@@ -515,6 +556,11 @@ if (BUILD_TESTS)
     DIRECTORY io/async/ssl/test/
       TEST ssl_errors_test SOURCES SSLErrorsTest.cpp
 
+    DIRECTORY lang/test/
+      TEST bits_test SOURCES BitsTest.cpp
+      TEST cold_class_test SOURCES ColdClassTest.cpp
+      TEST safe_assert_test SOURCES SafeAssertTest.cpp
+
     DIRECTORY memory/test/
       TEST arena_test SOURCES ArenaTest.cpp
       TEST thread_cached_arena_test SOURCES ThreadCachedArenaTest.cpp
@@ -532,11 +578,13 @@ if (BUILD_TESTS)
     DIRECTORY stats/test/
       TEST histogram_test SOURCES HistogramTest.cpp
       TEST timeseries_histogram_test SOURCES TimeseriesHistogramTest.cpp
-      TEST timeseries_test SOURCES TimeseriesTest.cpp
+      TEST timeseries_test SOURCES TimeSeriesTest.cpp
 
     DIRECTORY synchronization/test/
+      TEST baton_test SOURCES BatonTest.cpp
       TEST call_once_test SOURCES CallOnceTest.cpp
       TEST lifo_sem_test SOURCES LifoSemTests.cpp
+      TEST rw_spin_lock_test SOURCES RWSpinLockTest.cpp
 
     DIRECTORY system/test/
       TEST memory_mapping_test SOURCES MemoryMappingTest.cpp
@@ -545,6 +593,9 @@ if (BUILD_TESTS)
       TEST thread_id_test SOURCES ThreadIdTest.cpp
       TEST thread_name_test SOURCES ThreadNameTest.cpp
 
+    DIRECTORY synchronization/test/
+      TEST atomic_struct_test SOURCES AtomicStructTest.cpp
+
     DIRECTORY test/
       TEST ahm_int_stress_test SOURCES AHMIntStressTest.cpp
       TEST arena_smartptr_test SOURCES ArenaSmartPtrTest.cpp
@@ -554,15 +605,10 @@ if (BUILD_TESTS)
       TEST atomic_hash_map_test HANGING
         SOURCES AtomicHashMapTest.cpp
       TEST atomic_linked_list_test SOURCES AtomicLinkedListTest.cpp
-      TEST atomic_struct_test SOURCES AtomicStructTest.cpp
       TEST atomic_unordered_map_test SOURCES AtomicUnorderedMapTest.cpp
-      TEST baton_test SOURCES BatonTest.cpp
-      TEST bit_iterator_test SOURCES BitIteratorTest.cpp
-      TEST bits_test SOURCES BitsTest.cpp
       TEST cacheline_padded_test SOURCES CachelinePaddedTest.cpp
       TEST clock_gettime_wrappers_test SOURCES ClockGettimeWrappersTest.cpp
       TEST concurrent_skip_list_test SOURCES ConcurrentSkipListTest.cpp
-      TEST container_traits_test SOURCES ContainerTraitsTest.cpp
       TEST conv_test SOURCES ConvTest.cpp
       TEST cpu_id_test SOURCES CpuIdTest.cpp
       TEST demangle_test SOURCES DemangleTest.cpp
@@ -580,7 +626,7 @@ if (BUILD_TESTS)
       #TEST file_lock_test SOURCES FileLockTest.cpp
       TEST file_util_test HANGING
         SOURCES FileUtilTest.cpp
-      TEST fingerprint_test SOURCES FingerprintTest.cpp
+      TEST fingerprint_test SOURCES FingerprintTest.cpp
       TEST format_other_test SOURCES FormatOtherTest.cpp
       TEST format_test SOURCES FormatTest.cpp
       TEST function_scheduler_test SOURCES FunctionSchedulerTest.cpp
@@ -626,17 +672,15 @@ if (BUILD_TESTS)
       TEST portability_test SOURCES PortabilityTest.cpp
       TEST producer_consumer_queue_test SLOW
         SOURCES ProducerConsumerQueueTest.cpp
-      TEST r_w_spin_lock_test SOURCES RWSpinLockTest.cpp
       TEST random_test SOURCES RandomTest.cpp
       TEST range_test SOURCES RangeTest.cpp
-      TEST safe_assert_test SOURCES SafeAssertTest.cpp
       TEST scope_guard_test SOURCES ScopeGuardTest.cpp
       # Heavily dependent on drand and srand48
       #TEST shared_mutex_test SOURCES SharedMutexTest.cpp
-      TEST singleton_test SOURCES SingletonTest.cpp
+      # SingletonTest requires Subprocess
+      #TEST singleton_test SOURCES SingletonTest.cpp
       TEST singleton_test_global SOURCES SingletonTestGlobal.cpp
       TEST singleton_thread_local_test SOURCES SingletonThreadLocalTest.cpp
-      TEST singletonvault_c_test SOURCES SingletonVaultCTest.cpp
       TEST small_vector_test SOURCES small_vector_test.cpp
       TEST sorted_vector_types_test SOURCES sorted_vector_test.cpp
       TEST string_test SOURCES StringTest.cpp