Index: cmake/Modules/AddCompilerRT.cmake =================================================================== --- cmake/Modules/AddCompilerRT.cmake +++ cmake/Modules/AddCompilerRT.cmake @@ -86,47 +86,45 @@ endif() endmacro() -# Same as add_compiler_rt_runtime(... STATIC), but creates a universal library -# for several architectures. -# add_compiler_rt_osx_static_runtime( ARCHS -# SOURCES -# CFLAGS -# DEFS ) -macro(add_compiler_rt_osx_static_runtime name) - cmake_parse_arguments(LIB "" "" "ARCHS;SOURCES;CFLAGS;DEFS" ${ARGN}) - add_library(${name} STATIC ${LIB_SOURCES}) - set_target_compile_flags(${name} ${LIB_CFLAGS}) - set_property(TARGET ${name} APPEND PROPERTY - COMPILE_DEFINITIONS ${LIB_DEFS}) - set_target_properties(${name} PROPERTIES - OSX_ARCHITECTURES "${LIB_ARCHS}" - ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) - install(TARGETS ${name} - ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) -endmacro() - -# Adds dynamic runtime library on osx/iossim, which supports multiple +# Adds runtime library for darwin platforms, which supports multiple # architectures. -# add_compiler_rt_darwin_dynamic_runtime( -# ARCHS -# SOURCES -# CFLAGS -# DEFS -# LINKFLAGS ) -macro(add_compiler_rt_darwin_dynamic_runtime name os) - cmake_parse_arguments(LIB "" "" "ARCHS;SOURCES;CFLAGS;DEFS;LINKFLAGS" ${ARGN}) - add_library(${name} SHARED ${LIB_SOURCES}) - set_target_compile_flags(${name} ${LIB_CFLAGS} ${DARWIN_${os}_CFLAGS}) - set_target_link_flags(${name} ${LIB_LINKFLAGS} ${DARWIN_${os}_LINKFLAGS}) - set_property(TARGET ${name} APPEND PROPERTY - COMPILE_DEFINITIONS ${LIB_DEFS}) +# add_compiler_rt_darwin_runtime( +# STATIC|SHARED +# ARCHS +# SOURCES +# CFLAGS +# DEFS +# LINKFLAGS ) +function(add_compiler_rt_darwin_runtime name os) + cmake_parse_arguments(LIB "SHARED;STATIC" "" "ARCHS;SOURCES;CFLAGS;DEFS;LINKFLAGS" ${ARGN}) list_union(filtered_arches DARWIN_${os}_ARCHS LIB_ARCHS) - set_target_properties(${name} PROPERTIES - OSX_ARCHITECTURES "${filtered_arches}" - LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) - install(TARGETS ${name} - LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) -endmacro() + # if there are no supported architectures, don't create the library + if(filtered_arches) + if(LIB_SHARED) + add_library(${name} SHARED ${LIB_SOURCES}) + set_target_properties(${name} PROPERTIES + LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) + install(TARGETS ${name} + LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) + elseif(LIB_STATIC) + add_library(${name} STATIC ${LIB_SOURCES}) + set_target_properties(${name} PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR}) + install(TARGETS ${name} + ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) + else() + message(FATAL_ERROR "Must specified SHARED|STATIC to add_compiler_rt_darwin_runtime") + endif() + + set_target_compile_flags(${name} ${LIB_CFLAGS} ${DARWIN_${os}_CFLAGS}) + set_target_link_flags(${name} ${LIB_LINKFLAGS} ${DARWIN_${os}_LINKFLAGS}) + set_property(TARGET ${name} APPEND PROPERTY + COMPILE_DEFINITIONS ${LIB_DEFS}) + + set_target_properties(${name} PROPERTIES + OSX_ARCHITECTURES "${filtered_arches}") + endif() +endfunction() set(COMPILER_RT_TEST_CFLAGS) Index: lib/asan/CMakeLists.txt =================================================================== --- lib/asan/CMakeLists.txt +++ lib/asan/CMakeLists.txt @@ -111,7 +111,8 @@ add_custom_target(asan) if(APPLE) foreach (os ${SANITIZER_COMMON_SUPPORTED_OS}) - add_compiler_rt_darwin_dynamic_runtime(clang_rt.asan_${os}_dynamic ${os} + add_compiler_rt_darwin_runtime(clang_rt.asan_${os}_dynamic ${os} + SHARED ARCHS ${ASAN_SUPPORTED_ARCH} SOURCES $ $ Index: lib/profile/CMakeLists.txt =================================================================== --- lib/profile/CMakeLists.txt +++ lib/profile/CMakeLists.txt @@ -11,10 +11,13 @@ InstrProfilingUtil.c) if(APPLE) - add_compiler_rt_osx_static_runtime(clang_rt.profile_osx - ARCHS ${PROFILE_SUPPORTED_ARCH} - SOURCES ${PROFILE_SOURCES}) - add_dependencies(profile clang_rt.profile_osx) + foreach (os ${SANITIZER_COMMON_SUPPORTED_OS}) + add_compiler_rt_darwin_runtime(clang_rt.profile_${os} ${os} + STATIC + ARCHS ${PROFILE_SUPPORTED_ARCH} + SOURCES ${PROFILE_SOURCES}) + add_dependencies(profile clang_rt.profile_${os}) + endforeach() else() foreach(arch ${PROFILE_SUPPORTED_ARCH}) add_compiler_rt_runtime(clang_rt.profile-${arch} ${arch} STATIC Index: lib/safestack/CMakeLists.txt =================================================================== --- lib/safestack/CMakeLists.txt +++ lib/safestack/CMakeLists.txt @@ -8,13 +8,16 @@ if(APPLE) # Build universal binary on APPLE. - add_compiler_rt_osx_static_runtime(clang_rt.safestack_osx - ARCH ${SAFESTACK_SUPPORTED_ARCH} - SOURCES ${SAFESTACK_SOURCES} - $ - $ - CFLAGS ${SAFESTACK_CFLAGS}) - add_dependencies(safestack clang_rt.safestack_osx) + foreach (os ${SANITIZER_COMMON_SUPPORTED_OS}) + add_compiler_rt_darwin_runtime(clang_rt.safestack_${os} ${os} + STATIC + ARCH ${SAFESTACK_SUPPORTED_ARCH} + SOURCES ${SAFESTACK_SOURCES} + $ + $ + CFLAGS ${SAFESTACK_CFLAGS}) + add_dependencies(safestack clang_rt.safestack_${os}) + endforeach() else() # Otherwise, build separate libraries for each target. foreach(arch ${SAFESTACK_SUPPORTED_ARCH}) Index: lib/ubsan/CMakeLists.txt =================================================================== --- lib/ubsan/CMakeLists.txt +++ lib/ubsan/CMakeLists.txt @@ -50,7 +50,8 @@ SOURCES ${UBSAN_STANDALONE_SOURCES} CFLAGS ${UBSAN_STANDALONE_CFLAGS}) foreach(os ${SANITIZER_COMMON_SUPPORTED_OS}) - add_compiler_rt_darwin_dynamic_runtime(clang_rt.ubsan_${os}_dynamic ${os} + add_compiler_rt_darwin_runtime(clang_rt.ubsan_${os}_dynamic ${os} + SHARED ARCHS ${UBSAN_SUPPORTED_ARCH} SOURCES $ $