Index: compiler-rt/trunk/CMakeLists.txt =================================================================== --- compiler-rt/trunk/CMakeLists.txt +++ compiler-rt/trunk/CMakeLists.txt @@ -182,7 +182,26 @@ pythonize_bool(COMPILER_RT_DEBUG) option(COMPILER_RT_INTERCEPT_LIBDISPATCH - "Support interception of libdispatch (GCD). Requires '-fblocks'." OFF) + "Support interception of libdispatch (GCD). Requires '-fblocks'" OFF) +option(COMPILER_RT_BLOCKS_RUNTIME_LIBRARY_PATH + "Library search path for blocks runtime (-lBlocksRuntime)" "") +option(COMPILER_RT_LIBDISPATCH_LIBRARY_PATH + "Library search path for libdispatch (-ldispatch)" "") +if (COMPILER_RT_INTERCEPT_LIBDISPATCH) + set(COMPILER_RT_INTERCEPT_LIBDISPATCH_CFLAGS -fblocks) + set(COMPILER_RT_INTERCEPT_LIBDISPATCH_LINK_FLAGS) + if (COMPILER_RT_BLOCKS_RUNTIME_LIBRARY_PATH) + list(APPEND COMPILER_RT_INTERCEPT_LIBDISPATCH_LINK_FLAGS + -L${COMPILER_RT_BLOCKS_RUNTIME_LIBRARY_PATH} + -Wl,-rpath=${COMPILER_RT_BLOCKS_RUNTIME_LIBRARY_PATH}) + endif() + if (COMPILER_RT_LIBDISPATCH_LIBRARY_PATH) + list(APPEND COMPILER_RT_INTERCEPT_LIBDISPATCH_LINK_FLAGS + -L${COMPILER_RT_LIBDISPATCH_LIBRARY_PATH} + -Wl,-rpath=${COMPILER_RT_LIBDISPATCH_LIBRARY_PATH}) + endif() + list(APPEND COMPILER_RT_INTERCEPT_LIBDISPATCH_LINK_FLAGS -lBlocksRuntime -ldispatch) +endif() if (APPLE) # Always enable on Apple platforms. set(COMPILER_RT_INTERCEPT_LIBDISPATCH ON) endif() Index: compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake =================================================================== --- compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake +++ compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake @@ -595,6 +595,7 @@ -DCMAKE_C_FLAGS=${LIBCXX_C_FLAGS} -DCMAKE_CXX_FLAGS=${LIBCXX_CXX_FLAGS} -DCMAKE_BUILD_TYPE=Release + -DCMAKE_TRY_COMPILE_TARGET_TYPE=STATIC_LIBRARY -DLLVM_PATH=${LLVM_MAIN_SRC_DIR} -DLLVM_BINARY_DIR=${prefix} -DLLVM_LIBRARY_OUTPUT_INTDIR=${prefix}/lib Index: compiler-rt/trunk/lib/tsan/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/tsan/CMakeLists.txt +++ compiler-rt/trunk/lib/tsan/CMakeLists.txt @@ -72,10 +72,7 @@ if(COMPILER_RT_INTERCEPT_LIBDISPATCH) list(APPEND TSAN_SOURCES rtl/tsan_libdispatch.cc) - # Libdispatch support for non-Apple platforms requires '-fblocks'. - if (NOT APPLE) - list(APPEND TSAN_RTL_CFLAGS "-fblocks") - endif() + list(APPEND TSAN_RTL_CFLAGS ${COMPILER_RT_INTERCEPT_LIBDISPATCH_CFLAGS}) endif() set(TSAN_HEADERS Index: compiler-rt/trunk/lib/tsan/tests/CMakeLists.txt =================================================================== --- compiler-rt/trunk/lib/tsan/tests/CMakeLists.txt +++ compiler-rt/trunk/lib/tsan/tests/CMakeLists.txt @@ -45,6 +45,7 @@ else() list(APPEND LINK_FLAGS -fsanitize=thread) list(APPEND LINK_FLAGS -lm) + list(APPEND LINK_FLAGS ${COMPILER_RT_INTERCEPT_LIBDISPATCH_LINK_FLAGS}) endif() set(TSAN_RTL_HEADERS) Index: compiler-rt/trunk/test/tsan/CMakeLists.txt =================================================================== --- compiler-rt/trunk/test/tsan/CMakeLists.txt +++ compiler-rt/trunk/test/tsan/CMakeLists.txt @@ -31,6 +31,9 @@ string(TOLOWER "-${arch}" TSAN_TEST_CONFIG_SUFFIX) get_test_cc_for_arch(${arch} TSAN_TEST_TARGET_CC TSAN_TEST_TARGET_CFLAGS) + string(REPLACE ";" " " LIBDISPATCH_LINK_FLAGS_STRING " ${COMPILER_RT_INTERCEPT_LIBDISPATCH_LINK_FLAGS}") + string(APPEND TSAN_TEST_TARGET_CFLAGS ${LIBDISPATCH_LINK_FLAGS_STRING}) + string(TOUPPER ${arch} ARCH_UPPER_CASE) set(CONFIG_NAME ${ARCH_UPPER_CASE}Config)