llvm-config: Include -stdlib= in --cxxflags
[llvm-project.git] / llvm / tools / llvm-config / CMakeLists.txt
blobfc3dbaa9639024845f604de65c369d16238b1118
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       set(SYSTEM_LIBS ${SYSTEM_LIBS} "-l${l}")
24     endif()
25   endif()
26 endforeach()
27 string(REPLACE ";" " " SYSTEM_LIBS "${SYSTEM_LIBS}")
29 # Fetch target specific compile options, e.g. RTTI option
30 get_property(COMPILE_FLAGS TARGET llvm-config PROPERTY COMPILE_FLAGS)
32 # The language standard potentially affects the ABI/API of LLVM, so we want
33 # to make sure it is reported by llvm-config.
34 # NOTE: We don't want to start extracting any random C/CXX flags that the
35 # user may add that could affect the ABI.  We only want to extract flags
36 # that have been added by the LLVM build system.
37 string(REGEX MATCH "-std=[^ ]\+" LLVM_CXX_STD_FLAG ${CMAKE_CXX_FLAGS})
38 string(REGEX MATCH "-stdlib=[^ ]\+" LLVM_CXX_STDLIB_FLAG ${CMAKE_CXX_FLAGS})
39 string(REGEX MATCH "-std=[^ ]\+" LLVM_C_STD_FLAG ${CMAKE_C_FLAGS})
41 # Use configure_file to create BuildVariables.inc.
42 set(LLVM_SRC_ROOT ${LLVM_MAIN_SRC_DIR})
43 set(LLVM_OBJ_ROOT ${LLVM_BINARY_DIR})
44 set(LLVM_CPPFLAGS "${LLVM_DEFINITIONS}")
45 set(LLVM_CFLAGS "${LLVM_C_STD_FLAG} ${LLVM_DEFINITIONS}")
46 set(LLVM_CXXFLAGS "${LLVM_CXX_STD_FLAG} ${LLVM_CXX_STDLIB_FLAG} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")
47 set(LLVM_BUILD_SYSTEM cmake)
48 set(LLVM_HAS_RTTI ${LLVM_CONFIG_HAS_RTTI})
49 set(LLVM_DYLIB_VERSION "${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX}")
50 set(LLVM_HAS_GLOBAL_ISEL "ON")
52 # Use the C++ link flags, since they should be a superset of C link flags.
53 set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}")
54 set(LLVM_BUILDMODE ${CMAKE_BUILD_TYPE})
55 set(LLVM_SYSTEM_LIBS ${SYSTEM_LIBS})
56 string(REPLACE ";" " " LLVM_TARGETS_BUILT "${LLVM_TARGETS_TO_BUILD}")
57 llvm_canonicalize_cmake_booleans(
58   LLVM_BUILD_LLVM_DYLIB
59   LLVM_LINK_LLVM_DYLIB
60   LLVM_HAS_RTTI
61   LLVM_HAS_GLOBAL_ISEL
62   BUILD_SHARED_LIBS)
63 configure_file(${BUILDVARIABLES_SRCPATH} ${BUILDVARIABLES_OBJPATH} @ONLY)
65 # Set build-time environment(s).
66 add_definitions(-DCMAKE_CFG_INTDIR="${CMAKE_CFG_INTDIR}")
68 if(LLVM_ENABLE_MODULES)
69   target_compile_options(llvm-config PUBLIC
70     "-fmodules-ignore-macro=CMAKE_CFG_INTDIR"
71     )
72 endif()
74 # Add the dependency on the generation step.
75 add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.cpp ${BUILDVARIABLES_OBJPATH})
77 if(CMAKE_CROSSCOMPILING AND NOT LLVM_CONFIG_PATH)
78   set(LLVM_CONFIG_PATH "${LLVM_NATIVE_BUILD}/bin/llvm-config" CACHE STRING "")
80   add_custom_command(OUTPUT "${LLVM_CONFIG_PATH}"
81     COMMAND ${CMAKE_COMMAND} --build . --target llvm-config --config $<CONFIGURATION>
82     DEPENDS ${LLVM_NATIVE_BUILD}/CMakeCache.txt
83     WORKING_DIRECTORY ${LLVM_NATIVE_BUILD}
84     COMMENT "Building native llvm-config..."
85     USES_TERMINAL)
86   add_custom_target(NativeLLVMConfig DEPENDS ${LLVM_CONFIG_PATH})
87   add_dependencies(NativeLLVMConfig CONFIGURE_LLVM_NATIVE)
89   add_dependencies(llvm-config NativeLLVMConfig)
90 endif()