2011-12-02 04:18:09 +08:00
|
|
|
set(LLVM_LINK_COMPONENTS support)
|
2008-09-22 09:08:49 +08:00
|
|
|
|
2011-12-02 04:18:09 +08:00
|
|
|
set(BUILDVARIABLES_SRCPATH ${CMAKE_CURRENT_SOURCE_DIR}/BuildVariables.inc.in)
|
|
|
|
set(BUILDVARIABLES_OBJPATH ${CMAKE_CURRENT_BINARY_DIR}/BuildVariables.inc)
|
2008-10-26 08:47:52 +08:00
|
|
|
|
2015-08-15 00:20:31 +08:00
|
|
|
# Add the llvm-config tool.
|
|
|
|
add_llvm_tool(llvm-config
|
|
|
|
llvm-config.cpp
|
|
|
|
)
|
|
|
|
|
2011-12-02 04:18:09 +08:00
|
|
|
# Compute the substitution values for various items.
|
2018-03-09 22:46:44 +08:00
|
|
|
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})
|
2016-02-10 03:41:14 +08:00
|
|
|
if(MSVC)
|
|
|
|
set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}.lib")
|
|
|
|
else()
|
2016-06-22 03:34:40 +08:00
|
|
|
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.
|
2019-12-04 00:52:21 +08:00
|
|
|
if(IS_ABSOLUTE ${l})
|
|
|
|
set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}")
|
|
|
|
else()
|
|
|
|
set(SYSTEM_LIBS ${SYSTEM_LIBS} "-l${l}")
|
|
|
|
endif()
|
2016-06-22 03:34:40 +08:00
|
|
|
endif()
|
2016-02-10 03:41:14 +08:00
|
|
|
endif()
|
2009-05-27 23:49:33 +08:00
|
|
|
endforeach()
|
2013-08-29 01:04:06 +08:00
|
|
|
string(REPLACE ";" " " SYSTEM_LIBS "${SYSTEM_LIBS}")
|
2009-04-05 06:41:07 +08:00
|
|
|
|
2015-08-15 00:20:31 +08:00
|
|
|
# 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
|
|
|
# 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.
|
2019-08-26 17:42:30 +08:00
|
|
|
string(REGEX MATCH "-stdlib=[^ ]+" LLVM_CXX_STDLIB_FLAG ${CMAKE_CXX_FLAGS})
|
|
|
|
string(REGEX MATCH "-std=[^ ]+" LLVM_C_STD_FLAG ${CMAKE_C_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
|
|
|
|
2013-08-24 01:59:13 +08:00
|
|
|
# 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}")
|
2019-11-02 00:12:03 +08:00
|
|
|
# The language standard potentially affects the ABI/API of LLVM, so we want
|
|
|
|
# to make sure it is reported by llvm-config.
|
|
|
|
set(LLVM_CXXFLAGS "${CMAKE_CXX${CMAKE_CXX_STANDARD}_STANDARD_COMPILE_OPTION} ${LLVM_CXX_STDLIB_FLAG} ${COMPILE_FLAGS} ${LLVM_DEFINITIONS}")
|
2015-09-10 00:39:30 +08:00
|
|
|
set(LLVM_BUILD_SYSTEM cmake)
|
2015-11-05 04:57:43 +08:00
|
|
|
set(LLVM_HAS_RTTI ${LLVM_CONFIG_HAS_RTTI})
|
2018-03-29 17:44:09 +08:00
|
|
|
set(LLVM_DYLIB_VERSION "${LLVM_VERSION_MAJOR}${LLVM_VERSION_SUFFIX}")
|
2015-09-10 00:39:30 +08:00
|
|
|
|
2014-04-25 09:44:20 +08:00
|
|
|
# Use the C++ link flags, since they should be a superset of C link flags.
|
|
|
|
set(LLVM_LDFLAGS "${CMAKE_CXX_LINK_FLAGS}")
|
2013-08-24 01:59:13 +08:00
|
|
|
set(LLVM_BUILDMODE ${CMAKE_BUILD_TYPE})
|
|
|
|
set(LLVM_SYSTEM_LIBS ${SYSTEM_LIBS})
|
2013-08-29 01:04:06 +08:00
|
|
|
string(REPLACE ";" " " LLVM_TARGETS_BUILT "${LLVM_TARGETS_TO_BUILD}")
|
2017-01-11 03:55:51 +08:00
|
|
|
llvm_canonicalize_cmake_booleans(
|
|
|
|
LLVM_BUILD_LLVM_DYLIB
|
|
|
|
LLVM_LINK_LLVM_DYLIB
|
|
|
|
LLVM_HAS_RTTI
|
|
|
|
BUILD_SHARED_LIBS)
|
2019-07-20 06:46:47 +08:00
|
|
|
llvm_expand_pseudo_components(LLVM_DYLIB_COMPONENTS_expanded "${LLVM_DYLIB_COMPONENTS}")
|
2013-08-24 01:59:13 +08:00
|
|
|
configure_file(${BUILDVARIABLES_SRCPATH} ${BUILDVARIABLES_OBJPATH} @ONLY)
|
2008-09-22 09:08:49 +08:00
|
|
|
|
2013-12-03 22:35:17 +08:00
|
|
|
# Set build-time environment(s).
|
|
|
|
add_definitions(-DCMAKE_CFG_INTDIR="${CMAKE_CFG_INTDIR}")
|
|
|
|
|
2017-07-31 18:07:13 +08:00
|
|
|
if(LLVM_ENABLE_MODULES)
|
|
|
|
target_compile_options(llvm-config PUBLIC
|
|
|
|
"-fmodules-ignore-macro=CMAKE_CFG_INTDIR"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2011-12-02 04:18:09 +08:00
|
|
|
# Add the dependency on the generation step.
|
|
|
|
add_file_dependencies(${CMAKE_CURRENT_SOURCE_DIR}/llvm-config.cpp ${BUILDVARIABLES_OBJPATH})
|
2014-09-04 07:21:18 +08:00
|
|
|
|
2018-01-21 08:29:00 +08:00
|
|
|
if(CMAKE_CROSSCOMPILING AND NOT LLVM_CONFIG_PATH)
|
2019-04-02 23:58:03 +08:00
|
|
|
build_native_tool(llvm-config LLVM_CONFIG_PATH)
|
|
|
|
set(LLVM_CONFIG_PATH "${LLVM_CONFIG_PATH}" CACHE STRING "")
|
2014-09-04 07:21:18 +08:00
|
|
|
|
2018-01-21 08:29:00 +08:00
|
|
|
add_custom_target(NativeLLVMConfig DEPENDS ${LLVM_CONFIG_PATH})
|
|
|
|
add_dependencies(llvm-config NativeLLVMConfig)
|
|
|
|
endif()
|