diff options
author | Michael Gottesman <mgottesman@apple.com> | 2016-09-09 19:45:34 +0000 |
---|---|---|
committer | Michael Gottesman <mgottesman@apple.com> | 2016-09-09 19:45:34 +0000 |
commit | 31e9363a3e469e4fb0b1c38a829826216f808f29 (patch) | |
tree | 38d58936ee0a3ebc8bbb8ee2e96c3a2cee51f50e /llvm/cmake/modules/CMakeLists.txt | |
parent | 82621dcb107242edafb99895396129320e33a49a (diff) | |
download | bcm5719-llvm-31e9363a3e469e4fb0b1c38a829826216f808f29.tar.gz bcm5719-llvm-31e9363a3e469e4fb0b1c38a829826216f808f29.zip |
[cmake] Export gtest/gtest_main and its dependencies via a special build tree only cmake exports file.
Previously, gtest/gtest_main were not exported via cmake. The intention here was
to ensure that users whom are linking against the LLVM install tree would not
get the gtest/gtest_main targets. This prevents downstream projects that link
against the LLVM build tree (i.e. Swift) from getting this dependency
information in their cmake builds. Without such dependency information, linker
issues can result on linux due to LLVMSupport being put before gtest on the
linker command line.
This commit preserves behavior that we want for the install tree, while adding
support for the build tree by:
1. The special casing for gtest/gtest_main in the add_llvm_library code is
removed in favor of a flag called "BUILDTREE_ONLY". If this is set, then the
library is communicating that it is only meant to be exported into the build
tree and is not meant to be installed or exported via the install tree. This
part is just a tweak to remove the special case, the underlying code is the
same.
2. The cmake code that exports cmake targets for the build tree has special code
to import an additional targets file called
LLVMBuildTreeOnlyExports.cmake. Additionally the extra targets are added to the
LLVMConfig.cmake's LLVM_EXPORTED_TARGETS variable. In contrast, the
"installation" cmake file uses the normal LLVM_EXPORTS_TARGETS as before and
does not include the extra exports file. This is implemented by
defining/undefining variables when performing a configure of the build/install
tree LLVMConfig.cmake files.
llvm-svn: 281085
Diffstat (limited to 'llvm/cmake/modules/CMakeLists.txt')
-rw-r--r-- | llvm/cmake/modules/CMakeLists.txt | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/llvm/cmake/modules/CMakeLists.txt b/llvm/cmake/modules/CMakeLists.txt index d2510b853ad..deeaaa8be8b 100644 --- a/llvm/cmake/modules/CMakeLists.txt +++ b/llvm/cmake/modules/CMakeLists.txt @@ -1,9 +1,17 @@ set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm) set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}") +# First for users who use an installed LLVM, create the +# LLVMInstallationExports.cmake +set(LLVM_EXPORTS_FILE ${llvm_cmake_builddir}/LLVMExports.cmake) get_property(LLVM_EXPORTS GLOBAL PROPERTY LLVM_EXPORTS) -export(TARGETS ${LLVM_EXPORTS} - FILE ${llvm_cmake_builddir}/LLVMExports.cmake) +export(TARGETS ${LLVM_EXPORTS} FILE ${LLVM_EXPORTS_FILE}) + +# Then for users who want to link against the LLVM build tree, provide the +# normal targets and the build tree only targets. +set(LLVM_BUILDTREEONLY_EXPORTS_FILE ${llvm_cmake_builddir}/LLVMBuildTreeOnlyTargets.cmake) +get_property(LLVM_EXPORTS_BUILDTREE_ONLY GLOBAL PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY) +export(TARGETS ${LLVM_EXPORTS_BUILDTREE_ONLY} FILE ${LLVM_BUILDTREEONLY_EXPORTS_FILE}) get_property(LLVM_AVAILABLE_LIBS GLOBAL PROPERTY LLVM_LIBS) @@ -31,11 +39,21 @@ set(LLVM_CONFIG_LIBRARY_DIRS set(LLVM_CONFIG_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}") set(LLVM_CONFIG_BINARY_DIR "${LLVM_BINARY_DIR}") set(LLVM_CONFIG_TOOLS_BINARY_DIR "${LLVM_TOOLS_BINARY_DIR}") -set(LLVM_CONFIG_EXPORTS_FILE "${llvm_cmake_builddir}/LLVMExports.cmake") +# We need to use the full path to the LLVM Exports file to make sure we get the +# one from the build tree. This is due to our cmake files being split between +# this source dir and the binary dir in the build tree configuration and the +# LLVM_CONFIG_CMAKE_DIR being the source directory. In contrast in the install +# tree, both the generated LLVMExports.cmake file and the rest of the cmake +# source files are put in the same cmake directory. +set(LLVM_CONFIG_EXPORTS_FILE "${LLVM_EXPORTS_FILE}") +set(LLVM_CONFIG_EXPORTS "${LLVM_EXPORTS};${LLVM_EXPORTS_BUILDTREE_ONLY}") +set(llvm_config_include_buildtree_only_exports +"include(\"${LLVM_BUILDTREEONLY_EXPORTS_FILE}\")") configure_file( LLVMConfig.cmake.in ${llvm_cmake_builddir}/LLVMConfig.cmake @ONLY) +set(llvm_config_include_buildtree_only_exports) # For compatibility with projects that include(LLVMConfig) # via CMAKE_MODULE_PATH, place API modules next to it. @@ -64,6 +82,7 @@ set(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}") set(LLVM_CONFIG_BINARY_DIR "\${LLVM_INSTALL_PREFIX}") set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/bin") set(LLVM_CONFIG_EXPORTS_FILE "\${LLVM_CMAKE_DIR}/LLVMExports.cmake") +set(LLVM_CONFIG_EXPORTS "${LLVM_EXPORTS}") configure_file( LLVMConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LLVMConfig.cmake |