1set(LLVM_LINK_COMPONENTS support) 2 3set(BUILDVARIABLES_SRCPATH ${CMAKE_CURRENT_SOURCE_DIR}/BuildVariables.inc.in) 4set(BUILDVARIABLES_OBJPATH ${CMAKE_CURRENT_BINARY_DIR}/BuildVariables.inc) 5 6# Add the llvm-config tool. 7add_llvm_tool(llvm-config 8 llvm-config.cpp 9 ) 10 11# Compute the substitution values for various items. 12get_property(SUPPORT_SYSTEM_LIBS TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS) 13get_property(WINDOWSMANIFEST_SYSTEM_LIBS TARGET LLVMWindowsManifest PROPERTY LLVM_SYSTEM_LIBS) 14foreach(l ${SUPPORT_SYSTEM_LIBS} ${WINDOWSMANIFEST_SYSTEM_LIBS}) 15 if(MSVC) 16 set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}.lib") 17 else() 18 if (l MATCHES "^-") 19 # If it's an option, pass it without changes. 20 set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}") 21 else() 22 # Otherwise assume it's a library name we need to link with. 23 set(SYSTEM_LIBS ${SYSTEM_LIBS} "-l${l}") 24 endif() 25 endif() 26endforeach() 27string(REPLACE ";" " " SYSTEM_LIBS "${SYSTEM_LIBS}") 28 29# Fetch target specific compile options, e.g. RTTI option 30get_property(COMPILE_FLAGS TARGET llvm-config PROPERTY COMPILE_FLAGS) 31 32# Use configure_file to create BuildVariables.inc. 33set(LLVM_SRC_ROOT ${LLVM_MAIN_SRC_DIR}) 34set(LLVM_OBJ_ROOT ${LLVM_BINARY_DIR}) 35set(LLVM_CPPFLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_CPP_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}") 36set(LLVM_CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${LLVM_DEFINITIONS}") 37set(LLVM_CXXFLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${uppercase_CMAKE_BUILD_TYPE}} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}") 38set(LLVM_BUILD_SYSTEM cmake) 39set(LLVM_HAS_RTTI ${LLVM_CONFIG_HAS_RTTI}) 40set(LLVM_DYLIB_VERSION "${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX}") 41set(LLVM_HAS_GLOBAL_ISEL "ON") 42 43# Use the C++ link flags, since they should be a superset of C link flags. 44set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}") 45set(LLVM_BUILDMODE ${CMAKE_BUILD_TYPE}) 46set(LLVM_SYSTEM_LIBS ${SYSTEM_LIBS}) 47string(REPLACE ";" " " LLVM_TARGETS_BUILT "${LLVM_TARGETS_TO_BUILD}") 48llvm_canonicalize_cmake_booleans( 49 LLVM_BUILD_LLVM_DYLIB 50 LLVM_LINK_LLVM_DYLIB 51 LLVM_HAS_RTTI 52 LLVM_HAS_GLOBAL_ISEL 53 BUILD_SHARED_LIBS) 54configure_file(${BUILDVARIABLES_SRCPATH} ${BUILDVARIABLES_OBJPATH} @ONLY) 55 56# Set build-time environment(s). 57add_definitions(-DCMAKE_CFG_INTDIR="${CMAKE_CFG_INTDIR}") 58 59if(LLVM_ENABLE_MODULES) 60 target_compile_options(llvm-config PUBLIC 61 "-fmodules-ignore-macro=CMAKE_CFG_INTDIR" 62 ) 63endif() 64 65# Add the dependency on the generation step. 66add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.cpp ${BUILDVARIABLES_OBJPATH}) 67 68if(CMAKE_CROSSCOMPILING AND NOT LLVM_CONFIG_PATH) 69 set(LLVM_CONFIG_PATH "${LLVM_NATIVE_BUILD}/bin/llvm-config" CACHE STRING "") 70 71 add_custom_command(OUTPUT "${LLVM_CONFIG_PATH}" 72 COMMAND ${CMAKE_COMMAND} --build . --target llvm-config --config $<CONFIGURATION> 73 DEPENDS ${LLVM_NATIVE_BUILD}/CMakeCache.txt 74 WORKING_DIRECTORY ${LLVM_NATIVE_BUILD} 75 COMMENT "Building native llvm-config..." 76 USES_TERMINAL) 77 add_custom_target(NativeLLVMConfig DEPENDS ${LLVM_CONFIG_PATH}) 78 add_dependencies(NativeLLVMConfig CONFIGURE_LLVM_NATIVE) 79 80 add_dependencies(llvm-config NativeLLVMConfig) 81endif() 82