llvm.org GIT mirror llvm / 1f4e68f
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@281085 91177308-0d34-0410-b5e6-96231b3b80d8 Michael Gottesman 3 years ago
5 changed file(s) with 44 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
532532
533533 macro(add_llvm_library name)
534534 cmake_parse_arguments(ARG
535 "SHARED"
535 "SHARED;BUILDTREE_ONLY"
536536 ""
537537 ""
538538 ${ARGN})
539 if( BUILD_SHARED_LIBS )
540 llvm_add_library(${name} SHARED ${ARGN})
541 else()
542 llvm_add_library(${name} ${ARGN})
543 endif()
544 # The gtest libraries should not be installed or exported as a target
545 if ("${name}" STREQUAL gtest OR "${name}" STREQUAL gtest_main)
546 set(_is_gtest TRUE)
547 else()
548 set(_is_gtest FALSE)
539 if( BUILD_SHARED_LIBS OR ARG_SHARED )
540 llvm_add_library(${name} SHARED ${ARG_UNPARSED_ARGUMENTS})
541 else()
542 llvm_add_library(${name} ${ARG_UNPARSED_ARGUMENTS})
543 endif()
544
545 # Libraries that are meant to only be exposed via the build tree only are
546 # never installed and are only exported as a target in the special build tree
547 # config file.
548 if (NOT ARG_BUILDTREE_ONLY)
549549 set_property( GLOBAL APPEND PROPERTY LLVM_LIBS ${name} )
550550 endif()
551551
552552 if( EXCLUDE_FROM_ALL )
553553 set_target_properties( ${name} PROPERTIES EXCLUDE_FROM_ALL ON)
554 elseif(NOT _is_gtest)
554 elseif(ARG_BUILDTREE_ONLY)
555 set_property(GLOBAL APPEND PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY ${name})
556 else()
555557 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY OR ${name} STREQUAL "LTO")
556558 set(install_dir lib${LLVM_LIBDIR_SUFFIX})
557559 if(ARG_SHARED OR BUILD_SHARED_LIBS)
0 set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm)
11 set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
22
3 # First for users who use an installed LLVM, create the
4 # LLVMInstallationExports.cmake
5 set(LLVM_EXPORTS_FILE ${llvm_cmake_builddir}/LLVMExports.cmake)
36 get_property(LLVM_EXPORTS GLOBAL PROPERTY LLVM_EXPORTS)
4 export(TARGETS ${LLVM_EXPORTS}
5 FILE ${llvm_cmake_builddir}/LLVMExports.cmake)
7 export(TARGETS ${LLVM_EXPORTS} FILE ${LLVM_EXPORTS_FILE})
8
9 # Then for users who want to link against the LLVM build tree, provide the
10 # normal targets and the build tree only targets.
11 set(LLVM_BUILDTREEONLY_EXPORTS_FILE ${llvm_cmake_builddir}/LLVMBuildTreeOnlyTargets.cmake)
12 get_property(LLVM_EXPORTS_BUILDTREE_ONLY GLOBAL PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY)
13 export(TARGETS ${LLVM_EXPORTS_BUILDTREE_ONLY} FILE ${LLVM_BUILDTREEONLY_EXPORTS_FILE})
614
715 get_property(LLVM_AVAILABLE_LIBS GLOBAL PROPERTY LLVM_LIBS)
816
3038 set(LLVM_CONFIG_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
3139 set(LLVM_CONFIG_BINARY_DIR "${LLVM_BINARY_DIR}")
3240 set(LLVM_CONFIG_TOOLS_BINARY_DIR "${LLVM_TOOLS_BINARY_DIR}")
33 set(LLVM_CONFIG_EXPORTS_FILE "${llvm_cmake_builddir}/LLVMExports.cmake")
41 # We need to use the full path to the LLVM Exports file to make sure we get the
42 # one from the build tree. This is due to our cmake files being split between
43 # this source dir and the binary dir in the build tree configuration and the
44 # LLVM_CONFIG_CMAKE_DIR being the source directory. In contrast in the install
45 # tree, both the generated LLVMExports.cmake file and the rest of the cmake
46 # source files are put in the same cmake directory.
47 set(LLVM_CONFIG_EXPORTS_FILE "${LLVM_EXPORTS_FILE}")
48 set(LLVM_CONFIG_EXPORTS "${LLVM_EXPORTS};${LLVM_EXPORTS_BUILDTREE_ONLY}")
49 set(llvm_config_include_buildtree_only_exports
50 "include(\"${LLVM_BUILDTREEONLY_EXPORTS_FILE}\")")
3451 configure_file(
3552 LLVMConfig.cmake.in
3653 ${llvm_cmake_builddir}/LLVMConfig.cmake
3754 @ONLY)
55 set(llvm_config_include_buildtree_only_exports)
3856
3957 # For compatibility with projects that include(LLVMConfig)
4058 # via CMAKE_MODULE_PATH, place API modules next to it.
6381 set(LLVM_CONFIG_BINARY_DIR "\${LLVM_INSTALL_PREFIX}")
6482 set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/bin")
6583 set(LLVM_CONFIG_EXPORTS_FILE "\${LLVM_CMAKE_DIR}/LLVMExports.cmake")
84 set(LLVM_CONFIG_EXPORTS "${LLVM_EXPORTS}")
6685 configure_file(
6786 LLVMConfig.cmake.in
6887 ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LLVMConfig.cmake
6767 set(LLVM_TOOLS_INSTALL_DIR "@LLVM_TOOLS_INSTALL_DIR@")
6868
6969 if(NOT TARGET LLVMSupport)
70 set(LLVM_EXPORTED_TARGETS "@LLVM_EXPORTS@")
70 set(LLVM_EXPORTED_TARGETS "@LLVM_CONFIG_EXPORTS@")
7171 include("@LLVM_CONFIG_EXPORTS_FILE@")
72 @llvm_config_include_buildtree_only_exports@
7273 endif()
7374
7475 include(${LLVM_CMAKE_DIR}/LLVM-Config.cmake)
4444
4545 LINK_COMPONENTS
4646 Support # Depends on llvm::raw_ostream
47
48 # This is a library meant only for the build tree.
49 BUILDTREE_ONLY
4750 )
4851
4952 add_subdirectory(UnitTestMain)
55
66 LINK_COMPONENTS
77 Support # Depends on llvm::cl
8
9 # This library is not meant to be in the install tree, only the build tree.
10 BUILDTREE_ONLY
811 )