Index: compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake =================================================================== --- compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake +++ compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake @@ -477,56 +477,97 @@ 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(toolchain_deps $) + set(force_deps DEPENDS $) 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} ${toolchain_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 + -DLLVM_BINARY_DIR=${prefix} + -DLLVM_LIBRARY_OUTPUT_INTDIR=${prefix}/lib + -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() - ExternalProject_Add_Step(${name} clobber - COMMAND ${CMAKE_COMMAND} -E remove_directory - COMMAND ${CMAKE_COMMAND} -E make_directory - COMMENT "Clobberring ${name} build directory..." - DEPENDERS configure + 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/trunk/lib/fuzzer/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/fuzzer/CMakeLists.txt +++ compiler-rt/trunk/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}/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 @@ -104,9 +104,9 @@ -fvisibility=hidden CMAKE_ARGS -DLIBCXX_ENABLE_EXCEPTIONS=OFF -DLIBCXX_CXX_ABI=none) - target_compile_options(RTfuzzer.${arch} PRIVATE -isystem ${COMPILER_RT_LIBCXX_PATH}/include) + target_compile_options(RTfuzzer.${arch} PRIVATE -isystem ${LIBCXX_${arch}_PREFIX}/include/c++/v1) add_dependencies(RTfuzzer.${arch} libcxx_fuzzer_${arch}-build) - target_compile_options(RTfuzzer_main.${arch} PRIVATE -isystem ${COMPILER_RT_LIBCXX_PATH}/include) + target_compile_options(RTfuzzer_main.${arch} PRIVATE -isystem ${LIBCXX_${arch}_PREFIX}/include/c++/v1) add_dependencies(RTfuzzer_main.${arch} libcxx_fuzzer_${arch}-build) partially_link_libcxx(fuzzer_no_main ${LIBCXX_${arch}_PREFIX} ${arch}) partially_link_libcxx(fuzzer ${LIBCXX_${arch}_PREFIX} ${arch}) Index: compiler-rt/trunk/lib/fuzzer/tests/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/fuzzer/tests/CMakeLists.txt +++ compiler-rt/trunk/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}/lib/libc++.a) endif() set(FuzzerTestObjects) Index: compiler-rt/trunk/lib/msan/tests/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/msan/tests/CMakeLists.txt +++ compiler-rt/trunk/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) Index: compiler-rt/trunk/lib/tsan/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/tsan/CMakeLists.txt +++ compiler-rt/trunk/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/trunk/test/fuzzer/lit.cfg =================================================================== --- compiler-rt/trunk/test/fuzzer/lit.cfg +++ compiler-rt/trunk/test/fuzzer/lit.cfg @@ -7,8 +7,6 @@ config.suffixes = ['.test'] config.test_source_root = os.path.dirname(__file__) -config.environment['LD_LIBRARY_PATH'] = config.llvm_library_dir - # Choose between lit's internal shell pipeline runner and a real shell. If # LIT_USE_INTERNAL_SHELL is in the environment, we use that as an override. use_lit_shell = os.environ.get("LIT_USE_INTERNAL_SHELL") @@ -54,9 +52,9 @@ def generate_compiler_cmd(is_cpp=True, fuzzer_enabled=True): compiler_cmd = config.c_compiler if config.clang and config.stdlib == 'libc++': - link_cmd = '-stdlib=libc++' + link_cmd = '-stdlib=libc++ -Wl,-rpath=%s' % config.llvm_library_dir elif config.clang and config.stdlib == 'static-libc++': - link_cmd = '-stdlib=libc++ -lc++abi -static-libstdc++' + link_cmd = '-stdlib=libc++ -lc++abi -static-libstdc++ -Wl,-rpath=%s' % config.llvm_library_dir else: link_cmd = '-lc++' if any(x in config.target_triple for x in ('darwin', 'freebsd')) else '-lstdc++' std_cmd = '--driver-mode=g++ -std=c++11' if is_cpp else '' Index: compiler-rt/trunk/test/tsan/lit.cfg =================================================================== --- compiler-rt/trunk/test/tsan/lit.cfg +++ compiler-rt/trunk/test/tsan/lit.cfg @@ -56,7 +56,7 @@ 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) + "tsan", "libcxx_tsan_%s" % config.target_arch) libcxx_incdir = os.path.join(libcxx_path, "include", "c++", "v1") libcxx_libdir = os.path.join(libcxx_path, "lib") libcxx_so = os.path.join(libcxx_libdir, "libc++.so")