summaryrefslogtreecommitdiff
path: root/cmake/Modules
diff options
context:
space:
mode:
authorChris Bieneman <beanz@apple.com>2015-08-13 20:38:16 +0000
committerChris Bieneman <beanz@apple.com>2015-08-13 20:38:16 +0000
commit19c8451a0e798abcfd1762fa8196f22b43018d2e (patch)
tree97af6f6cd847104c6cbe85e2c3e52c3bb5b0794c /cmake/Modules
parent1b93c183b00c0b29fd6e14c1ea9b8342c6417f7b (diff)
[CMake] Add experimental support for building compiler-rt for iOS
Summary: This is a reunification of three separate reviews D11073, D11082, D11083. Having them separate was not constructive even though the patches were smaller because it led to fragmented conversations, and this is really all about one change. This patch incorporates feedback from samsonov, and refactors the hacky darwin code out of the root CMakeLists.txt and int config-ix.cmake. Reviewers: zaks.anna, bogner, kubabrecka, chandlerc, samsonov Subscribers: jevinskie, filcab, llvm-commits Differential Revision: http://reviews.llvm.org/D11820 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@244948 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'cmake/Modules')
-rw-r--r--cmake/Modules/AddCompilerRT.cmake7
-rw-r--r--cmake/Modules/CompilerRTDarwinUtils.cmake79
-rw-r--r--cmake/Modules/CompilerRTUtils.cmake10
3 files changed, 94 insertions, 2 deletions
diff --git a/cmake/Modules/AddCompilerRT.cmake b/cmake/Modules/AddCompilerRT.cmake
index 3a87def8c..4a0a47577 100644
--- a/cmake/Modules/AddCompilerRT.cmake
+++ b/cmake/Modules/AddCompilerRT.cmake
@@ -19,6 +19,7 @@ function(add_compiler_rt_object_libraries name)
set(libname "${name}.${os}")
set(libnames ${libnames} ${libname})
set(extra_cflags_${libname} ${DARWIN_${os}_CFLAGS})
+ list_union(LIB_ARCHS_${libname} DARWIN_${os}_ARCHS LIB_ARCHS)
endforeach()
else()
foreach(arch ${LIB_ARCHS})
@@ -39,7 +40,8 @@ function(add_compiler_rt_object_libraries name)
set_property(TARGET ${libname} APPEND PROPERTY
COMPILE_DEFINITIONS ${LIB_DEFS})
if(APPLE)
- set_target_properties(${libname} PROPERTIES OSX_ARCHITECTURES "${LIB_ARCHS}")
+ set_target_properties(${libname} PROPERTIES
+ OSX_ARCHITECTURES "${LIB_ARCHS_${libname}}")
endif()
endforeach()
endfunction()
@@ -118,8 +120,9 @@ macro(add_compiler_rt_darwin_dynamic_runtime name os)
set_target_link_flags(${name} ${LIB_LINKFLAGS} ${DARWIN_${os}_LINKFLAGS})
set_property(TARGET ${name} APPEND PROPERTY
COMPILE_DEFINITIONS ${LIB_DEFS})
+ list_union(filtered_arches DARWIN_${os}_ARCHS LIB_ARCHS)
set_target_properties(${name} PROPERTIES
- OSX_ARCHITECTURES "${LIB_ARCHS}"
+ OSX_ARCHITECTURES "${filtered_arches}"
LIBRARY_OUTPUT_DIRECTORY ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
install(TARGETS ${name}
LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
diff --git a/cmake/Modules/CompilerRTDarwinUtils.cmake b/cmake/Modules/CompilerRTDarwinUtils.cmake
new file mode 100644
index 000000000..36191f463
--- /dev/null
+++ b/cmake/Modules/CompilerRTDarwinUtils.cmake
@@ -0,0 +1,79 @@
+# On OS X SDKs can be installed anywhere on the base system and xcode-select can
+# set the default Xcode to use. This function finds the SDKs that are present in
+# the current Xcode.
+function(find_darwin_sdk_dir var sdk_name)
+ # Let's first try the internal SDK, otherwise use the public SDK.
+ execute_process(
+ COMMAND xcodebuild -version -sdk ${sdk_name}.internal Path
+ OUTPUT_VARIABLE var_internal
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_FILE /dev/null
+ )
+ if("" STREQUAL "${var_internal}")
+ execute_process(
+ COMMAND xcodebuild -version -sdk ${sdk_name} Path
+ OUTPUT_VARIABLE var_internal
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_FILE /dev/null
+ )
+ endif()
+ set(${var} ${var_internal} PARENT_SCOPE)
+endfunction()
+
+# There isn't a clear mapping of what architectures are supported with a given
+# target platform, but ld's version output does list the architectures it can
+# link for.
+function(darwin_get_toolchain_supported_archs output_var)
+ execute_process(
+ COMMAND ld -v
+ ERROR_VARIABLE LINKER_VERSION)
+
+ string(REGEX MATCH "configured to support archs: ([^\n]+)"
+ ARCHES_MATCHED "${LINKER_VERSION}")
+ if(ARCHES_MATCHED)
+ set(ARCHES "${CMAKE_MATCH_1}")
+ message("Matched ARCHES: ${ARCHES}")
+ string(REPLACE " " ";" ARCHES ${ARCHES})
+ else()
+ # If auto-detecting fails, fall back to a default set
+ message(WARNING "Detecting supported architectures from 'ld -v' failed. Returning default set.")
+ set(ARCHES "i386;x86_64;armv7;armv7s;arm64")
+ endif()
+
+ set(${output_var} ${ARCHES} PARENT_SCOPE)
+endfunction()
+
+# This function takes an OS and a list of architectures and identifies the
+# subset of the architectures list that the installed toolchain can target.
+function(darwin_test_archs os valid_archs)
+ set(archs ${ARGN})
+ message(STATUS "Finding valid architectures for ${os}...")
+ set(SIMPLE_CPP ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/src.cpp)
+ file(WRITE ${SIMPLE_CPP} "#include <iostream>\nint main() { return 0; }\n")
+
+ set(os_linker_flags)
+ foreach(flag ${DARWIN_${os}_LINKFLAGS})
+ set(os_linker_flags "${os_linker_flags} ${flag}")
+ endforeach()
+
+ # The simple program will build for x86_64h on the simulator because it is
+ # compatible with x86_64 libraries (mostly), but since x86_64h isn't actually
+ # a valid or useful architecture for the iOS simulator we should drop it.
+ if(${os} STREQUAL "iossim")
+ list(REMOVE_ITEM archs "x86_64h")
+ endif()
+
+ set(working_archs)
+ foreach(arch ${archs})
+
+ set(arch_linker_flags "-arch ${arch} ${os_linker_flags}")
+ try_compile(CAN_TARGET_${os}_${arch} ${CMAKE_BINARY_DIR} ${SIMPLE_CPP}
+ COMPILE_DEFINITIONS "-v -arch ${arch}" ${DARWIN_${os}_CFLAGS}
+ CMAKE_FLAGS "-DCMAKE_EXE_LINKER_FLAGS=${arch_linker_flags}"
+ OUTPUT_VARIABLE TEST_OUTPUT)
+ if(${CAN_TARGET_${os}_${arch}})
+ list(APPEND working_archs ${arch})
+ endif()
+ endforeach()
+ set(${valid_archs} ${working_archs} PARENT_SCOPE)
+endfunction()
diff --git a/cmake/Modules/CompilerRTUtils.cmake b/cmake/Modules/CompilerRTUtils.cmake
index f7f60a4ac..cf690f4a3 100644
--- a/cmake/Modules/CompilerRTUtils.cmake
+++ b/cmake/Modules/CompilerRTUtils.cmake
@@ -57,3 +57,13 @@ macro(append_have_file_definition filename varname list)
endif()
list(APPEND ${list} "${varname}=${${varname}}")
endmacro()
+
+macro(list_union output input1 input2)
+ set(${output})
+ foreach(it ${${input1}})
+ list(FIND ${input2} ${it} index)
+ if( NOT (index EQUAL -1))
+ list(APPEND ${output} ${it})
+ endif()
+ endforeach()
+endmacro()