[libc-commits] [libc] e5edd74 - [libc] Add a target to install libc in the full build mode.
Siva Chandra Reddy via libc-commits
libc-commits at lists.llvm.org
Wed Aug 17 15:49:10 PDT 2022
Author: Siva Chandra Reddy
Date: 2022-08-17T22:49:02Z
New Revision: e5edd74bb77e55bd865d14528fc5022740c2336e
URL: https://github.com/llvm/llvm-project/commit/e5edd74bb77e55bd865d14528fc5022740c2336e
DIFF: https://github.com/llvm/llvm-project/commit/e5edd74bb77e55bd865d14528fc5022740c2336e.diff
LOG: [libc] Add a target to install libc in the full build mode.
* In the full build mode, `ninja install-libc` will install the headers as
well the static archive named libc.a.
* In the default mode, `ninja install-llvmlibc` will only install the
static archive libllvmlibc.a.
Reviewed By: jeffbailey
Differential Revision: https://reviews.llvm.org/D132015
Added:
Modified:
libc/CMakeLists.txt
libc/cmake/modules/LLVMLibCHeaderRules.cmake
libc/cmake/modules/LLVMLibCRules.cmake
libc/include/CMakeLists.txt
libc/lib/CMakeLists.txt
Removed:
################################################################################
diff --git a/libc/CMakeLists.txt b/libc/CMakeLists.txt
index 30d7c33c2ce9b..8aca93b2cf7cd 100644
--- a/libc/CMakeLists.txt
+++ b/libc/CMakeLists.txt
@@ -141,6 +141,22 @@ if(LLVM_LIBC_FULL_BUILD)
add_subdirectory(utils/HdrGen)
endif()
+set(LIBC_TARGET)
+set(LIBC_COMPONENT)
+set(LIBC_INSTALL_DEPENDS)
+set(LIBC_INSTALL_TARGET)
+if(LLVM_LIBC_FULL_BUILD)
+ set(LIBC_TARGET c)
+ set(LIBC_COMPONENT libc)
+ set(LIBC_INSTALL_DEPENDS "c;libc-headers")
+ set(LIBC_INSTALL_TARGET install-libc)
+else()
+ set(LIBC_TARGET llvmlibc)
+ set(LIBC_COMPONENT llvmlibc)
+ set(LIBC_INSTALL_DEPENDS llvmlibc)
+ set(LIBC_INSTALL_TARGET install-llvmlibc)
+endif()
+
add_subdirectory(include)
add_subdirectory(config)
add_subdirectory(src)
@@ -168,3 +184,9 @@ endif()
if (LIBC_INCLUDE_DOCS)
add_subdirectory(docs)
endif()
+
+add_llvm_install_targets(
+ ${LIBC_INSTALL_TARGET}
+ DEPENDS ${LIBC_INSTALL_DEPENDS}
+ COMPONENT ${LIBC_COMPONENT}
+)
diff --git a/libc/cmake/modules/LLVMLibCHeaderRules.cmake b/libc/cmake/modules/LLVMLibCHeaderRules.cmake
index c9bf466132311..729e91481d30e 100644
--- a/libc/cmake/modules/LLVMLibCHeaderRules.cmake
+++ b/libc/cmake/modules/LLVMLibCHeaderRules.cmake
@@ -35,10 +35,25 @@ function(add_header target_name)
if(ADD_HEADER_DEPENDS)
get_fq_deps_list(fq_deps_list ${ADD_HEADER_DEPENDS})
+ # Dependencies of a add_header target can only be another add_header target
+ # or an add_gen_header target.
+ foreach(dep IN LISTS fq_deps_list)
+ get_target_property(header_file ${dep} HEADER_FILE_PATH)
+ if(NOT header_file)
+ message(FATAL_ERROR "Invalid dependency '${dep}' for '${fq_target_name}'.")
+ endif()
+ endforeach()
add_dependencies(
${fq_target_name} ${fq_deps_list}
)
endif()
+
+ set_target_properties(
+ ${fq_target_name}
+ PROPERTIES
+ HEADER_FILE_PATH ${dest_file}
+ DEPS "${fq_deps_list}"
+ )
endfunction(add_header)
# A rule for generated header file targets.
@@ -53,7 +68,7 @@ endfunction(add_header)
function(add_gen_header target_name)
cmake_parse_arguments(
"ADD_GEN_HDR"
- "" # No optional arguments
+ "PUBLIC" # No optional arguments
"DEF_FILE;GEN_HDR" # Single value arguments
"PARAMS;DATA_FILES;DEPENDS" # Multi value arguments
${ARGN}
@@ -108,9 +123,24 @@ function(add_gen_header target_name)
if(ADD_GEN_HDR_DEPENDS)
get_fq_deps_list(fq_deps_list ${ADD_GEN_HDR_DEPENDS})
+ # Dependencies of a add_header target can only be another add_gen_header target
+ # or an add_header target.
+ foreach(dep IN LISTS fq_deps_list)
+ get_target_property(header_file ${dep} HEADER_FILE_PATH)
+ if(NOT header_file)
+ message(FATAL_ERROR "Invalid dependency '${dep}' for '${fq_target_name}'.")
+ endif()
+ endforeach()
endif()
add_custom_target(
${fq_target_name}
DEPENDS ${out_file} ${fq_deps_list}
)
+
+ set_target_properties(
+ ${fq_target_name}
+ PROPERTIES
+ HEADER_FILE_PATH ${out_file}
+ DEPS "${fq_deps_list}"
+ )
endfunction(add_gen_header)
diff --git a/libc/cmake/modules/LLVMLibCRules.cmake b/libc/cmake/modules/LLVMLibCRules.cmake
index c45a3f6491174..020938d0d64de 100644
--- a/libc/cmake/modules/LLVMLibCRules.cmake
+++ b/libc/cmake/modules/LLVMLibCRules.cmake
@@ -1,6 +1,5 @@
include(LLVMLibCTargetNameUtils)
include(LLVMLibCFlagRules)
-include(LLVMLibCHeaderRules)
include(LLVMLibCObjectRules)
include(LLVMLibCLibraryRules)
include(LLVMLibCTestRules)
diff --git a/libc/include/CMakeLists.txt b/libc/include/CMakeLists.txt
index faa8b1e8fcb1d..cb420cc5524dd 100644
--- a/libc/include/CMakeLists.txt
+++ b/libc/include/CMakeLists.txt
@@ -1,3 +1,6 @@
+set(LIBC_INCLUDE_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
+include(LLVMLibCHeaderRules)
+
add_subdirectory(llvm-libc-macros)
add_subdirectory(llvm-libc-types)
@@ -217,3 +220,39 @@ add_gen_header(
DATA_FILES
../config/${LIBC_TARGET_OS}/syscall_numbers.h.inc
)
+
+if(NOT LLVM_LIBC_FULLBUILD)
+ # We don't install headers in non-fullbuild mode.
+ return()
+endif()
+
+function(get_all_install_header_targets out_var)
+ set(all_deps ${ARGN})
+ foreach(target IN LISTS ARGN)
+ get_target_property(deps ${target} DEPS)
+ if(NOT deps)
+ continue()
+ endif()
+ list(APPEND all_deps ${deps})
+ get_all_install_header_targets(nested_deps ${deps})
+ list(APPEND all_deps ${nested_deps})
+ endforeach()
+ list(REMOVE_DUPLICATES all_deps)
+ set(${out_var} ${all_deps} PARENT_SCOPE)
+endfunction(get_all_install_header_targets)
+
+get_all_install_header_targets(all_install_header_targets ${TARGET_PUBLIC_HEADERS})
+add_custom_target(libc-headers)
+add_dependencies(libc-headers ${all_install_header_targets})
+foreach(target IN LISTS all_install_header_targets)
+ get_target_property(header_file ${target} HEADER_FILE_PATH)
+ if(NOT header_file)
+ message(FATAL_ERROR "Installable header file '${target}' does not have the "
+ "HEADER_FILE_PATH property set.")
+ endif()
+ file(RELATIVE_PATH relative_path ${LIBC_INCLUDE_BINARY_DIR} ${header_file})
+ get_filename_component(nested_dir ${relative_path} DIRECTORY)
+ install(FILES ${header_file}
+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${nested_dir}
+ COMPONENT ${LIBC_COMPONENT})
+endforeach()
diff --git a/libc/lib/CMakeLists.txt b/libc/lib/CMakeLists.txt
index ed8e6f8f8edd0..c5181e92a310c 100644
--- a/libc/lib/CMakeLists.txt
+++ b/libc/lib/CMakeLists.txt
@@ -1,5 +1,5 @@
add_entrypoint_library(
- llvmlibc
+ ${LIBC_TARGET}
DEPENDS
${TARGET_LLVMLIBC_ENTRYPOINTS}
)
@@ -11,13 +11,7 @@ else()
endif()
install(
- TARGETS llvmlibc
+ TARGETS ${LIBC_TARGET}
ARCHIVE DESTINATION "${LIBC_INSTALL_LIBRARY_DIR}"
- COMPONENT llvmlibc
-)
-
-add_llvm_install_targets(
- install-llvmlibc
- DEPENDS llvmlibc
- COMPONENT llvmlibc
+ COMPONENT ${LIBC_COMPONENT}
)
More information about the libc-commits
mailing list