diff options
Diffstat (limited to 'cmake/Modules')
-rw-r--r-- | cmake/Modules/AddCompilerRT.cmake | 30 | ||||
-rw-r--r-- | cmake/Modules/CompilerRTUtils.cmake | 36 |
2 files changed, 62 insertions, 4 deletions
diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake index e7ec4bd28..cd4c704fc 100644 --- a/cmake/Modules/AddCompilerRT.cmake +++ b/cmake/Modules/AddCompilerRT.cmake @@ -32,9 +32,11 @@ endfunction() # SOURCES <source files> # CFLAGS <compile flags> # DEFS <compile definitions> -# DEPS <dependencies>) +# DEPS <dependencies> +# ADDITIONAL_HEADERS <header files>) 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" + ${ARGN}) set(libnames) if(APPLE) foreach(os ${LIB_OS}) @@ -55,6 +57,13 @@ function(add_compiler_rt_object_libraries name) endforeach() endif() + # Add headers to LIB_SOURCES for IDEs + compiler_rt_process_sources(LIB_SOURCES + ${LIB_SOURCES} + ADDITIONAL_HEADERS + ${LIB_ADDITIONAL_HEADERS} + ) + foreach(libname ${libnames}) add_library(${libname} OBJECT ${LIB_SOURCES}) if(LIB_DEPS) @@ -132,7 +141,8 @@ endmacro() # DEFS <compile definitions> # LINK_LIBS <linked libraries> (only for shared library) # OBJECT_LIBS <object libraries to use as sources> -# PARENT_TARGET <convenience parent target>) +# PARENT_TARGET <convenience parent target> +# ADDITIONAL_HEADERS <header files>) function(add_compiler_rt_runtime name type) if(NOT type MATCHES "^(STATIC|SHARED)$") message(FATAL_ERROR "type argument must be STATIC or SHARED") @@ -141,7 +151,7 @@ function(add_compiler_rt_runtime name type) 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" ${ARGN}) set(libnames) # Until we support this some other way, build compiler-rt runtime without LTO @@ -152,6 +162,18 @@ function(add_compiler_rt_runtime name type) 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. + compiler_rt_process_sources(LIB_SOURCES + ${LIB_SOURCES} + ADDITIONAL_HEADERS + ${LIB_ADDITIONAL_HEADERS} + ) + endif() + if(APPLE) foreach(os ${LIB_OS}) # Strip out -msse3 if this isn't macOS. diff --git a/cmake/Modules/CompilerRTUtils.cmake b/cmake/Modules/CompilerRTUtils.cmake index ea332d37d..e5651718f 100644 --- a/cmake/Modules/CompilerRTUtils.cmake +++ b/cmake/Modules/CompilerRTUtils.cmake @@ -344,3 +344,39 @@ function(get_compiler_rt_output_dir arch output_dir) set(${output_dir} ${COMPILER_RT_LIBRARY_OUTPUT_DIR} PARENT_SCOPE) endif() endfunction() + +# compiler_rt_process_sources( +# <OUTPUT_VAR> +# <SOURCE_FILE> ... +# [ADDITIONAL_HEADERS <header> ...] +# ) +# +# Process the provided sources and write the list of new sources +# into `<OUTPUT_VAR>`. +# +# ADDITIONAL_HEADERS - Adds the supplied header to 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(compiler_rt_process_sources OUTPUT_VAR) + cmake_parse_arguments( + ARG + "" + "" + "ADDITIONAL_HEADERS" + ${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}) + 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() |