Bump version to 19.1.0 (final)
[llvm-project.git] / libc / lib / CMakeLists.txt
blob37acf3950b4602c5878ca3efecd75f4a3a30c08a
1 set(libc_archive_targets "")
2 set(libc_archive_names "")
3 set(libc_archive_entrypoint_lists "")
4 if(LLVM_LIBC_FULL_BUILD)
5   list(APPEND libc_archive_names c m)
6   list(APPEND libc_archive_targets libc libm)
7   list(APPEND libc_archive_entrypoint_lists
8        TARGET_LIBC_ENTRYPOINTS TARGET_LIBM_ENTRYPOINTS)
9 else()
10   list(APPEND libc_archive_names llvmlibc)
11   list(APPEND libc_archive_targets libc)
12   list(APPEND libc_archive_entrypoint_lists TARGET_LLVMLIBC_ENTRYPOINTS)
13 endif()
15 set(added_archive_targets "")
16 foreach(archive IN ZIP_LISTS
17         libc_archive_names libc_archive_targets libc_archive_entrypoint_lists)
18   if(NOT ${archive_2})
19     # If an entrypoint list is missing, then skip adding targets for it.
20     continue()
21   endif()
22   add_entrypoint_library(
23     ${archive_1}
24     DEPENDS
25       ${${archive_2}}
26   )
27   set_target_properties(
28     ${archive_1}
29     PROPERTIES
30       ARCHIVE_OUTPUT_NAME ${archive_0}
31   )
32   if(LLVM_LIBC_FULL_BUILD)
33     target_link_libraries(${archive_1} PUBLIC libc-headers)
34     if(TARGET libc-startup)
35       add_dependencies(${archive_1} libc-startup)
36     endif()
37   endif()
38   list(APPEND added_archive_targets ${archive_1})
40   # Add the offloading version of the library for offloading languages. These
41   # are installed in the standard search path separate from the other libraries.
42   if(LIBC_TARGET_OS_IS_GPU)
43     add_gpu_entrypoint_library(
44       ${archive_1}gpu
45       ${archive_1}
46       DEPENDS
47         ${${archive_2}}
48     )
49     set_target_properties(
50       ${archive_1}gpu
51       PROPERTIES
52         ARCHIVE_OUTPUT_NAME ${archive_0}gpu-${LIBC_TARGET_ARCHITECTURE}
53         ARCHIVE_OUTPUT_DIRECTORY ${LLVM_LIBRARY_OUTPUT_INTDIR}
54     )
55     list(APPEND added_gpu_archive_targets ${archive_1}gpu)
57     add_bitcode_entrypoint_library(
58       ${archive_1}bitcode
59       ${archive_1}
60       DEPENDS
61         ${${archive_2}}
62     )
63     set_target_properties(
64       ${archive_1}bitcode
65       PROPERTIES
66         OUTPUT_NAME ${archive_1}.bc
67     )
68     add_dependencies(${archive_1}gpu ${archive_1}bitcode)
69     list(APPEND added_gpu_bitcode_targets ${archive_1}bitcode)
70   endif()
71 endforeach()
73 install(
74   TARGETS ${added_archive_targets}
75   ARCHIVE DESTINATION ${LIBC_INSTALL_LIBRARY_DIR}
76   COMPONENT libc
79 if(LIBC_TARGET_OS_IS_GPU)
80   set(gpu_install_dir lib${LLVM_LIBDIR_SUFFIX})
81   if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
82     set(gpu_install_dir lib${LLVM_LIBDIR_SUFFIX}/${LLVM_HOST_TRIPLE})
83   endif()
84   install(
85     TARGETS ${added_gpu_archive_targets}
86     ARCHIVE DESTINATION ${gpu_install_dir}
87     COMPONENT libc
88   )
89   foreach(file ${added_gpu_bitcode_targets})
90     install(FILES $<TARGET_PROPERTY:${file},TARGET_OBJECT>
91             DESTINATION ${LIBC_INSTALL_LIBRARY_DIR}
92             RENAME $<TARGET_PROPERTY:${file},OUTPUT_NAME>
93             COMPONENT libc
94     )
95   endforeach()
96 endif()
98 if(NOT LIBC_TARGET_OS_IS_BAREMETAL)
99   # For now we will disable libc-startup installation for baremetal. The
100   # correct way to do it would be to make a hookable startup for baremetal
101   # and install it as part of the libc installation.
102   set(startup_target "libc-startup")
103 endif()
105 if(LLVM_LIBC_FULL_BUILD)
106   set(header_install_target install-libc-headers)
107 endif()
109 add_custom_target(install-libc
110                   DEPENDS ${added_archive_targets}
111                           ${startup_target}
112                           ${header_install_target}
113                   COMMAND "${CMAKE_COMMAND}"
114                           -DCMAKE_INSTALL_COMPONENT=libc
115                           -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
116 add_custom_target(install-libc-stripped
117                   DEPENDS ${added_archive_targets}
118                           ${startup_target}
119                           ${header_install_target}
120                   COMMAND "${CMAKE_COMMAND}"
121                           -DCMAKE_INSTALL_COMPONENT=libc
122                           -DCMAKE_INSTALL_DO_STRIP=1
123                           -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")