llvm-project/llvm/tools/llvm-config/CMakeLists.txt

84 lines
3.2 KiB
CMake
Raw Normal View History

set(LLVM_LINK_COMPONENTS support)
set(BUILDVARIABLES_SRCPATH ${CMAKE_CURRENT_SOURCE_DIR}/BuildVariables.inc.in)
set(BUILDVARIABLES_OBJPATH ${CMAKE_CURRENT_BINARY_DIR}/BuildVariables.inc)
# Add the llvm-config tool.
add_llvm_tool(llvm-config
llvm-config.cpp
)
# Compute the substitution values for various items.
get_property(SUPPORT_SYSTEM_LIBS TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS)
get_property(WINDOWSMANIFEST_SYSTEM_LIBS TARGET LLVMWindowsManifest PROPERTY LLVM_SYSTEM_LIBS)
foreach(l ${SUPPORT_SYSTEM_LIBS} ${WINDOWSMANIFEST_SYSTEM_LIBS})
if(MSVC)
set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}.lib")
else()
if (l MATCHES "^-")
# If it's an option, pass it without changes.
set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}")
else()
# Otherwise assume it's a library name we need to link with.
set(SYSTEM_LIBS ${SYSTEM_LIBS} "-l${l}")
endif()
endif()
endforeach()
string(REPLACE ";" " " SYSTEM_LIBS "${SYSTEM_LIBS}")
# Fetch target specific compile options, e.g. RTTI option
get_property(COMPILE_FLAGS TARGET llvm-config PROPERTY COMPILE_FLAGS)
Don't add unnecessary compiler flags to llvm-config output Summary: llvm-config --cxxflags --cflags, should only output the minimal flags required to link against the llvm libraries. They currently contain all flags used to compile llvm including flags like -g, -pedantic, -Wall, etc, which users may not always want. This changes the llvm-config output to only include flags that have been explictly added to the COMPILE_FLAGS property of the llvm-config target by the llvm build system. llvm.org/PR8220 Output from llvm-config when running cmake with: cmake -G Ninja .. -DCMAKE_CXX_FLAGS=-funroll-loops Before: --cppflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS --cflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include -fPIC -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings \ -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough \ -Wno-comment -fdiagnostics-color -g -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS \ -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS --cxxflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include\ -funroll-loops -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall \ -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers \ -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized \ -Wno-class-memaccess -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment \ -fdiagnostics-color -g -fno-exceptions -fno-rtti -D_GNU_SOURCE -D_DEBUG \ -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS" After: --cppflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include \ -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS --cflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include \ -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS --cxxflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include \ -std=c++11 -fno-exceptions -fno-rtti \ -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS Reviewers: sylvestre.ledru, infinity0, mgorny Reviewed By: sylvestre.ledru, mgorny Subscribers: mgorny, dmgreen, llvm-commits Differential Revision: https://reviews.llvm.org/D55391 llvm-svn: 349068
2018-12-14 02:21:23 +08:00
# The language standard potentially affects the ABI/API of LLVM, so we want
# to make sure it is reported by llvm-config.
# NOTE: We don't want to start extracting any random C/CXX flags that the
# user may add that could affect the ABI. We only want to extract flags
# that have been added by the LLVM build system.
string(REGEX MATCH "-std=[^ ]\+" LLVM_CXX_STD_FLAG ${CMAKE_CXX_FLAGS})
string(REGEX MATCH "-stdlib=[^ ]\+" LLVM_CXX_STDLIB_FLAG ${CMAKE_CXX_FLAGS})
Don't add unnecessary compiler flags to llvm-config output Summary: llvm-config --cxxflags --cflags, should only output the minimal flags required to link against the llvm libraries. They currently contain all flags used to compile llvm including flags like -g, -pedantic, -Wall, etc, which users may not always want. This changes the llvm-config output to only include flags that have been explictly added to the COMPILE_FLAGS property of the llvm-config target by the llvm build system. llvm.org/PR8220 Output from llvm-config when running cmake with: cmake -G Ninja .. -DCMAKE_CXX_FLAGS=-funroll-loops Before: --cppflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS --cflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include -fPIC -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings \ -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough \ -Wno-comment -fdiagnostics-color -g -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS \ -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS --cxxflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include\ -funroll-loops -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall \ -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers \ -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized \ -Wno-class-memaccess -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment \ -fdiagnostics-color -g -fno-exceptions -fno-rtti -D_GNU_SOURCE -D_DEBUG \ -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS" After: --cppflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include \ -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS --cflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include \ -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS --cxxflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include \ -std=c++11 -fno-exceptions -fno-rtti \ -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS Reviewers: sylvestre.ledru, infinity0, mgorny Reviewed By: sylvestre.ledru, mgorny Subscribers: mgorny, dmgreen, llvm-commits Differential Revision: https://reviews.llvm.org/D55391 llvm-svn: 349068
2018-12-14 02:21:23 +08:00
string(REGEX MATCH "-std=[^ ]\+" LLVM_C_STD_FLAG ${CMAKE_C_FLAGS})
# Use configure_file to create BuildVariables.inc.
set(LLVM_SRC_ROOT ${LLVM_MAIN_SRC_DIR})
set(LLVM_OBJ_ROOT ${LLVM_BINARY_DIR})
Don't add unnecessary compiler flags to llvm-config output Summary: llvm-config --cxxflags --cflags, should only output the minimal flags required to link against the llvm libraries. They currently contain all flags used to compile llvm including flags like -g, -pedantic, -Wall, etc, which users may not always want. This changes the llvm-config output to only include flags that have been explictly added to the COMPILE_FLAGS property of the llvm-config target by the llvm build system. llvm.org/PR8220 Output from llvm-config when running cmake with: cmake -G Ninja .. -DCMAKE_CXX_FLAGS=-funroll-loops Before: --cppflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS --cflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include -fPIC -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings \ -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough \ -Wno-comment -fdiagnostics-color -g -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS \ -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS --cxxflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include\ -funroll-loops -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall \ -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers \ -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-maybe-uninitialized \ -Wno-class-memaccess -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment \ -fdiagnostics-color -g -fno-exceptions -fno-rtti -D_GNU_SOURCE -D_DEBUG \ -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS" After: --cppflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include \ -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS --cflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include \ -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS --cxxflags: -I$HEADERS_DIR/llvm/include -I$HEADERS_DIR/llvm/build/include \ -std=c++11 -fno-exceptions -fno-rtti \ -D_GNU_SOURCE -D_DEBUG -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS Reviewers: sylvestre.ledru, infinity0, mgorny Reviewed By: sylvestre.ledru, mgorny Subscribers: mgorny, dmgreen, llvm-commits Differential Revision: https://reviews.llvm.org/D55391 llvm-svn: 349068
2018-12-14 02:21:23 +08:00
set(LLVM_CPPFLAGS "${LLVM_DEFINITIONS}")
set(LLVM_CFLAGS "${LLVM_C_STD_FLAG} ${LLVM_DEFINITIONS}")
set(LLVM_CXXFLAGS "${LLVM_CXX_STD_FLAG} ${LLVM_CXX_STDLIB_FLAG} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")
set(LLVM_BUILD_SYSTEM cmake)
set(LLVM_HAS_RTTI ${LLVM_CONFIG_HAS_RTTI})
set(LLVM_DYLIB_VERSION "${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX}")
set(LLVM_HAS_GLOBAL_ISEL "ON")
# Use the C++ link flags, since they should be a superset of C link flags.
set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}")
set(LLVM_BUILDMODE ${CMAKE_BUILD_TYPE})
set(LLVM_SYSTEM_LIBS ${SYSTEM_LIBS})
string(REPLACE ";" " " LLVM_TARGETS_BUILT "${LLVM_TARGETS_TO_BUILD}")
llvm_canonicalize_cmake_booleans(
LLVM_BUILD_LLVM_DYLIB
LLVM_LINK_LLVM_DYLIB
LLVM_HAS_RTTI
LLVM_HAS_GLOBAL_ISEL
BUILD_SHARED_LIBS)
configure_file(${BUILDVARIABLES_SRCPATH} ${BUILDVARIABLES_OBJPATH} @ONLY)
# Set build-time environment(s).
add_definitions(-DCMAKE_CFG_INTDIR="${CMAKE_CFG_INTDIR}")
if(LLVM_ENABLE_MODULES)
target_compile_options(llvm-config PUBLIC
"-fmodules-ignore-macro=CMAKE_CFG_INTDIR"
)
endif()
# Add the dependency on the generation step.
add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.cpp ${BUILDVARIABLES_OBJPATH})
if(CMAKE_CROSSCOMPILING AND NOT LLVM_CONFIG_PATH)
build_native_tool(llvm-config LLVM_CONFIG_PATH)
set(LLVM_CONFIG_PATH "${LLVM_CONFIG_PATH}" CACHE STRING "")
add_custom_target(NativeLLVMConfig DEPENDS ${LLVM_CONFIG_PATH})
add_dependencies(llvm-config NativeLLVMConfig)
endif()