llvm.org GIT mirror llvm / a08ee01
Refactoring CMake CrossCompile module. * put most of the cross-compiling support into a function llvm_create_cross_target_internal. * when CrossCompile is included it still generates a NATIVE target. * llvm_create_cross_target function takes a target_name which should match a toolchain. * llvm_create_cross_target can now be used to target more than one cross-compilation target. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@232067 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Bieneman 4 years ago
3 changed file(s) with 50 addition(s) and 28 deletion(s). Raw diff Collapse all Expand all
None if(NOT DEFINED LLVM_NATIVE_BUILD)
1 set(LLVM_NATIVE_BUILD "${CMAKE_BINARY_DIR}/native")
2 message(STATUS "Setting native build dir to ${LLVM_NATIVE_BUILD}")
3 endif(NOT DEFINED LLVM_NATIVE_BUILD)
0 function(llvm_create_cross_target_internal target_name toochain buildtype)
41
5 add_custom_command(OUTPUT ${LLVM_NATIVE_BUILD}
6 COMMAND ${CMAKE_COMMAND} -E make_directory ${LLVM_NATIVE_BUILD}
7 COMMENT "Creating ${LLVM_NATIVE_BUILD}...")
2 if(NOT DEFINED LLVM_${target_name}_BUILD)
3 set(LLVM_${target_name}_BUILD "${CMAKE_BINARY_DIR}/${target_name}")
4 set(LLVM_${target_name}_BUILD ${LLVM_${target_name}_BUILD} PARENT_SCOPE)
5 message(STATUS "Setting native build dir to " ${LLVM_${target_name}_BUILD})
6 endif(NOT DEFINED LLVM_${target_name}_BUILD)
87
9 add_custom_command(OUTPUT ${LLVM_NATIVE_BUILD}/CMakeCache.txt
10 COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" ${CMAKE_SOURCE_DIR}
11 WORKING_DIRECTORY ${LLVM_NATIVE_BUILD}
12 DEPENDS ${LLVM_NATIVE_BUILD}
13 COMMENT "Configuring native LLVM...")
8 if (EXISTS ${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake)
9 set(CROSS_TOOLCHAIN_FLAGS_${target_name}
10 -DCMAKE_TOOLCHAIN_FILE=\"${LLVM_MAIN_SRC_DIR}/cmake/platforms/${toolchain}.cmake\"
11 CACHE STRING "Toolchain file for ${target_name}")
12 endif()
1413
15 add_custom_target(ConfigureNativeLLVM DEPENDS ${LLVM_NATIVE_BUILD}/CMakeCache.txt)
14 add_custom_command(OUTPUT ${LLVM_${target_name}_BUILD}
15 COMMAND ${CMAKE_COMMAND} -E make_directory ${LLVM_${target_name}_BUILD}
16 COMMENT "Creating ${LLVM_${target_name}_BUILD}...")
1617
17 set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${LLVM_NATIVE_BUILD})
18 add_custom_command(OUTPUT ${LLVM_${target_name}_BUILD}/CMakeCache.txt
19 COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}"
20 ${CROSS_TOOLCHAIN_FLAGS_${target_name}} ${CMAKE_SOURCE_DIR}
21 WORKING_DIRECTORY ${LLVM_${target_name}_BUILD}
22 DEPENDS ${LLVM_${target_name}_BUILD}
23 COMMENT "Configuring ${target_name} LLVM...")
1824
19 if(NOT IS_DIRECTORY ${LLVM_NATIVE_BUILD})
20 if(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
21 set(HOST_SYSROOT_FLAGS -DCMAKE_OSX_SYSROOT=macosx)
22 endif(${CMAKE_HOST_SYSTEM_NAME} MATCHES "Darwin")
25 add_custom_target(CONFIGURE_LLVM_${target_name}
26 DEPENDS ${LLVM_${target_name}_BUILD}/CMakeCache.txt)
2327
24 message(STATUS "Configuring native build...")
25 execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory
26 ${LLVM_NATIVE_BUILD} )
28 set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES
29 ${LLVM_${target_name}_BUILD})
2730
28 message(STATUS "Configuring native targets...")
29 execute_process(COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release
30 -G "${CMAKE_GENERATOR}" -DLLVM_TARGETS_TO_BUILD=${LLVM_TARGETS_TO_BUILD} ${HOST_SYSROOT_FLAGS} ${CMAKE_SOURCE_DIR}
31 WORKING_DIRECTORY ${LLVM_NATIVE_BUILD} )
32 endif(NOT IS_DIRECTORY ${LLVM_NATIVE_BUILD})
31 if(NOT IS_DIRECTORY ${LLVM_${target_name}_BUILD})
32
33
34 message(STATUS "Configuring ${target_name} build...")
35 execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory
36 ${LLVM_${target_name}_BUILD} )
37
38 message(STATUS "Configuring ${target_name} targets...")
39 if (buildtype)
40 set(build_type_flags "-DCMAKE_BUILD_TYPE=${buildtype}")
41 endif()
42 execute_process(COMMAND ${CMAKE_COMMAND} ${build_type_flags}
43 -G "${CMAKE_GENERATOR}" -DLLVM_TARGETS_TO_BUILD=${LLVM_TARGETS_TO_BUILD}
44 ${CROSS_TOOLCHAIN_FLAGS_${target_name}} ${CMAKE_SOURCE_DIR}
45 WORKING_DIRECTORY ${LLVM_${target_name}_BUILD} )
46 endif(NOT IS_DIRECTORY ${LLVM_${target_name}_BUILD})
47
48 endfunction()
49
50 function(llvm_create_cross_target target_name sysroot)
51 llvm_create_cross_target_internal(${target_name} ${sysroot} ${CMAKE_BUILD_TYPE})
52 endfunction()
53
54 llvm_create_cross_target_internal(NATIVE "" Release)
101101 WORKING_DIRECTORY ${LLVM_NATIVE_BUILD}
102102 COMMENT "Building native TableGen...")
103103 add_custom_target(${project}NativeTableGen DEPENDS ${${project}_TABLEGEN_EXE})
104 add_dependencies(${project}NativeTableGen ConfigureNativeLLVM)
104 add_dependencies(${project}NativeTableGen CONFIGURE_LLVM_NATIVE)
105105
106106 add_dependencies(${target} ${project}NativeTableGen)
107107 endif()
4343 WORKING_DIRECTORY ${LLVM_NATIVE_BUILD}
4444 COMMENT "Building native llvm-config...")
4545 add_custom_target(${project}NativeLLVMConfig DEPENDS ${${project}_LLVM_CONFIG_EXE})
46 add_dependencies(${project}NativeLLVMConfig ConfigureNativeLLVM)
46 add_dependencies(${project}NativeLLVMConfig CONFIGURE_LLVM_NATIVE)
4747
4848 add_dependencies(llvm-config ${project}NativeLLVMConfig)
4949 endif(CMAKE_CROSSCOMPILING)