mirror of
https://github.com/intel/llvm.git
synced 2026-02-06 06:31:50 +08:00
[libunwind] Allow target flags to affect CMake configuration tests
Summary: This patch changes the libunwind CMake so that it adds certain target flags like '-m32' or '--gcc-toolchain' before including config-ix.cmake. Since these flags can affect things like check_library_exists([...]) they needed to be added before the tests are performed. Additionally this patch adds LIBUNWIND_BUILD_32_BITS which defaults to LLVM_BUILD_32_BITS. This patch fixes: https://llvm.org/bugs/show_bug.cgi?id=27950 https://llvm.org/bugs/show_bug.cgi?id=27959 Reviewers: jroelofs, danalbert, bcraig, rmaprath, compnerd Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D20889 llvm-svn: 271458
This commit is contained in:
@@ -99,14 +99,16 @@ endif()
|
||||
#===============================================================================
|
||||
|
||||
# Define options.
|
||||
option(LIBUNWIND_BUILD_32_BITS "Build 32 bit libunwind" ${LLVM_BUILD_32_BITS})
|
||||
option(LIBUNWIND_ENABLE_ASSERTIONS "Enable assertions independent of build mode." ON)
|
||||
option(LIBUNWIND_ENABLE_PEDANTIC "Compile with pedantic enabled." ON)
|
||||
option(LIBUNWIND_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF)
|
||||
option(LIBUNWIND_ENABLE_SHARED "Build libunwind as a shared library." ON)
|
||||
option(LIBUNWIND_ENABLE_CROSS_UNWINDING "Enable cross-platform unwinding support." OFF)
|
||||
|
||||
set(LIBUNWIND_GCC_TOOLCHAIN "" CACHE STRING "GCC toolchain for cross compiling.")
|
||||
set(LIBUNWIND_SYSROOT "" CACHE STRING "Sysroot for cross compiling.")
|
||||
set(LIBUNWIND_TARGET_TRIPLE "" CACHE STRING "Target triple for cross compiling.")
|
||||
set(LIBUNWIND_GCC_TOOLCHAIN "" CACHE PATH "GCC toolchain for cross compiling.")
|
||||
set(LIBUNWIND_SYSROOT "" CACHE PATH "Sysroot for cross compiling.")
|
||||
|
||||
#===============================================================================
|
||||
# Configure System
|
||||
@@ -117,17 +119,15 @@ set(CMAKE_MODULE_PATH
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake"
|
||||
${CMAKE_MODULE_PATH})
|
||||
|
||||
# Configure compiler.
|
||||
include(config-ix)
|
||||
|
||||
set(LIBUNWIND_COMPILER ${CMAKE_CXX_COMPILER})
|
||||
set(LIBUNWIND_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
set(LIBUNWIND_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set(LIBUNWIND_LIBRARY_DIR ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX})
|
||||
|
||||
#===============================================================================
|
||||
# Setup Compiler Flags
|
||||
#===============================================================================
|
||||
set(LIBUNWIND_C_FLAGS "")
|
||||
set(LIBUNWIND_CXX_FLAGS "")
|
||||
set(LIBUNWIND_COMPILE_FLAGS "")
|
||||
set(LIBUNWIND_LINK_FLAGS "")
|
||||
|
||||
# Get required flags.
|
||||
macro(append_if list condition var)
|
||||
@@ -136,10 +136,29 @@ macro(append_if list condition var)
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
set(LIBUNWIND_C_FLAGS "")
|
||||
set(LIBUNWIND_CXX_FLAGS "")
|
||||
set(LIBUNWIND_COMPILE_FLAGS "")
|
||||
set(LIBUNWIND_LINK_FLAGS "")
|
||||
macro(add_target_flags_if condition var)
|
||||
if (${condition})
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${var}")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${var}")
|
||||
list(APPEND LINUNWIND_COMPILE_FLAGS ${var})
|
||||
list(APPEND LIBUNWIND_LINK_FLAGS ${var})
|
||||
endif()
|
||||
endmacro()
|
||||
|
||||
add_target_flags_if(LIBUNWIND_BUILD_32_BITS "-m32")
|
||||
add_target_flags_if(LIBUNWIND_TARGET_TRIPLE
|
||||
"-target ${LIBUNWIND_TARGET_TRIPLE}")
|
||||
add_target_flags_if(LIBUNWIND_GCC_TOOLCHAIN
|
||||
"-gcc-toolchain ${LIBUNWIND_GCC_TOOLCHAIN}")
|
||||
add_target_flags_if(LIBUNWIND_SYSROOT
|
||||
"--sysroot=${LIBUNWIND_SYSROOT}")
|
||||
|
||||
# Configure compiler.
|
||||
include(config-ix)
|
||||
|
||||
#===============================================================================
|
||||
# Setup Compiler Flags
|
||||
#===============================================================================
|
||||
|
||||
append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_HAS_WERROR_FLAG -Werror=return-type)
|
||||
|
||||
@@ -213,13 +232,6 @@ if (MSVC)
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
endif ()
|
||||
|
||||
append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_TARGET_TRIPLE
|
||||
"-target ${LIBUNWIND_TARGET_TRIPLE}")
|
||||
append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_GCC_TOOLCHAIN
|
||||
"-gcc-toolchain ${LIBUNWIND_GCC_TOOLCHAIN}")
|
||||
append_if(LIBUNWIND_COMPILE_FLAGS LIBUNWIND_SYSROOT
|
||||
"--sysroot=${LIBUNWIND_SYSROOT}")
|
||||
|
||||
#===============================================================================
|
||||
# Setup Source Code
|
||||
#===============================================================================
|
||||
|
||||
@@ -94,17 +94,20 @@ endif ()
|
||||
|
||||
string(REPLACE ";" " " LIBUNWIND_COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}")
|
||||
string(REPLACE ";" " " LIBUNWIND_CXX_FLAGS "${LIBUNWIND_CXX_FLAGS}")
|
||||
string(REPLACE ";" " " LIBUNWIND_C_FLAGS "${LIBUNWIND_C_FLAGS}")
|
||||
string(REPLACE ";" " " LIBUNWIND_LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}")
|
||||
|
||||
set_target_properties(unwind
|
||||
PROPERTIES
|
||||
COMPILE_FLAGS "${CMAKE_COMPILE_FLAGS} ${LIBUNWIND_COMPILE_FLAGS}"
|
||||
LINK_FLAGS "${CMAKE_LINK_FLAGS} ${LIBUNWIND_LINK_FLAGS}"
|
||||
COMPILE_FLAGS "${LIBUNWIND_COMPILE_FLAGS}"
|
||||
LINK_FLAGS "${LIBUNWIND_LINK_FLAGS}"
|
||||
OUTPUT_NAME "unwind"
|
||||
VERSION "1.0"
|
||||
SOVERSION "1")
|
||||
set_property(SOURCE ${LIBUNWIND_CXX_SOURCES}
|
||||
APPEND_STRING PROPERTY COMPILE_FLAGS "${LIBUNWIND_CXX_FLAGS}")
|
||||
APPEND_STRING PROPERTY COMPILE_FLAGS "${CMAKE_CXX_FLAGS} ${LIBUNWIND_CXX_FLAGS}")
|
||||
set_property(SOURCE ${LIBUNWIND_C_SOURCES}
|
||||
APPEND_STRING PROPERTY COMPILE_FLAGS "${CMAKE_C_FLAGS} ${LIBUNWIND_C_FLAGS}")
|
||||
|
||||
install(TARGETS unwind
|
||||
LIBRARY DESTINATION lib${LLVM_LIBDIR_SUFFIX}
|
||||
|
||||
Reference in New Issue
Block a user