EricWF created this revision. EricWF added reviewers: jroelofs, danalbert, compnerd, bcraig, rmaprath. EricWF added a subscriber: cfe-commits.
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 http://reviews.llvm.org/D20889 Files: CMakeLists.txt src/CMakeLists.txt
Index: src/CMakeLists.txt =================================================================== --- src/CMakeLists.txt +++ src/CMakeLists.txt @@ -94,17 +94,20 @@ 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} Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -99,6 +99,7 @@ #=============================================================================== # 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) @@ -117,29 +118,46 @@ "${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) if (${condition}) list(APPEND ${list} ${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 +231,6 @@ 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 #===============================================================================
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits