[CodeGenPrepare] Handle all debug calls in dupRetToEnableTailCallOpts()
[llvm-complete.git] / cmake / modules / CrossCompile.cmake
blobb239816c8253928446e2d4bcf9fe205433211dd5
1 function(llvm_create_cross_target_internal target_name toolchain buildtype)
3   if(NOT DEFINED LLVM_${target_name}_BUILD)
4     set(LLVM_${target_name}_BUILD "${CMAKE_BINARY_DIR}/${target_name}")
5     set(LLVM_${target_name}_BUILD ${LLVM_${target_name}_BUILD} PARENT_SCOPE)
6     message(STATUS "Setting native build dir to " ${LLVM_${target_name}_BUILD})
7   endif(NOT DEFINED LLVM_${target_name}_BUILD)
9   if (EXISTS ${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake)
10     set(CROSS_TOOLCHAIN_FLAGS_INIT
11       -DCMAKE_TOOLCHAIN_FILE=\"${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake\")
12   else()
13     set(CROSS_TOOLCHAIN_FLAGS_INIT
14       -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
15       -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
16       )
17   endif()
18   set(CROSS_TOOLCHAIN_FLAGS_${target_name} ${CROSS_TOOLCHAIN_FLAGS_INIT}
19     CACHE STRING "Toolchain configuration for ${target_name}")
21   if (buildtype)
22     set(build_type_flags "-DCMAKE_BUILD_TYPE=${buildtype}")
23   endif()
24   if (LLVM_USE_LINKER AND NOT CMAKE_CROSSCOMPILING)
25     set(linker_flag "-DLLVM_USE_LINKER=${LLVM_USE_LINKER}")
26   endif()
27   if (LLVM_EXTERNAL_CLANG_SOURCE_DIR)
28     # Propagate LLVM_EXTERNAL_CLANG_SOURCE_DIR so that clang-tblgen can be built
29     set(external_clang_dir "-DLLVM_EXTERNAL_CLANG_SOURCE_DIR=${LLVM_EXTERNAL_CLANG_SOURCE_DIR}")
30   endif()
32   add_custom_command(OUTPUT ${LLVM_${target_name}_BUILD}
33     COMMAND ${CMAKE_COMMAND} -E make_directory ${LLVM_${target_name}_BUILD}
34     COMMENT "Creating ${LLVM_${target_name}_BUILD}...")
36   add_custom_target(CREATE_LLVM_${target_name}
37                     DEPENDS ${LLVM_${target_name}_BUILD})
39   # Escape semicolons in the targets list so that cmake doesn't expand
40   # them to spaces.
41   string(REPLACE ";" "$<SEMICOLON>" targets_to_build_arg
42          "${LLVM_TARGETS_TO_BUILD}")
43   string(REPLACE ";" "$<SEMICOLON>" experimental_targets_to_build_arg
44          "${LLVM_EXPERIMENTAL_TARGETS_TO_BUILD}")
46   add_custom_command(OUTPUT ${LLVM_${target_name}_BUILD}/CMakeCache.txt
47     COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
48         -DCMAKE_MAKE_PROGRAM="${CMAKE_MAKE_PROGRAM}"
49         ${CROSS_TOOLCHAIN_FLAGS_${target_name}} ${CMAKE_SOURCE_DIR}
50         -DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE
51         -DLLVM_TARGETS_TO_BUILD="${targets_to_build_arg}"
52         -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="${experimental_targets_to_build_arg}"
53         -DLLVM_DEFAULT_TARGET_TRIPLE="${TARGET_TRIPLE}"
54         -DLLVM_TARGET_ARCH="${LLVM_TARGET_ARCH}"
55         ${build_type_flags} ${linker_flag} ${external_clang_dir}
56     WORKING_DIRECTORY ${LLVM_${target_name}_BUILD}
57     DEPENDS CREATE_LLVM_${target_name}
58     COMMENT "Configuring ${target_name} LLVM...")
60   add_custom_target(CONFIGURE_LLVM_${target_name}
61                     DEPENDS ${LLVM_${target_name}_BUILD}/CMakeCache.txt)
63 endfunction()
65 function(llvm_create_cross_target target_name sysroot)
66   llvm_create_cross_target_internal(${target_name} ${sysroot} ${CMAKE_BUILD_TYPE})
67 endfunction()
69 llvm_create_cross_target_internal(NATIVE "" Release)