summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2014-05-09 22:11:03 +0000
committerAlexey Samsonov <samsonov@google.com>2014-05-09 22:11:03 +0000
commit2e8e44123a1af21beacf1190fc9f9c8104088c5f (patch)
treef695eb3804dbd01b18db183bb7ffe705e86065ac /cmake
parent37ad976ebf0b192db2c7d5f23c404d4e0dede625 (diff)
[CMake] Use ExternalProject to build MSan-ified version of libcxx for unit tests.
This change lets MSan rely on libcxx's own build system instead of manually compiling its sources and setting up all the necessary compile flags. It would also simplify compiling libcxx with another sanitizers (in particular, TSan). The tricky part is to make sure libcxx is reconfigured/rebuilt when Clang or MSan runtime library is changed. "clobber" step used in this patch works well for me, but it's possible it would break for other configurations - will watch the buildbots. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@208451 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'cmake')
-rw-r--r--cmake/Modules/AddCompilerRT.cmake46
1 files changed, 46 insertions, 0 deletions
diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake
index 82947eac4..ba22927d7 100644
--- a/cmake/Modules/AddCompilerRT.cmake
+++ b/cmake/Modules/AddCompilerRT.cmake
@@ -1,4 +1,5 @@
include(AddLLVM)
+include(ExternalProject)
include(LLVMParseArguments)
include(CompilerRTUtils)
@@ -167,3 +168,48 @@ macro(add_compiler_rt_script name)
PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
DESTINATION ${COMPILER_RT_INSTALL_PATH}/bin)
endmacro(add_compiler_rt_script src name)
+
+# Builds custom version of libc++ and installs it in <prefix>.
+# Can be used to build sanitized versions of libc++ for running unit tests.
+# add_custom_libcxx(<name> <prefix>
+# DEPS <list of build deps>
+# CFLAGS <list of compile flags>)
+macro(add_custom_libcxx name prefix)
+ if(NOT COMPILER_RT_HAS_LIBCXX_SOURCES)
+ message(FATAL_ERROR "libcxx not found!")
+ endif()
+
+ parse_arguments(LIBCXX "DEPS;CFLAGS" "" ${ARGN})
+ foreach(flag ${LIBCXX_CFLAGS})
+ set(flagstr "${flagstr} ${flag}")
+ endforeach()
+ set(LIBCXX_CFLAGS ${flagstr})
+
+ if(NOT COMPILER_RT_STANDALONE_BUILD)
+ list(APPEND LIBCXX_DEPS clang)
+ endif()
+
+ ExternalProject_Add(${name}
+ PREFIX ${prefix}
+ SOURCE_DIR ${COMPILER_RT_LIBCXX_PATH}
+ CMAKE_ARGS -DCMAKE_C_COMPILER=${COMPILER_RT_TEST_COMPILER}
+ -DCMAKE_CXX_COMPILER=${COMPILER_RT_TEST_COMPILER}
+ -DCMAKE_C_FLAGS=${LIBCXX_CFLAGS}
+ -DCMAKE_CXX_FLAGS=${LIBCXX_CFLAGS}
+ -DCMAKE_BUILD_TYPE=Release
+ -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR>
+ )
+
+ ExternalProject_Add_Step(${name} force-reconfigure
+ DEPENDERS configure
+ ALWAYS 1
+ )
+
+ ExternalProject_Add_Step(${name} clobber
+ COMMAND ${CMAKE_COMMAND} -E remove_directory <BINARY_DIR>
+ COMMAND ${CMAKE_COMMAND} -E make_directory <BINARY_DIR>
+ COMMENT "Clobberring ${name} build directory..."
+ DEPENDERS configure
+ DEPENDS ${LIBCXX_DEPS}
+ )
+endmacro()