Clang] Fix expansion of response files in -Wp after integrated-cc1 change
[llvm-project.git] / llvm / tools / llvm-config / CMakeLists.txt
blob16ba54c0cf2fcaaf7296724a289b5cf7d35301c6
1 set(LLVM_LINK_COMPONENTS support)
3 set(BUILDVARIABLES_SRCPATH ${CMAKE_CURRENT_SOURCE_DIR}/BuildVariables.inc.in)
4 set(BUILDVARIABLES_OBJPATH ${CMAKE_CURRENT_BINARY_DIR}/BuildVariables.inc)
6 # Add the llvm-config tool.
7 add_llvm_tool(llvm-config
8   llvm-config.cpp
9   )
11 # Compute the substitution values for various items.
12 get_property(SUPPORT_SYSTEM_LIBS TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS)
13 get_property(WINDOWSMANIFEST_SYSTEM_LIBS TARGET LLVMWindowsManifest PROPERTY LLVM_SYSTEM_LIBS)
14 foreach(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       if(IS_ABSOLUTE ${l})
24         set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}")
25       else()
26         set(SYSTEM_LIBS ${SYSTEM_LIBS} "-l${l}")
27       endif()
28     endif()
29   endif()
30 endforeach()
31 string(REPLACE ";" " " SYSTEM_LIBS "${SYSTEM_LIBS}")
33 # Fetch target specific compile options, e.g. RTTI option
34 get_property(COMPILE_FLAGS TARGET llvm-config PROPERTY COMPILE_FLAGS)
36 # NOTE: We don't want to start extracting any random C/CXX flags that the
37 # user may add that could affect the ABI.  We only want to extract flags
38 # that have been added by the LLVM build system.
39 string(REGEX MATCH "-stdlib=[^ ]+" LLVM_CXX_STDLIB_FLAG ${CMAKE_CXX_FLAGS})
40 string(REGEX MATCH "-std=[^ ]+" LLVM_C_STD_FLAG ${CMAKE_C_FLAGS})
42 # Use configure_file to create BuildVariables.inc.
43 set(LLVM_SRC_ROOT ${LLVM_MAIN_SRC_DIR})
44 set(LLVM_OBJ_ROOT ${LLVM_BINARY_DIR})
45 set(LLVM_CPPFLAGS "${LLVM_DEFINITIONS}")
46 set(LLVM_CFLAGS "${LLVM_C_STD_FLAG} ${LLVM_DEFINITIONS}")
47 # The language standard potentially affects the ABI/API of LLVM, so we want
48 # to make sure it is reported by llvm-config.
49 set(LLVM_CXXFLAGS "${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION} ${LLVM_CXX_STDLIB_FLAG} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")
50 set(LLVM_BUILD_SYSTEM cmake)
51 set(LLVM_HAS_RTTI ${LLVM_CONFIG_HAS_RTTI})
52 set(LLVM_DYLIB_VERSION "${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX}")
53 set(LLVM_HAS_GLOBAL_ISEL "ON")
55 # Use the C++ link flags, since they should be a superset of C link flags.
56 set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}")
57 set(LLVM_BUILDMODE ${CMAKE_BUILD_TYPE})
58 set(LLVM_SYSTEM_LIBS ${SYSTEM_LIBS})
59 string(REPLACE ";" " " LLVM_TARGETS_BUILT "${LLVM_TARGETS_TO_BUILD}")
60 llvm_canonicalize_cmake_booleans(
61   LLVM_BUILD_LLVM_DYLIB
62   LLVM_LINK_LLVM_DYLIB
63   LLVM_HAS_RTTI
64   LLVM_HAS_GLOBAL_ISEL
65   BUILD_SHARED_LIBS)
66 llvm_expand_pseudo_components(LLVM_DYLIB_COMPONENTS_expanded "${LLVM_DYLIB_COMPONENTS}")
67 configure_file(${BUILDVARIABLES_SRCPATH} ${BUILDVARIABLES_OBJPATH} @ONLY)
69 # Set build-time environment(s).
70 add_definitions(-DCMAKE_CFG_INTDIR="${CMAKE_CFG_INTDIR}")
72 if(LLVM_ENABLE_MODULES)
73   target_compile_options(llvm-config PUBLIC
74     "-fmodules-ignore-macro=CMAKE_CFG_INTDIR"
75     )
76 endif()
78 # Add the dependency on the generation step.
79 add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.cpp ${BUILDVARIABLES_OBJPATH})
81 if(CMAKE_CROSSCOMPILING AND NOT LLVM_CONFIG_PATH)
82   build_native_tool(llvm-config LLVM_CONFIG_PATH)
83   set(LLVM_CONFIG_PATH "${LLVM_CONFIG_PATH}" CACHE STRING "")
85   add_custom_target(NativeLLVMConfig DEPENDS ${LLVM_CONFIG_PATH})
86   add_dependencies(llvm-config NativeLLVMConfig)
87 endif()