Index: compiler-rt/cmake/Modules/AddCompilerRT.cmake =================================================================== --- compiler-rt/cmake/Modules/AddCompilerRT.cmake +++ compiler-rt/cmake/Modules/AddCompilerRT.cmake @@ -477,56 +477,99 @@ foreach(flag ${LIBCXX_CFLAGS}) set(flagstr "${flagstr} ${flag}") endforeach() - set(LIBCXX_CFLAGS ${flagstr}) + set(LIBCXX_C_FLAGS ${flagstr}) + set(LIBCXX_CXX_FLAGS ${flagstr}) if(LIBCXX_USE_TOOLCHAIN) set(compiler_args -DCMAKE_C_COMPILER=${COMPILER_RT_TEST_COMPILER} -DCMAKE_CXX_COMPILER=${COMPILER_RT_TEST_CXX_COMPILER}) if(NOT COMPILER_RT_STANDALONE_BUILD) - set(force_deps DEPENDS clang) + set(force_deps DEPENDS $) + list(APPEND LIBCXX_DEPS clang) endif() else() set(compiler_args -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}) endif() + set(STAMP_DIR ${prefix}-stamps/) + set(BINARY_DIR ${prefix}-bins/) + + add_custom_target(${name}-clear + COMMAND ${CMAKE_COMMAND} -E remove_directory ${BINARY_DIR} + COMMAND ${CMAKE_COMMAND} -E remove_directory ${STAMP_DIR} + COMMENT "Clobbering ${name} build and stamp directories" + USES_TERMINAL + ) + + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${name}-clobber-stamp + DEPENDS ${LIBCXX_DEPS} + COMMAND ${CMAKE_COMMAND} -E touch ${BINARY_DIR}/CMakeCache.txt + COMMAND ${CMAKE_COMMAND} -E touch ${STAMP_DIR}/${name}-mkdir + COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/${name}-clobber-stamp + COMMENT "Clobbering bootstrap build and stamp directories" + ) + + add_custom_target(${name}-clobber + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${name}-clobber-stamp) + if(CMAKE_SYSROOT) set(sysroot_arg -DCMAKE_SYSROOT=${CMAKE_SYSROOT}) endif() ExternalProject_Add(${name} - DEPENDS ${LIBCXX_DEPS} + DEPENDS ${name}-clobber #${LIBCXX_DEPS} PREFIX ${prefix} SOURCE_DIR ${COMPILER_RT_LIBCXX_PATH} + STAMP_DIR ${STAMP_DIR} + BINARY_DIR ${BINARY_DIR} CMAKE_ARGS -DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM} ${compiler_args} ${sysroot_arg} - -DCMAKE_C_FLAGS=${LIBCXX_CFLAGS} - -DCMAKE_CXX_FLAGS=${LIBCXX_CFLAGS} + -DCMAKE_C_FLAGS=${LIBCXX_C_FLAGS} + -DCMAKE_CXX_FLAGS=${LIBCXX_CXX_FLAGS} -DCMAKE_BUILD_TYPE=Release - -DCMAKE_INSTALL_PREFIX= + -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -DLLVM_PATH=${LLVM_MAIN_SRC_DIR} - -DLIBCXX_STANDALONE_BUILD=On + -DLIBCXX_STANDALONE_BUILD=ON ${LIBCXX_CMAKE_ARGS} - STEP_TARGETS configure build install - LOG_BUILD 1 - LOG_CONFIGURE 1 - LOG_INSTALL 1 + INSTALL_COMMAND "" + STEP_TARGETS configure build + BUILD_ALWAYS 1 + USES_TERMINAL_CONFIGURE 1 + USES_TERMINAL_BUILD 1 + USES_TERMINAL_INSTALL 1 EXCLUDE_FROM_ALL TRUE ) - ExternalProject_Add_Step(${name} force-reconfigure - DEPENDERS configure - ALWAYS 1 - ) + if (CMAKE_GENERATOR MATCHES "Make") + set(run_clean "$(MAKE)" "-C" "${BINARY_DIR}" "clean") + else() + set(run_clean ${CMAKE_COMMAND} --build ${BINARY_DIR} --target clean + --config "$") + endif() + + if(LIBCXX_USE_TOOLCHAIN AND NOT COMPILER_RT_STANDALONE_BUILD) + endif() - ExternalProject_Add_Step(${name} clobber - COMMAND ${CMAKE_COMMAND} -E remove_directory - COMMAND ${CMAKE_COMMAND} -E make_directory - COMMENT "Clobberring ${name} build directory..." - DEPENDERS configure + llvm_ExternalProject_BuildCmd(run_clean clean ${BINARY_DIR}) + ExternalProject_Add_Step(${name} clean + COMMAND ${run_clean} + COMMENT "Cleaning ${name}..." + DEPENDEES configure ${force_deps} + WORKING_DIRECTORY ${BINARY_DIR} + EXCLUDE_FROM_MAIN 1 + USES_TERMINAL 1 ) + ExternalProject_Add_StepTargets(${name} clean) + + if(LIBCXX_USE_TOOLCHAIN) + add_dependencies(${name}-clean ${name}-clobber) + set_target_properties(${name}-clean PROPERTIES + SOURCES ${CMAKE_CURRENT_BINARY_DIR}/${name}-clobber-stamp) + endif() endmacro() function(rt_externalize_debuginfo name) Index: compiler-rt/lib/fuzzer/CMakeLists.txt =================================================================== --- compiler-rt/lib/fuzzer/CMakeLists.txt +++ compiler-rt/lib/fuzzer/CMakeLists.txt @@ -86,7 +86,7 @@ set(cxx_${arch}_merge_dir "${CMAKE_CURRENT_BINARY_DIR}/cxx_${arch}_merge.dir") file(MAKE_DIRECTORY ${cxx_${arch}_merge_dir}) add_custom_command(TARGET clang_rt.${name}-${arch} POST_BUILD - COMMAND ${CMAKE_LINKER} --whole-archive "$" --no-whole-archive ${dir}/src/libcxx_fuzzer_${arch}-build/lib/libc++.a -r -o ${name}.o + COMMAND ${CMAKE_LINKER} --whole-archive "$" --no-whole-archive ${dir}-bins/lib/libc++.a -r -o ${name}.o COMMAND ${CMAKE_OBJCOPY} --localize-hidden ${name}.o COMMAND ${CMAKE_COMMAND} -E remove "$" COMMAND ${CMAKE_AR} qcs "$" ${name}.o Index: compiler-rt/lib/fuzzer/tests/CMakeLists.txt =================================================================== --- compiler-rt/lib/fuzzer/tests/CMakeLists.txt +++ compiler-rt/lib/fuzzer/tests/CMakeLists.txt @@ -40,7 +40,7 @@ if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" AND COMPILER_RT_LIBCXX_PATH) set(LIBFUZZER_TEST_RUNTIME_DEPS libcxx_fuzzer_${arch}-build) set(LIBFUZZER_TEST_RUNTIME_CFLAGS -isystem ${COMPILER_RT_LIBCXX_PATH}/include) - set(LIBFUZZER_TEST_RUNTIME_LINK_FLAGS ${LIBCXX_${arch}_PREFIX}/src/libcxx_fuzzer_${arch}-build/lib/libc++.a) + set(LIBFUZZER_TEST_RUNTIME_LINK_FLAGS ${LIBCXX_${arch}_PREFIX}-bins/lib/libc++.a) endif() set(FuzzerTestObjects) Index: compiler-rt/lib/msan/tests/CMakeLists.txt =================================================================== --- compiler-rt/lib/msan/tests/CMakeLists.txt +++ compiler-rt/lib/msan/tests/CMakeLists.txt @@ -109,7 +109,7 @@ DEPS ${MSAN_INST_LOADABLE_OBJECTS}) set(MSAN_TEST_OBJECTS ${MSAN_INST_TEST_OBJECTS} ${MSAN_INST_GTEST}) - set(MSAN_TEST_DEPS ${MSAN_TEST_OBJECTS} libcxx_msan_${arch}-install + set(MSAN_TEST_DEPS ${MSAN_TEST_OBJECTS} libcxx_msan_${arch}-build ${MSAN_LOADABLE_SO}) if(NOT COMPILER_RT_STANDALONE_BUILD) list(APPEND MSAN_TEST_DEPS msan) @@ -121,7 +121,7 @@ LINK_FLAGS ${MSAN_UNITTEST_LINK_FLAGS} ${TARGET_LINK_FLAGS} "-Wl,-rpath=${CMAKE_CURRENT_BINARY_DIR}" - "-Wl,-rpath=${LIBCXX_PREFIX}/lib") + "-Wl,-rpath=${LIBCXX_PREFIX}-bins/lib") endmacro() # We should only build MSan unit tests if we can build instrumented libcxx. @@ -133,7 +133,7 @@ DEPS ${MSAN_RUNTIME_LIBRARIES} CFLAGS ${MSAN_LIBCXX_CFLAGS} ${TARGET_CFLAGS} USE_TOOLCHAIN) - set(MSAN_LIBCXX_SO ${LIBCXX_PREFIX}/lib/libc++.so) + set(MSAN_LIBCXX_SO ${LIBCXX_PREFIX}-bins/lib/libc++.so) add_msan_tests_for_arch(${arch} "" "") add_msan_tests_for_arch(${arch} "-with-call" Index: compiler-rt/lib/tsan/CMakeLists.txt =================================================================== --- compiler-rt/lib/tsan/CMakeLists.txt +++ compiler-rt/lib/tsan/CMakeLists.txt @@ -214,7 +214,7 @@ DEPS ${TSAN_RUNTIME_LIBRARIES} CFLAGS ${TARGET_CFLAGS} -fsanitize=thread USE_TOOLCHAIN) - list(APPEND libcxx_tsan_deps libcxx_tsan_${arch}-install) + list(APPEND libcxx_tsan_deps libcxx_tsan_${arch}-build) endforeach() add_custom_target(libcxx_tsan DEPENDS ${libcxx_tsan_deps}) Index: compiler-rt/test/lit.common.configured.in =================================================================== --- compiler-rt/test/lit.common.configured.in +++ compiler-rt/test/lit.common.configured.in @@ -21,6 +21,7 @@ set_default("gold_executable", "@GOLD_EXECUTABLE@") set_default("clang", "@COMPILER_RT_RESOLVED_TEST_COMPILER@") set_default("compiler_id", "@COMPILER_RT_TEST_COMPILER_ID@") +set_default("libcxx_path", "@COMPILER_RT_LIBCXX_PATH@") set_default("python_executable", "@PYTHON_EXECUTABLE@") set_default("compiler_rt_debug", @COMPILER_RT_DEBUG_PYBOOL@) set_default("compiler_rt_libdir", "@COMPILER_RT_RESOLVED_LIBRARY_OUTPUT_DIR@") Index: compiler-rt/test/tsan/lit.cfg =================================================================== --- compiler-rt/test/tsan/lit.cfg +++ compiler-rt/test/tsan/lit.cfg @@ -56,8 +56,8 @@ if config.has_libcxx and config.host_os != 'Darwin': # FIXME: Dehardcode this path somehow. libcxx_path = os.path.join(config.compiler_rt_obj_root, "lib", - "tsan", "libcxx_tsan_" + config.target_arch) - libcxx_incdir = os.path.join(libcxx_path, "include", "c++", "v1") + "tsan", "libcxx_tsan_%s-bins" % config.target_arch) + libcxx_incdir = os.path.join(config.libcxx_path, "include") libcxx_libdir = os.path.join(libcxx_path, "lib") libcxx_so = os.path.join(libcxx_libdir, "libc++.so") clang_tsan_cxxflags += ["-nostdinc++",