[llvm-objcopy] [COFF] Test absolute symbols wrt --strip-unneeded and --discard-all...
[llvm-complete.git] / cmake / modules / CMakeLists.txt
blobf5cc0006fa06ad5fc2a11707be1d3dac062013d4
1 set(LLVM_INSTALL_PACKAGE_DIR lib${LLVM_LIBDIR_SUFFIX}/cmake/llvm)
2 set(llvm_cmake_builddir "${LLVM_BINARY_DIR}/${LLVM_INSTALL_PACKAGE_DIR}")
4 # First for users who use an installed LLVM, create the LLVMExports.cmake file.
5 set(LLVM_EXPORTS_FILE ${llvm_cmake_builddir}/LLVMExports.cmake)
6 get_property(LLVM_EXPORTS GLOBAL PROPERTY LLVM_EXPORTS)
7 export(TARGETS ${LLVM_EXPORTS} FILE ${LLVM_EXPORTS_FILE})
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})
15 get_property(LLVM_AVAILABLE_LIBS GLOBAL PROPERTY LLVM_LIBS)
17 foreach(lib ${LLVM_AVAILABLE_LIBS})
18   get_property(llvm_lib_deps GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${lib})
19   set(all_llvm_lib_deps
20     "${all_llvm_lib_deps}\nset_property(GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_${lib} ${llvm_lib_deps})")
21 endforeach(lib)
23 # CMake requires that all targets expressed as dependencies exist, so we can't
24 # have intrinsics_gen in LLVM_COMMON_DEPENDS when it is written out, otherwise
25 # projects building out of tree will have CMake errors. This only gets hit when
26 # LLVM_ENABLE_MODULES=On. Eventually we should come up with a better solution to
27 # this, but there is no easy solution.
28 if(intrinsics_gen IN_LIST LLVM_COMMON_DEPENDS)
29   list(REMOVE_ITEM LLVM_COMMON_DEPENDS intrinsics_gen)
30 endif()
32 # Generate LLVMConfig.cmake for the build tree.
33 set(LLVM_CONFIG_CODE "
34 # LLVM_BUILD_* values available only from LLVM build tree.
35 set(LLVM_BUILD_BINARY_DIR \"${LLVM_BINARY_DIR}\")
36 set(LLVM_BUILD_LIBRARY_DIR \"${LLVM_LIBRARY_DIR}\")
37 set(LLVM_BUILD_MAIN_INCLUDE_DIR \"${LLVM_MAIN_INCLUDE_DIR}\")
38 set(LLVM_BUILD_MAIN_SRC_DIR \"${LLVM_MAIN_SRC_DIR}\")
40 set(LLVM_CONFIG_INCLUDE_DIRS
41   "${LLVM_MAIN_INCLUDE_DIR}"
42   "${LLVM_INCLUDE_DIR}"
43   )
44 set(LLVM_CONFIG_LIBRARY_DIRS
45   "${LLVM_LIBRARY_DIR}"
46   )
47 set(LLVM_CONFIG_CMAKE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
48 set(LLVM_CONFIG_BINARY_DIR "${LLVM_BINARY_DIR}")
49 set(LLVM_CONFIG_TOOLS_BINARY_DIR "${LLVM_TOOLS_BINARY_DIR}")
51 if (LLVM_LINK_LLVM_DYLIB)
52   set(LLVM_CONFIG_LINK_LLVM_DYLIB
53       "set(LLVM_LINK_LLVM_DYLIB ${LLVM_LINK_LLVM_DYLIB})")
54 endif()
56 # We need to use the full path to the LLVM Exports file to make sure we get the
57 # one from the build tree. This is due to our cmake files being split between
58 # this source dir and the binary dir in the build tree configuration and the
59 # LLVM_CONFIG_CMAKE_DIR being the source directory. In contrast in the install
60 # tree, both the generated LLVMExports.cmake file and the rest of the cmake
61 # source files are put in the same cmake directory.
62 set(LLVM_CONFIG_EXPORTS_FILE "${LLVM_EXPORTS_FILE}")
63 set(LLVM_CONFIG_EXPORTS "${LLVM_EXPORTS};${LLVM_EXPORTS_BUILDTREE_ONLY}")
64 set(llvm_config_include_buildtree_only_exports
65 "include(\"${LLVM_BUILDTREEONLY_EXPORTS_FILE}\")")
66 configure_file(
67   LLVMConfig.cmake.in
68   ${llvm_cmake_builddir}/LLVMConfig.cmake
69   @ONLY)
70 set(llvm_config_include_buildtree_only_exports)
72 # For compatibility with projects that include(LLVMConfig)
73 # via CMAKE_MODULE_PATH, place API modules next to it.
74 # This should be removed in the future.
75 file(COPY .
76   DESTINATION ${llvm_cmake_builddir}
77   FILES_MATCHING PATTERN *.cmake
78   PATTERN .svn EXCLUDE
79   PATTERN CMakeFiles EXCLUDE
80   )
82 # Generate LLVMConfig.cmake for the install tree.
83 set(LLVM_CONFIG_CODE "
84 # Compute the installation prefix from this LLVMConfig.cmake file location.
85 get_filename_component(LLVM_INSTALL_PREFIX \"\${CMAKE_CURRENT_LIST_FILE}\" PATH)")
86 # Construct the proper number of get_filename_component(... PATH)
87 # calls to compute the installation prefix.
88 string(REGEX REPLACE "/" ";" _count "${LLVM_INSTALL_PACKAGE_DIR}")
89 foreach(p ${_count})
90   set(LLVM_CONFIG_CODE "${LLVM_CONFIG_CODE}
91 get_filename_component(LLVM_INSTALL_PREFIX \"\${LLVM_INSTALL_PREFIX}\" PATH)")
92 endforeach(p)
93 set(LLVM_CONFIG_INCLUDE_DIRS "\${LLVM_INSTALL_PREFIX}/include")
94 set(LLVM_CONFIG_LIBRARY_DIRS "\${LLVM_INSTALL_PREFIX}/lib\${LLVM_LIBDIR_SUFFIX}")
95 set(LLVM_CONFIG_CMAKE_DIR "\${LLVM_INSTALL_PREFIX}/${LLVM_INSTALL_PACKAGE_DIR}")
96 set(LLVM_CONFIG_BINARY_DIR "\${LLVM_INSTALL_PREFIX}")
97 set(LLVM_CONFIG_TOOLS_BINARY_DIR "\${LLVM_INSTALL_PREFIX}/bin")
98 set(LLVM_CONFIG_EXPORTS_FILE "\${LLVM_CMAKE_DIR}/LLVMExports.cmake")
99 set(LLVM_CONFIG_EXPORTS "${LLVM_EXPORTS}")
100 configure_file(
101   LLVMConfig.cmake.in
102   ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LLVMConfig.cmake
103   @ONLY)
105 # Generate LLVMConfigVersion.cmake for build and install tree.
106 configure_file(
107   LLVMConfigVersion.cmake.in
108   ${llvm_cmake_builddir}/LLVMConfigVersion.cmake
109   @ONLY)
111 if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
112   get_property(llvm_has_exports GLOBAL PROPERTY LLVM_HAS_EXPORTS)
113   if(llvm_has_exports)
114     install(EXPORT LLVMExports DESTINATION ${LLVM_INSTALL_PACKAGE_DIR}
115             COMPONENT cmake-exports)
116   endif()
118   install(FILES
119     ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/LLVMConfig.cmake
120     ${llvm_cmake_builddir}/LLVMConfigVersion.cmake
121     LLVM-Config.cmake
122     DESTINATION ${LLVM_INSTALL_PACKAGE_DIR}
123     COMPONENT cmake-exports)
125   install(DIRECTORY .
126     DESTINATION ${LLVM_INSTALL_PACKAGE_DIR}
127     COMPONENT cmake-exports
128     FILES_MATCHING PATTERN *.cmake
129     PATTERN .svn EXCLUDE
130     PATTERN LLVMConfig.cmake EXCLUDE
131     PATTERN LLVMConfigVersion.cmake EXCLUDE
132     PATTERN LLVM-Config.cmake EXCLUDE
133     PATTERN GetHostTriple.cmake EXCLUDE)
135   if (NOT LLVM_ENABLE_IDE)
136     # Add a dummy target so this can be used with LLVM_DISTRIBUTION_COMPONENTS
137     add_custom_target(cmake-exports)
138     add_llvm_install_targets(install-cmake-exports
139                              COMPONENT cmake-exports)
140   endif()
141 endif()