[libcxx] r223591 - Add support for building and testing libc++ without threads to CMake.

Eric Fiselier eric at efcs.ca
Sat Dec 6 13:02:59 PST 2014


Author: ericwf
Date: Sat Dec  6 15:02:58 2014
New Revision: 223591

URL: http://llvm.org/viewvc/llvm-project?rev=223591&view=rev
Log:
Add support for building and testing libc++ without threads to CMake.

Currently hacks must be used in to configure and build libc++ without threads
when using CMake. This patch adds CMake options to enable/disable building with
threads and a monotonic clock.

This patch also propagates the configuration information to lit so the tests
are properly configured as well.

Modified:
    libcxx/trunk/CMakeLists.txt
    libcxx/trunk/test/CMakeLists.txt
    libcxx/trunk/test/lit.cfg
    libcxx/trunk/test/lit.site.cfg.in

Modified: libcxx/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/CMakeLists.txt?rev=223591&r1=223590&r2=223591&view=diff
==============================================================================
--- libcxx/trunk/CMakeLists.txt (original)
+++ libcxx/trunk/CMakeLists.txt Sat Dec  6 15:02:58 2014
@@ -42,6 +42,10 @@ option(LIBCXX_ENABLE_PEDANTIC "Compile w
 option(LIBCXX_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
 option(LIBCXX_ENABLE_CXX1Y "Enable -std=c++1y and use of c++1y language features if the compiler supports it." OFF)
 option(LIBCXX_ENABLE_SHARED "Build libc++ as a shared library." ON)
+option(LIBCXX_ENABLE_THREADS "Build libc++ with support for threads." ON)
+option(LIBCXX_ENABLE_MONOTONIC_CLOCK
+  "Build libc++ with support for a monotonic clock.
+   This option may only be used when LIBCXX_ENABLE_THREADS=OFF." ON)
 option(LIBCXX_INSTALL_SUPPORT_HEADERS "Install libc++ support headers." ON)
 if (LIBCXX_BUILT_STANDALONE)
   set(LLVM_USE_SANITIZER "" CACHE STRING
@@ -206,6 +210,18 @@ if (MSVC)
   add_definitions(-D_CRT_SECURE_NO_WARNINGS)
 endif()
 
+# LIBCXX_ENABLE_THREADS configuration
+if (NOT LIBCXX_ENABLE_THREADS)
+  add_definitions(-D_LIBCPP_HAS_NO_THREADS)
+  if (NOT LIBCXX_ENABLE_MONOTONIC_CLOCK)
+    add_definitions(-D_LIBCPP_HAS_NO_MONOTONIC_CLOCK)
+  endif()
+# Ensure LIBCXX_ENABLE_MONOTONIC_CLOCK is set to ON.
+elseif(NOT LIBCXX_ENABLE_MONOTONIC_CLOCK)
+  message(FATAL_ERROR "LIBCXX_ENABLE_MONOTONIC_CLOCK can only be set to OFF"
+                      " when LIBCXX_ENABLE_THREADS is also set to OFF.")
+endif()
+
 # Configure for sanitizers. If LIBCXX_BUILT_STANDALONE then we have to do
 # the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it.
 if (LIBCXX_BUILT_STANDALONE)

Modified: libcxx/trunk/test/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/CMakeLists.txt?rev=223591&r1=223590&r2=223591&view=diff
==============================================================================
--- libcxx/trunk/test/CMakeLists.txt (original)
+++ libcxx/trunk/test/CMakeLists.txt Sat Dec  6 15:02:58 2014
@@ -28,6 +28,8 @@ if(PYTHONINTERP_FOUND)
   set(LIBCXX_BINARY_DIR ${CMAKE_BINARY_DIR})
   set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
   pythonize_bool(LIBCXX_ENABLE_SHARED)
+  pythonize_bool(LIBCXX_ENABLE_THREADS)
+  pythonize_bool(LIBCXX_ENABLE_MONOTONIC_CLOCK)
 
   set(AUTO_GEN_COMMENT "## Autogenerated by libcxx configuration.\n# Do not edit!")
 

Modified: libcxx/trunk/test/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/lit.cfg?rev=223591&r1=223590&r2=223591&view=diff
==============================================================================
--- libcxx/trunk/test/lit.cfg (original)
+++ libcxx/trunk/test/lit.cfg Sat Dec  6 15:02:58 2014
@@ -360,10 +360,14 @@ class Configuration(object):
             self.config.available_features.add(
                 'with_system_lib=%s' % self.config.target_triple)
 
-        if 'libcpp-has-no-threads' in self.config.available_features:
+        # TODO 6/12/2014: Remove these once the buildmaster restarts.
+        # Removing before will break the bot that tests libcpp-has-no-threads.
+        if 'libcpp-has-no-threads' in self.config.available_features \
+            and '-D_LIBCPP_HAS_NO_THREADS' not in self.compile_flags:
             self.compile_flags += ['-D_LIBCPP_HAS_NO_THREADS']
 
-        if 'libcpp-has-no-monotonic-clock' in self.config.available_features:
+        if 'libcpp-has-no-monotonic-clock' in self.config.available_features \
+            and '-D_LIBCPP_HAS_NO_MONOTONIC_CLOCK' not in self.compile_flags:
             self.compile_flags += ['-D_LIBCPP_HAS_NO_MONOTONIC_CLOCK']
 
         # Some linux distributions have different locale data than others.
@@ -384,6 +388,19 @@ class Configuration(object):
             self.compile_flags += ['-D__STDC_FORMAT_MACROS',
                                    '-D__STDC_LIMIT_MACROS',
                                    '-D__STDC_CONSTANT_MACROS']
+        # Configure threading features.
+        enable_threads = self.get_lit_bool('enable_threads')
+        enable_monotonic_clock = self.get_lit_bool('enable_monotonic_clock')
+        assert enable_threads is not None and enable_monotonic_clock is not None
+        if not enable_threads:
+            self.compile_flags += ['-D_LIBCPP_HAS_NO_THREADS']
+            self.config.available_features.add('libcpp-has-no-threads')
+            if not enable_monotonic_clock:
+                self.compile_flags += ['-D_LIBCPP_HAS_NO_MONOTONIC_CLOCK']
+                self.config.available_features.add('libcpp-has-no-monotonic-clock')
+        elif not enable_monotonic_clock:
+            self.lit_config.fatal('enable_monotonic_clock cannot be false when'
+                                  ' enable_threads is true.')
 
     def configure_link_flags(self):
         # Configure library search paths

Modified: libcxx/trunk/test/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/lit.site.cfg.in?rev=223591&r1=223590&r2=223591&view=diff
==============================================================================
--- libcxx/trunk/test/lit.site.cfg.in (original)
+++ libcxx/trunk/test/lit.site.cfg.in Sat Dec  6 15:02:58 2014
@@ -1,13 +1,15 @@
 @AUTO_GEN_COMMENT@
-config.cxx_under_test        = "@LIBCXX_COMPILER@"
-config.std                   = "@LIBCXX_STD_VERSION@"
-config.libcxx_src_root       = "@LIBCXX_SOURCE_DIR@"
-config.libcxx_obj_root       = "@LIBCXX_BINARY_DIR@"
-config.python_executable     = "@PYTHON_EXECUTABLE@"
-config.enable_shared         = @LIBCXX_ENABLE_SHARED@
-config.cxx_abi               = "@LIBCXX_CXX_ABI_LIBNAME@"
-config.llvm_use_sanitizer    = "@LLVM_USE_SANITIZER@"
-config.abi_library_path      = "@LIBCXX_CXX_ABI_LIBRARY_PATH@"
+config.cxx_under_test           = "@LIBCXX_COMPILER@"
+config.std                      = "@LIBCXX_STD_VERSION@"
+config.libcxx_src_root          = "@LIBCXX_SOURCE_DIR@"
+config.libcxx_obj_root          = "@LIBCXX_BINARY_DIR@"
+config.python_executable        = "@PYTHON_EXECUTABLE@"
+config.enable_shared            = "@LIBCXX_ENABLE_SHARED@"
+config.enable_threads           = "@LIBCXX_ENABLE_THREADS@"
+config.enable_monotonic_clock   = "@LIBCXX_ENABLE_MONOTONIC_CLOCK@"
+config.cxx_abi                  = "@LIBCXX_CXX_ABI_LIBNAME@"
+config.llvm_use_sanitizer       = "@LLVM_USE_SANITIZER@"
+config.abi_library_path         = "@LIBCXX_CXX_ABI_LIBRARY_PATH@"
 
 # Let the main config do the real work.
 lit_config.load_config(config, "@LIBCXX_SOURCE_DIR@/test/lit.cfg")





More information about the cfe-commits mailing list