[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / cmake / modules / CMakeLists.txt
blob51b6a4fdc2843d0d21d233014bc52bee5e67baff
1 include(LLVMDistributionSupport)
3 set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm)
4 set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
6 # First for users who use an installed LLVM, create the LLVMExports.cmake file.
7 set(LLVM_EXPORTS_FILE ${llvm_cmake_builddir}/LLVMExports.cmake)
8 get_property(LLVM_EXPORTS GLOBAL PROPERTY LLVM_EXPORTS)
9 export(TARGETS ${LLVM_EXPORTS} FILE ${LLVM_EXPORTS_FILE})
11 # Then for users who want to link against the LLVM build tree, provide the
12 # normal targets and the build tree only targets.
13 set(LLVM_BUILDTREEONLY_EXPORTS_FILE ${llvm_cmake_builddir}/LLVMBuildTreeOnlyTargets.cmake)
14 get_property(LLVM_EXPORTS_BUILDTREE_ONLY GLOBAL PROPERTY LLVM_EXPORTS_BUILDTREE_ONLY)
15 export(TARGETS ${LLVM_EXPORTS_BUILDTREE_ONLY} FILE ${LLVM_BUILDTREEONLY_EXPORTS_FILE})
17 get_property(LLVM_AVAILABLE_LIBS GLOBAL PROPERTY LLVM_LIBS)
19 foreach(lib ${LLVM_AVAILABLE_LIBS})
20   get_property(llvm_lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${lib})
21   set(all_llvm_lib_deps
22     "${all_llvm_lib_deps}\nset_property(GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${lib} ${llvm_lib_deps})")
23 endforeach(lib)
25 # CMake requires that all targets expressed as dependencies exist, so we can't
26 # have intrinsics_gen in LLVM_COMMON_DEPENDS when it is written out, otherwise
27 # projects building out of tree will have CMake errors. This only gets hit when
28 # LLVM_ENABLE_MODULES=On. Eventually we should come up with a better solution to
29 # this, but there is no easy solution.
30 if(intrinsics_gen IN_LIST LLVM_COMMON_DEPENDS)
31   list(REMOVE_ITEM LLVM_COMMON_DEPENDS intrinsics_gen)
32 endif()
33 if(omp_gen IN_LIST LLVM_COMMON_DEPENDS)
34   list(REMOVE_ITEM LLVM_COMMON_DEPENDS omp_gen)
35 endif()
37 # Generate LLVMConfig.cmake for the build tree.
38 set(LLVM_CONFIG_CODE "
39 # LLVM_BUILD_* values available only from LLVM build tree.
40 set(LLVM_BUILD_BINARY_DIR \"${LLVM_BINARY_DIR}\")
41 set(LLVM_BUILD_LIBRARY_DIR \"${LLVM_LIBRARY_DIR}\")
42 set(LLVM_BUILD_MAIN_INCLUDE_DIR \"${LLVM_MAIN_INCLUDE_DIR}\")
43 set(LLVM_BUILD_MAIN_SRC_DIR \"${LLVM_MAIN_SRC_DIR}\")
45 set(LLVM_CONFIG_INCLUDE_DIRS
46   "${LLVM_MAIN_INCLUDE_DIR}"
47   "${LLVM_INCLUDE_DIR}"
48   )
49 set(LLVM_CONFIG_INCLUDE_DIR
50   "${LLVM_INCLUDE_DIR}"
51   )
52 set(LLVM_CONFIG_MAIN_INCLUDE_DIR
53   "${LLVM_MAIN_INCLUDE_DIR}"
54   )
55 set(LLVM_CONFIG_LIBRARY_DIRS
56   "${LLVM_LIBRARY_DIR}"
57   )
58 set(LLVM_CONFIG_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
59 set(LLVM_CONFIG_BINARY_DIR "${LLVM_BINARY_DIR}")
60 set(LLVM_CONFIG_TOOLS_BINARY_DIR "${LLVM_TOOLS_BINARY_DIR}")
62 # Generate a default location for lit
63 if (LLVM_BUILD_UTILS)
64   if (CMAKE_HOST_WIN32 AND NOT CYGWIN)
65     set(LLVM_CONFIG_DEFAULT_EXTERNAL_LIT "${LLVM_CONFIG_TOOLS_BINARY_DIR}/llvm-lit.py")
66   else()
67     set(LLVM_CONFIG_DEFAULT_EXTERNAL_LIT "${LLVM_CONFIG_TOOLS_BINARY_DIR}/llvm-lit")
68   endif()
69 endif()
71 if (LLVM_LINK_LLVM_DYLIB)
72   set(LLVM_CONFIG_LINK_LLVM_DYLIB
73       "set(LLVM_LINK_LLVM_DYLIB ${LLVM_LINK_LLVM_DYLIB})")
74 endif()
76 # We need to use the full path to the LLVM Exports file to make sure we get the
77 # one from the build tree. This is due to our cmake files being split between
78 # this source dir and the binary dir in the build tree configuration and the
79 # LLVM_CONFIG_CMAKE_DIR being the source directory. In contrast in the install
80 # tree, both the generated LLVMExports.cmake file and the rest of the cmake
81 # source files are put in the same cmake directory.
82 set(LLVM_CONFIG_EXPORTS "${LLVM_EXPORTS};${LLVM_EXPORTS_BUILDTREE_ONLY}")
83 set(LLVM_CONFIG_INCLUDE_EXPORTS "include(\"${LLVM_EXPORTS_FILE}\")")
84 set(llvm_config_include_buildtree_only_exports
85 "include(\"${LLVM_BUILDTREEONLY_EXPORTS_FILE}\")")
86 configure_file(
87   LLVMConfig.cmake.in
88   ${llvm_cmake_builddir}/LLVMConfig.cmake
89   @ONLY)
90 set(llvm_config_include_buildtree_only_exports)
92 # For compatibility with projects that include(LLVMConfig)
93 # via CMAKE_MODULE_PATH, place API modules next to it.
94 # This should be removed in the future.
95 file(COPY .
96   DESTINATION ${llvm_cmake_builddir}
97   FILES_MATCHING PATTERN *.cmake
98   PATTERN CMakeFiles EXCLUDE
99   )
101 # Generate LLVMConfig.cmake for the install tree.
102 set(LLVM_CONFIG_CODE "
103 # Compute the installation prefix from this LLVMConfig.cmake file location.
104 get_filename_component(LLVM_INSTALL_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)")
105 # Construct the proper number of get_filename_component(... PATH)
106 # calls to compute the installation prefix.
107 string(REGEX REPLACE "/" ";" _count "${LLVM_INSTALL_PACKAGE_DIR}")
108 foreach(p ${_count})
109   set(LLVM_CONFIG_CODE "${LLVM_CONFIG_CODE}
110 get_filename_component(LLVM_INSTALL_PREFIX \"\${LLVM_INSTALL_PREFIX}\" PATH)")
111 endforeach(p)
112 set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/include")
113 set(LLVM_CONFIG_INCLUDE_DIR "${LLVM_CONFIG_INCLUDE_DIRS}")
114 set(LLVM_CONFIG_MAIN_INCLUDE_DIR "${LLVM_CONFIG_INCLUDE_DIRS}")
115 set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/lib\${LLVM_LIBDIR_SUFFIX}")
116 set(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}")
117 set(LLVM_CONFIG_BINARY_DIR "\${LLVM_INSTALL_PREFIX}")
118 set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/bin")
120 # Generate a default location for lit
121 if (LLVM_INSTALL_UTILS AND LLVM_BUILD_UTILS)
122   set(LLVM_CONFIG_DEFAULT_EXTERNAL_LIT "${LLVM_CONFIG_TOOLS_BINARY_DIR}/llvm-lit")
123 endif()
125 get_config_exports_includes(LLVM LLVM_CONFIG_INCLUDE_EXPORTS)
126 set(LLVM_CONFIG_EXPORTS "${LLVM_EXPORTS}")
127 configure_file(
128   LLVMConfig.cmake.in
129   ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LLVMConfig.cmake
130   @ONLY)
132 # Generate LLVMConfigVersion.cmake for build and install tree.
133 configure_file(
134   LLVMConfigVersion.cmake.in
135   ${llvm_cmake_builddir}/LLVMConfigVersion.cmake
136   @ONLY)
138 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
139   install_distribution_exports(LLVM)
141   install(FILES
142     ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LLVMConfig.cmake
143     ${llvm_cmake_builddir}/LLVMConfigVersion.cmake
144     LLVM-Config.cmake
145     DESTINATION ${LLVM_INSTALL_PACKAGE_DIR}
146     COMPONENT cmake-exports)
148   install(DIRECTORY .
149     DESTINATION ${LLVM_INSTALL_PACKAGE_DIR}
150     COMPONENT cmake-exports
151     FILES_MATCHING PATTERN *.cmake
152     PATTERN LLVMConfig.cmake EXCLUDE
153     PATTERN LLVMConfigExtensions.cmake EXCLUDE
154     PATTERN LLVMConfigVersion.cmake EXCLUDE
155     PATTERN LLVM-Config.cmake EXCLUDE
156     PATTERN GetHostTriple.cmake EXCLUDE)
158   if (NOT LLVM_ENABLE_IDE)
159     # Add a dummy target so this can be used with LLVM_DISTRIBUTION_COMPONENTS
160     add_custom_target(cmake-exports)
161     add_llvm_install_targets(install-cmake-exports
162                              COMPONENT cmake-exports)
163   endif()
164 endif()