Index: cmake/Modules/AddCompilerRT.cmake =================================================================== --- cmake/Modules/AddCompilerRT.cmake +++ cmake/Modules/AddCompilerRT.cmake @@ -32,9 +32,11 @@ # SOURCES # CFLAGS # DEFS -# DEPS ) +# DEPS +# ADDITIONAL_HEADERS
) +# ADDITIONAL_HEADER_DIRS
) function(add_compiler_rt_object_libraries name) - cmake_parse_arguments(LIB "" "" "OS;ARCHS;SOURCES;CFLAGS;DEFS;DEPS" ${ARGN}) + cmake_parse_arguments(LIB "" "" "OS;ARCHS;SOURCES;CFLAGS;DEFS;DEPS;ADDITIONAL_HEADERS;ADDITIONAL_HEADER_DIRS" ${ARGN}) set(libnames) if(APPLE) foreach(os ${LIB_OS}) @@ -55,6 +57,18 @@ endforeach() endif() + # Add headers to LIB_SOURCES for IDEs + crt_process_sources(LIB_SOURCES + ${LIB_SOURCES} + ADDITIONAL_HEADERS + ${LIB_ADDITIONAL_HEADERS} + ADDITIONAL_HEADER_DIRS + # We implicitly pass the current source directory which commonly contains + # the relevant header files. This simplifies the call sites. + "${CMAKE_CURRENT_SOURCE_DIR}" + ${LIB_ADDITIONAL_HEADER_DIRS} + ) + foreach(libname ${libnames}) add_library(${libname} OBJECT ${LIB_SOURCES}) if(LIB_DEPS) @@ -128,7 +142,9 @@ # DEFS # LINK_LIBS (only for shared library) # OBJECT_LIBS -# PARENT_TARGET ) +# PARENT_TARGET +# ADDITIONAL_HEADERS
+# ADDITIONAL_HEADER_DIRS
) function(add_compiler_rt_runtime name type) if(NOT type MATCHES "^(STATIC|SHARED)$") message(FATAL_ERROR "type argument must be STATIC or SHARED") @@ -137,7 +153,7 @@ cmake_parse_arguments(LIB "" "PARENT_TARGET" - "OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;LINK_LIBS;OBJECT_LIBS" + "OS;ARCHS;SOURCES;CFLAGS;LINK_FLAGS;DEFS;LINK_LIBS;OBJECT_LIBS;ADDITIONAL_HEADERS;ADDITIONAL_HEADER_DIRS" ${ARGN}) set(libnames) # Until we support this some other way, build compiler-rt runtime without LTO @@ -148,6 +164,23 @@ set(NO_LTO_FLAGS "") endif() + list(LENGTH LIB_SOURCES LIB_SOURCES_LENGTH) + if (${LIB_SOURCES_LENGTH} GREATER 0) + # Add headers to LIB_SOURCES for IDEs. It doesn't make sense to + # do this for a runtime library that only consists of OBJECT + # libraries, so only add the headers when source files are present. + crt_process_sources(LIB_SOURCES + ${LIB_SOURCES} + ADDITIONAL_HEADERS + ${LIB_ADDITIONAL_HEADERS} + ADDITIONAL_HEADER_DIRS + # We implicitly pass the current source directory which commonly + # contains the relevant header files. This simplifies the call sites. + "${CMAKE_CURRENT_SOURCE_DIR}" + ${LIB_ADDITIONAL_HEADER_DIRS} + ) + endif() + if(APPLE) foreach(os ${LIB_OS}) # Strip out -msse3 if this isn't macOS. Index: cmake/Modules/CompilerRTUtils.cmake =================================================================== --- cmake/Modules/CompilerRTUtils.cmake +++ cmake/Modules/CompilerRTUtils.cmake @@ -314,3 +314,58 @@ endforeach () set(${output_var} ${intermediate} PARENT_SCOPE) endfunction() + +function(crt_find_headers_in_dir OUTPUT_VAR DIR) + if (NOT IS_DIRECTORY "${DIR}") + message(FATAL_ERROR "\"${DIR}\" is not a directory") + endif() + set(found_headers "") + foreach (pattern "*.h" "*.def" "*.inc") + file(GLOB matched_header_files RELATIVE "${DIR}" "${pattern}") + list(APPEND found_headers ${matched_header_files}) + endforeach() + set("${OUTPUT_VAR}" ${found_headers} PARENT_SCOPE) +endfunction() + +# crt_process_sources( +# +# ... +# [ADDITIONAL_HEADERS
...] +# [ADDITIONAL_HEADER_DIRS
...] +# ) +# +# Process the provided sources and write the list of new sources +# into ``. +# +# ADDITIONAL_HEADERS - Adds the supplied header to list of sources for IDEs. +# ADDITIONAL_HEADER_DIRS - Searchers the provided directory for headers which +# are added to the list of sources for IDEs. +# +# This function is very similar to `llvm_process_sources()` but exists here +# because we need to support standalone builds of compiler-rt. +function(crt_process_sources OUTPUT_VAR) + cmake_parse_arguments( + ARG + "" + "" + "ADDITIONAL_HEADERS;ADDITIONAL_HEADER_DIRS" + ${ARGN} + ) + set(sources ${ARG_UNPARSED_ARGUMENTS}) + set(headers "") + if (XCODE OR MSVC_IDE OR CMAKE_EXTRA_GENERATOR) + # For IDEs we need to tell CMake about header files. + # Otherwise they won't show up in UI. + set(headers ${ARG_ADDITIONAL_HEADERS}) + foreach (header_dir ${ARG_ADDITIONAL_HEADER_DIRS}) + crt_find_headers_in_dir(headers_in_dir "${header_dir}") + list(APPEND headers ${headers_in_dir}) + endforeach() + list(LENGTH headers headers_length) + if (${headers_length} GREATER 0) + set_source_files_properties(${headers} + PROPERTIES HEADER_FILE_ONLY ON) + endif() + endif() + set("${OUTPUT_VAR}" ${sources} ${headers} PARENT_SCOPE) +endfunction() Index: lib/tsan/CMakeLists.txt =================================================================== --- lib/tsan/CMakeLists.txt +++ lib/tsan/CMakeLists.txt @@ -120,12 +120,14 @@ CFLAGS ${TSAN_RTL_CFLAGS} LINK_FLAGS ${SANITIZER_COMMON_LINK_FLAGS} ${WEAK_SYMBOL_LINK_FLAGS} LINK_LIBS ${TSAN_LINK_LIBS} objc - PARENT_TARGET tsan) + PARENT_TARGET tsan + ADDITIONAL_HEADERS ${TSAN_HEADERS}) add_compiler_rt_object_libraries(RTTsan_dynamic OS ${TSAN_SUPPORTED_OS} ARCHS ${TSAN_SUPPORTED_ARCH} SOURCES ${TSAN_SOURCES} ${TSAN_CXX_SOURCES} ${TSAN_ASM_SOURCES} - CFLAGS ${TSAN_RTL_CFLAGS}) + CFLAGS ${TSAN_RTL_CFLAGS} + ADDITIONAL_HEADERS ${TSAN_HEADERS}) # Build and check Go runtime. set(BUILDGO_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/go/buildgo.sh) @@ -179,7 +181,8 @@ $ $ CFLAGS ${TSAN_RTL_CFLAGS} - PARENT_TARGET tsan) + PARENT_TARGET tsan + ADDITIONAL_HEADERS ${TSAN_HEADERS}) add_compiler_rt_runtime(clang_rt.tsan_cxx STATIC ARCHS ${arch}