diff options
Diffstat (limited to 'cmake/Modules/AddCompilerRT.cmake')
| -rw-r--r-- | cmake/Modules/AddCompilerRT.cmake | 93 | 
1 files changed, 50 insertions, 43 deletions
diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake index a7782a1948478..5ea313ba71620 100644 --- a/cmake/Modules/AddCompilerRT.cmake +++ b/cmake/Modules/AddCompilerRT.cmake @@ -1,42 +1,48 @@  include(AddLLVM)  include(ExternalProject) -include(LLVMParseArguments)  include(CompilerRTUtils) -# Tries to add "object library" target for a given architecture -# with name "<name>.<arch>" if architecture can be targeted. -# add_compiler_rt_object_library(<name> <arch> -#                                SOURCES <source files> -#                                CFLAGS <compile flags> -#                                DEFS <compile definitions>) -macro(add_compiler_rt_object_library name arch) -  if(CAN_TARGET_${arch}) -    parse_arguments(LIB "SOURCES;CFLAGS;DEFS" "" ${ARGN}) -    add_library(${name}.${arch} OBJECT ${LIB_SOURCES}) -    set_target_compile_flags(${name}.${arch} -      ${CMAKE_CXX_FLAGS} ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS}) -    set_property(TARGET ${name}.${arch} APPEND PROPERTY -      COMPILE_DEFINITIONS ${LIB_DEFS}) +# Tries to add an "object library" target for a given list of OSs and/or +# architectures with name "<name>.<arch>" for non-Darwin platforms if +# architecture can be targeted, and "<name>.<os>" for Darwin platforms. +# add_compiler_rt_object_libraries(<name> +#                                  OS <os names> +#                                  ARCHS <architectures> +#                                  SOURCES <source files> +#                                  CFLAGS <compile flags> +#                                  DEFS <compile definitions>) +function(add_compiler_rt_object_libraries name) +  cmake_parse_arguments(LIB "" "" "OS;ARCHS;SOURCES;CFLAGS;DEFS" ${ARGN}) +  set(libnames) +  if(APPLE) +    foreach(os ${LIB_OS}) +      set(libname "${name}.${os}") +      set(libnames ${libnames} ${libname}) +      set(extra_cflags_${libname} ${DARWIN_${os}_CFLAGS}) +    endforeach()    else() -    message(FATAL_ERROR "Archtecture ${arch} can't be targeted") +    foreach(arch ${LIB_ARCHS}) +      set(libname "${name}.${arch}") +      set(libnames ${libnames} ${libname}) +      set(extra_cflags_${libname} ${TARGET_${arch}_CFLAGS}) +      if(NOT CAN_TARGET_${arch}) +        message(FATAL_ERROR "Archtecture ${arch} can't be targeted") +        return() +      endif() +    endforeach()    endif() -endmacro() - -# Same as above, but adds universal osx library for either OSX or iOS simulator -# with name "<name>.<os>" targeting multiple architectures. -# add_compiler_rt_darwin_object_library(<name> <os> ARCH <architectures> -#                                                   SOURCES <source files> -#                                                   CFLAGS <compile flags> -#                                                   DEFS <compile definitions>) -macro(add_compiler_rt_darwin_object_library name os) -  parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS" "" ${ARGN}) -  set(libname "${name}.${os}") -  add_library(${libname} OBJECT ${LIB_SOURCES}) -  set_target_compile_flags(${libname} ${LIB_CFLAGS} ${DARWIN_${os}_CFLAGS}) -  set_target_properties(${libname} PROPERTIES OSX_ARCHITECTURES "${LIB_ARCH}") -  set_property(TARGET ${libname} APPEND PROPERTY -    COMPILE_DEFINITIONS ${LIB_DEFS}) -endmacro() +   +  foreach(libname ${libnames}) +    add_library(${libname} OBJECT ${LIB_SOURCES}) +    set_target_compile_flags(${libname} +      ${CMAKE_CXX_FLAGS} ${extra_cflags_${libname}} ${LIB_CFLAGS}) +    set_property(TARGET ${libname} APPEND PROPERTY +      COMPILE_DEFINITIONS ${LIB_DEFS}) +    if(APPLE) +      set_target_properties(${libname} PROPERTIES OSX_ARCHITECTURES "${LIB_ARCHS}") +    endif() +  endforeach() +endfunction()  # Adds static or shared runtime for a given architecture and puts it in the  # proper directory in the build and install trees. @@ -47,13 +53,13 @@ endmacro()  #                         OUTPUT_NAME <output library name>)  macro(add_compiler_rt_runtime name arch type)    if(CAN_TARGET_${arch}) -    parse_arguments(LIB "SOURCES;CFLAGS;DEFS;OUTPUT_NAME" "" ${ARGN}) +    cmake_parse_arguments(LIB "" "OUTPUT_NAME" "SOURCES;CFLAGS;LINKFLAGS;DEFS" ${ARGN})      add_library(${name} ${type} ${LIB_SOURCES})      # Setup compile flags and definitions.      set_target_compile_flags(${name}        ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS})      set_target_link_flags(${name} -      ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS}) +      ${TARGET_${arch}_CFLAGS} ${LIB_CFLAGS} ${LIB_LINKFLAGS})      set_property(TARGET ${name} APPEND PROPERTY        COMPILE_DEFINITIONS ${LIB_DEFS})      # Setup correct output directory in the build tree. @@ -80,18 +86,18 @@ endmacro()  # Same as add_compiler_rt_runtime(... STATIC), but creates a universal library  # for several architectures. -# add_compiler_rt_osx_static_runtime(<name> ARCH <architectures> +# add_compiler_rt_osx_static_runtime(<name> ARCHS <architectures>  #                                    SOURCES <source files>  #                                    CFLAGS <compile flags>  #                                    DEFS <compile definitions>)  macro(add_compiler_rt_osx_static_runtime name) -  parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS" "" ${ARGN}) +  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_ARCH}" +    OSX_ARCHITECTURES "${LIB_ARCHS}"      ARCHIVE_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})    install(TARGETS ${name}      ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) @@ -100,20 +106,20 @@ endmacro()  # Adds dynamic runtime library on osx/iossim, which supports multiple  # architectures.  # add_compiler_rt_darwin_dynamic_runtime(<name> <os> -#                                        ARCH <architectures> +#                                        ARCHS <architectures>  #                                        SOURCES <source files>  #                                        CFLAGS <compile flags>  #                                        DEFS <compile definitions>  #                                        LINKFLAGS <link flags>)  macro(add_compiler_rt_darwin_dynamic_runtime name os) -  parse_arguments(LIB "ARCH;SOURCES;CFLAGS;DEFS;LINKFLAGS" "" ${ARGN}) +  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})    set_target_properties(${name} PROPERTIES -    OSX_ARCHITECTURES "${LIB_ARCH}" +    OSX_ARCHITECTURES "${LIB_ARCHS}"      LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})    install(TARGETS ${name}      LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) @@ -162,7 +168,7 @@ endif()  #                      DEPS <deps (e.g. runtime libs)>  #                      LINK_FLAGS <link flags>)  macro(add_compiler_rt_test test_suite test_name) -  parse_arguments(TEST "SUBDIR;OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN}) +  cmake_parse_arguments(TEST "" "SUBDIR" "OBJECTS;DEPS;LINK_FLAGS" "" ${ARGN})    if(TEST_SUBDIR)      set(output_bin "${CMAKE_CURRENT_BINARY_DIR}/${TEST_SUBDIR}/${test_name}")    else() @@ -229,7 +235,7 @@ macro(add_custom_libcxx name prefix)      message(FATAL_ERROR "libcxx not found!")    endif() -  parse_arguments(LIBCXX "DEPS;CFLAGS" "" ${ARGN}) +  cmake_parse_arguments(LIBCXX "" "" "DEPS;CFLAGS" ${ARGN})    foreach(flag ${LIBCXX_CFLAGS})      set(flagstr "${flagstr} ${flag}")    endforeach() @@ -252,6 +258,7 @@ macro(add_custom_libcxx name prefix)      LOG_CONFIGURE 1      LOG_INSTALL 1      ) +  set_target_properties(${name} PROPERTIES EXCLUDE_FROM_ALL TRUE)    ExternalProject_Add_Step(${name} force-reconfigure      DEPENDERS configure  | 
