1function(llvm_create_cross_target_internal target_name toochain buildtype) 2 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) 8 9 if (EXISTS ${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake) 10 set(CROSS_TOOLCHAIN_FLAGS_${target_name} 11 -DCMAKE_TOOLCHAIN_FILE=\"${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake\" 12 CACHE STRING "Toolchain file for ${target_name}") 13 endif() 14 15 add_custom_command(OUTPUT ${LLVM_${target_name}_BUILD} 16 COMMAND ${CMAKE_COMMAND} -E make_directory ${LLVM_${target_name}_BUILD} 17 COMMENT "Creating ${LLVM_${target_name}_BUILD}...") 18 19 add_custom_command(OUTPUT ${LLVM_${target_name}_BUILD}/CMakeCache.txt 20 COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" 21 ${CROSS_TOOLCHAIN_FLAGS_${target_name}} ${CMAKE_SOURCE_DIR} 22 -DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE 23 WORKING_DIRECTORY ${LLVM_${target_name}_BUILD} 24 DEPENDS ${LLVM_${target_name}_BUILD} 25 COMMENT "Configuring ${target_name} LLVM...") 26 27 add_custom_target(CONFIGURE_LLVM_${target_name} 28 DEPENDS ${LLVM_${target_name}_BUILD}/CMakeCache.txt) 29 30 set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES 31 ${LLVM_${target_name}_BUILD}) 32 33 if(NOT IS_DIRECTORY ${LLVM_${target_name}_BUILD}) 34 35 36 message(STATUS "Configuring ${target_name} build...") 37 execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory 38 ${LLVM_${target_name}_BUILD} ) 39 40 message(STATUS "Configuring ${target_name} targets...") 41 if (buildtype) 42 set(build_type_flags "-DCMAKE_BUILD_TYPE=${buildtype}") 43 endif() 44 execute_process(COMMAND ${CMAKE_COMMAND} ${build_type_flags} 45 -G "${CMAKE_GENERATOR}" -DLLVM_TARGETS_TO_BUILD=${LLVM_TARGETS_TO_BUILD} 46 ${CROSS_TOOLCHAIN_FLAGS_${target_name}} ${CMAKE_SOURCE_DIR} 47 -DLLVM_TARGET_IS_CROSSCOMPILE_HOST=TRUE 48 WORKING_DIRECTORY ${LLVM_${target_name}_BUILD} ) 49 endif(NOT IS_DIRECTORY ${LLVM_${target_name}_BUILD}) 50 51endfunction() 52 53function(llvm_create_cross_target target_name sysroot) 54 llvm_create_cross_target_internal(${target_name} ${sysroot} ${CMAKE_BUILD_TYPE}) 55endfunction() 56 57llvm_create_cross_target_internal(NATIVE "" Release) 58