Add CMake build and fix major Linux blockers.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@121510 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Michael J. Spencer
2010-12-10 19:47:54 +00:00
parent b8f787b188
commit 626916fc25
15 changed files with 562 additions and 24 deletions

44
test/CMakeLists.txt Normal file
View File

@@ -0,0 +1,44 @@
macro(pythonize_bool var)
if (${var})
set(${var} True)
else()
set(${var} False)
endif()
endmacro()
include(FindPythonInterp)
if(PYTHONINTERP_FOUND)
set(LIT_EXECUTABLE "" CACHE FILEPATH "Path to LLVM's lit.py.")
set(LIT_ARGS_DEFAULT "-sv")
if (MSVC OR XCODE)
set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
endif()
set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}"
CACHE STRING "Default options for lit")
set(LIT_ARGS "${LLVM_LIT_ARGS}")
separate_arguments(LIT_ARGS)
set(LIBCXX_COMPILER ${CMAKE_CXX_COMPILER})
set(LIBCXX_SOURCE_DIR ${CMAKE_SOURCE_DIR})
set(LIBCXX_BINARY_DIR ${CMAKE_BINARY_DIR})
set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE})
pythonize_bool(LIBCXX_ENABLE_SHARED)
pythonize_bool(LIBCXX_HAS_STDCXX0X_FLAG)
set(AUTO_GEN_COMMENT "## Autogenerated by libcxx configuration.\n# Do not edit!")
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg
@ONLY)
add_custom_target(check
COMMAND ${PYTHON_EXECUTABLE}
${LIT_EXECUTABLE}
${LIT_ARGS}
${CMAKE_CURRENT_BINARY_DIR}
DEPENDS
COMMENT "Running libcxx tests")
else()
message(WARNING "Could not find Python, no check target will be available!")
endif()

View File

@@ -3,6 +3,7 @@
# Configuration file for the 'lit' test runner.
import os
import sys
import platform
import tempfile
import signal
@@ -66,8 +67,9 @@ class LibcxxTestFormat(lit.formats.FileBasedTest):
exec_file.close()
try:
cmd = [self.cxx_under_test, '-o', exec_path,
compile_cmd = [self.cxx_under_test, '-o', exec_path,
source_path] + self.cpp_flags + self.ld_flags
cmd = compile_cmd
out, err, exitCode = self.execute_command(cmd)
if exitCode != 0:
report = """Command: %s\n""" % ' '.join(["'%s'" % a
@@ -83,7 +85,9 @@ class LibcxxTestFormat(lit.formats.FileBasedTest):
cmd = [exec_path]
out, err, exitCode = self.execute_command(cmd)
if exitCode != 0:
report = """Command: %s\n""" % ' '.join(["'%s'" % a
report = """Compiled With: %s\n""" % ' '.join(["'%s'" % a
for a in compile_cmd])
report += """Command: %s\n""" % ' '.join(["'%s'" % a
for a in cmd])
report += """Exit Code: %d\n""" % exitCode
if out:
@@ -111,12 +115,35 @@ config.test_source_root = os.path.dirname(__file__)
# FIXME: Would be nice to Use -stdlib=libc++ option with Clang's that accept it.
cxx_under_test = lit.params.get('cxx_under_test', None)
if cxx_under_test is None:
lit.fatal('must specify user parameter cxx_under_test '
'(e.g., --param=cxx_under_test=clang++)')
cxx_under_test = getattr(config, 'cxx_under_test', None)
if cxx_under_test is None:
lit.fatal('must specify user parameter cxx_under_test '
'(e.g., --param=cxx_under_test=clang++)')
include_paths = []
library_paths = []
libcxx_src_root = getattr(config, 'libcxx_src_root', None)
if libcxx_src_root is not None:
include_paths += ['-I' + libcxx_src_root + '/include']
else:
include_paths += ['-I/usr/include/c++/v1']
libcxx_obj_root = getattr(config, 'libcxx_obj_root', None)
if libcxx_obj_root is not None:
library_paths += ['-L' + libcxx_obj_root + '/lib']
else:
libcxx_obj_root = "/usr"
# Configure extra libraries.
libraries = []
if sys.platform == 'darwin':
libraries += ['-lSystem']
if sys.platform == 'linux2':
libraries += ['-lgcc_eh', '-lsupc++', '-lc', '-lm', '-lgcc_s']
libraries += ['-Wl,-R', libcxx_obj_root + '/lib']
config.test_format = LibcxxTestFormat(cxx_under_test,
cpp_flags = ['-nostdinc++',
'-I/usr/include/c++/v1'],
ld_flags = ['-nodefaultlibs', '-lc++',
'-lSystem'])
cpp_flags = ['-nostdinc++'] + include_paths,
ld_flags = ['-nodefaultlibs'] + library_paths + ['-lc++'] + libraries)
config.target_triple = None

10
test/lit.site.cfg.in Normal file
View File

@@ -0,0 +1,10 @@
@AUTO_GEN_COMMENT@
config.cxx_under_test = "@LIBCXX_COMPILER@"
config.cxx_has_stdcxx0x_flag = @LIBCXX_HAS_STDCXX0X_FLAG@
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@
# Let the main config do the real work.
lit.load_config(config, "@LIBCXX_SOURCE_DIR@/test/lit.cfg")