• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Generate a list of CMake library targets so that other CMake projects can
2# link against them. LLVM calls its version of this file LLVMExports.cmake, but
3# the usual CMake convention seems to be ${Project}Targets.cmake.
4set(FLANG_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/flang)
5set(flang_cmake_builddir "${CMAKE_BINARY_DIR}/${FLANG_INSTALL_PACKAGE_DIR}")
6
7# Keep this in sync with llvm/cmake/CMakeLists.txt!
8set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm)
9set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
10
11get_property(FLANG_EXPORTS GLOBAL PROPERTY FLANG_EXPORTS)
12export(TARGETS ${FLANG_EXPORTS} FILE ${flang_cmake_builddir}/FlangTargets.cmake)
13
14# Generate FlangConfig.cmake for the build tree.
15set(FLANG_CONFIG_CMAKE_DIR "${flang_cmake_builddir}")
16set(FLANG_CONFIG_LLVM_CMAKE_DIR "${llvm_cmake_builddir}")
17set(FLANG_CONFIG_EXPORTS_FILE "${flang_cmake_builddir}/FlangTargets.cmake")
18set(FLANG_CONFIG_INCLUDE_DIRS
19  "${FLANG_SOURCE_DIR}/include"
20  "${FLANG_BINARY_DIR}/include"
21  )
22configure_file(
23  ${CMAKE_CURRENT_SOURCE_DIR}/FlangConfig.cmake.in
24  ${flang_cmake_builddir}/FlangConfig.cmake
25  @ONLY)
26set(FLANG_CONFIG_CMAKE_DIR)
27set(FLANG_CONFIG_LLVM_CMAKE_DIR)
28set(FLANG_CONFIG_EXPORTS_FILE)
29
30# Generate FlangConfig.cmake for the install tree.
31set(FLANG_CONFIG_CODE "
32  # Compute the installation prefix from this LLVMConfig.cmake file location.
33  get_filename_component(FLANG_INSTALL_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)")
34# Construct the proper number of get_filename_component(... PATH)
35# calls to compute the installation prefix.
36string(REGEX REPLACE "/" ";" _count "${FLANG_INSTALL_PACKAGE_DIR}")
37foreach(p ${_count})
38  set(FLANG_CONFIG_CODE "${FLANG_CONFIG_CODE}
39      get_filename_component(FLANG_INSTALL_PREFIX \"\${FLANG_INSTALL_PREFIX}\" PATH)")
40endforeach(p)
41
42set(FLANG_CONFIG_CMAKE_DIR "\${FLANG_INSTALL_PREFIX}/${FLANG_INSTALL_PACKAGE_DIR}")
43set(FLANG_CONFIG_LLVM_CMAKE_DIR "\${FLANG_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}")
44set(FLANG_CONFIG_EXPORTS_FILE "\${FLANG_CMAKE_DIR}/FlangTargets.cmake")
45set(FLANG_CONFIG_INCLUDE_DIRS "\${FLANG_INSTALL_PREFIX}/include")
46
47configure_file(
48  ${CMAKE_CURRENT_SOURCE_DIR}/FlangConfig.cmake.in
49  ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/FlangConfig.cmake
50  @ONLY)
51
52set(FLANG_CONFIG_CODE)
53set(FLANG_CONFIG_CMAKE_DIR)
54set(FLANG_CONFIG_EXPORTS_FILE)
55
56if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
57  get_property(flang_has_exports GLOBAL PROPERTY FLANG_HAS_EXPORTS)
58  if(flang_has_exports)
59    install(EXPORT FlangTargets DESTINATION ${FLANG_INSTALL_PACKAGE_DIR}
60            COMPONENT flang-cmake-exports)
61  endif()
62
63  install(FILES
64    ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/FlangConfig.cmake
65    DESTINATION ${FLANG_INSTALL_PACKAGE_DIR}
66    COMPONENT flang-cmake-exports)
67
68  if(NOT LLVM_ENABLE_IDE)
69    # Add a dummy target so this can be used with LLVM_DISTRIBUTION_COMPONENTS
70    add_custom_target(flang-cmake-exports)
71    add_llvm_install_targets(install-flang-cmake-exports
72                             COMPONENT flang-cmake-exports)
73  endif()
74endif()
75