mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-28 08:02:08 +00:00
[libc] Cleanup the CMake infrastructure to add startup objects.
Instead of using a custom target to copy the startup object file to a file with the desired name, a normal object library with a special property is used. Follow up patches will do more cleanup wrt how the startup objects are used in integration tests. Reviewed By: jhuber6 Differential Revision: https://reviews.llvm.org/D143464
This commit is contained in:
parent
2d279c0d95
commit
9b4999cbea
@ -403,9 +403,6 @@ endfunction(add_libc_fuzzer)
|
||||
# COMPILE_OPTIONS <list of special compile options for this target>
|
||||
# )
|
||||
#
|
||||
# The startup target should provide a property named STARTUP_OBJECT which is
|
||||
# the full path to the object file produced when the startup system is built.
|
||||
#
|
||||
# The DEPENDS list can be empty. If not empty, it should be a list of
|
||||
# targets added with add_entrypoint_object or add_object_library.
|
||||
function(add_integration_test test_name)
|
||||
@ -464,22 +461,21 @@ function(add_integration_test test_name)
|
||||
file(MAKE_DIRECTORY ${sysroot}/include)
|
||||
set(sysroot_lib ${sysroot}/lib)
|
||||
file(MAKE_DIRECTORY ${sysroot_lib})
|
||||
get_target_property(startup_object_file ${INTEGRATION_TEST_STARTUP} STARTUP_OBJECT)
|
||||
get_target_property(crti_object_file libc.startup.linux.crti STARTUP_OBJECT)
|
||||
get_target_property(crtn_object_file libc.startup.linux.crtn STARTUP_OBJECT)
|
||||
set(startup_object_file $<TARGET_OBJECTS:${INTEGRATION_TEST_STARTUP}>)
|
||||
set(crti_object_file $<TARGET_OBJECTS:libc.startup.linux.crti>)
|
||||
set(crtn_object_file $<TARGET_OBJECTS:libc.startup.linux.crtn>)
|
||||
set(dummy_archive $<TARGET_PROPERTY:libc_integration_test_dummy,ARCHIVE_OUTPUT_DIRECTORY>/lib$<TARGET_PROPERTY:libc_integration_test_dummy,ARCHIVE_OUTPUT_NAME>.a)
|
||||
if(NOT startup_object_file)
|
||||
message(FATAL_ERROR "Missing STARTUP_OBJECT property of ${INTEGRATION_TEST_STARTUP}.")
|
||||
endif()
|
||||
set(startup_dst ${sysroot_lib}/${LIBC_TARGET_ARCHITECTURE}-linux-gnu/crt1.o)
|
||||
# TODO: Copy the startup files to the correct target-triple directory instead
|
||||
# of to a partly hard-coded directory.
|
||||
set(startup_dst ${sysroot_lib}/${LIBC_TARGET_ARCHITECTURE}-linux-gnu)
|
||||
add_custom_command(
|
||||
OUTPUT ${startup_dst} ${sysroot}/lib/crti.o ${sysroot}/lib/crtn.o ${sysroot}/lib/libm.a ${sysroot}/lib/libc++.a
|
||||
COMMAND cmake -E copy ${startup_object_file} ${startup_dst}
|
||||
COMMAND cmake -E copy ${crti_object_file} ${sysroot}/lib
|
||||
COMMAND cmake -E copy ${crtn_object_file} ${sysroot}/lib
|
||||
COMMAND cmake -E copy ${startup_object_file} ${startup_dst}/$<TARGET_PROPERTY:${INTEGRATION_TEST_STARTUP},OUTPUT_NAME>
|
||||
COMMAND cmake -E copy ${crti_object_file} ${sysroot_lib}/$<TARGET_PROPERTY:libc.startup.linux.crti,OUTPUT_NAME>
|
||||
COMMAND cmake -E copy ${crtn_object_file} ${sysroot_lib}/$<TARGET_PROPERTY:libc.startup.linux.crtn,OUTPUT_NAME>
|
||||
# We copy the dummy archive as libm.a and libc++.a as the compiler drivers expect them.
|
||||
COMMAND cmake -E copy ${dummy_archive} ${sysroot}/lib/libm.a
|
||||
COMMAND cmake -E copy ${dummy_archive} ${sysroot}/lib/libc++.a
|
||||
COMMAND cmake -E copy ${dummy_archive} ${sysroot_lib}/libm.a
|
||||
COMMAND cmake -E copy ${dummy_archive} ${sysroot_lib}/libc++.a
|
||||
DEPENDS ${INTEGRATION_TEST_STARTUP} libc.startup.linux.crti libc.startup.linux.crtn libc_integration_test_dummy
|
||||
)
|
||||
add_custom_target(
|
||||
|
@ -8,53 +8,22 @@ function(add_startup_object name)
|
||||
)
|
||||
|
||||
get_fq_target_name(${name} fq_target_name)
|
||||
get_fq_deps_list(fq_deps_list ${ADD_STARTUP_OBJECT_DEPENDS})
|
||||
if(ADD_STARTUP_OBJECT_ALIAS)
|
||||
list(LENGTH ADD_STARTUP_OBJECT_DEPENDS deps_size)
|
||||
if(NOT (${deps_size} EQUAL "1"))
|
||||
message(FATAL_ERROR "A startup object alias should have exactly one dependency.")
|
||||
endif()
|
||||
list(GET ADD_STARTUP_OBJECT_DEPENDS 0 dep)
|
||||
get_fq_dep_name(fq_dep_name ${dep})
|
||||
|
||||
add_custom_target(${fq_target_name})
|
||||
add_dependencies(${fq_target_name} ${fq_dep_name})
|
||||
get_target_property(startup_object ${fq_dep_name} STARTUP_OBJECT)
|
||||
set_target_properties(
|
||||
${fq_target_name}
|
||||
PROPERTIES
|
||||
"TARGET_TYPE" "${OBJECT_LIBRARY_TARGET_TYPE}"
|
||||
"STARTUP_OBJECT" "${startup_object}"
|
||||
"OBJECT_FILES" ""
|
||||
"DEPS" "${fq_dep_name}"
|
||||
)
|
||||
get_fq_deps_list(fq_dep_list ${ADD_STARTUP_OBJECT_DEPENDS})
|
||||
add_library(${fq_target_name} ALIAS ${fq_dep_list})
|
||||
return()
|
||||
endif()
|
||||
|
||||
add_object_library(
|
||||
${name}.__objects__
|
||||
${name}
|
||||
SRCS ${ADD_STARTUP_OBJECT_SRC}
|
||||
DEPENDS ${ADD_STARTUP_OBJECT_DEPENDS}
|
||||
COMPILE_OPTIONS ${ADD_STARTUP_OBJECT_COMPILE_OPTIONS}
|
||||
)
|
||||
|
||||
set(objfile ${LIBC_BUILD_DIR}/lib/${name}.o)
|
||||
add_custom_command(
|
||||
OUTPUT ${objfile}
|
||||
COMMAND cp $<TARGET_OBJECTS:${fq_target_name}.__objects__> ${objfile}
|
||||
DEPENDS $<TARGET_OBJECTS:${fq_target_name}.__objects__>
|
||||
)
|
||||
add_custom_target(
|
||||
${fq_target_name}
|
||||
DEPENDS ${objfile}
|
||||
)
|
||||
set_target_properties(
|
||||
${fq_target_name}
|
||||
PROPERTIES
|
||||
"TARGET_TYPE" "${OBJECT_LIBRARY_TARGET_TYPE}"
|
||||
"STARTUP_OBJECT" "${objfile}"
|
||||
"OBJECT_FILES" ""
|
||||
"DEPS" "${fq_target_name}.__objects__"
|
||||
OUTPUT_NAME ${name}.o
|
||||
)
|
||||
endfunction()
|
||||
|
||||
@ -89,8 +58,8 @@ set(startup_components crt1 crti crtn)
|
||||
foreach(target IN LISTS startup_components)
|
||||
set(fq_target_name libc.startup.linux.${target})
|
||||
add_dependencies(libc-startup ${fq_target_name})
|
||||
get_target_property(startup_object ${fq_target_name} STARTUP_OBJECT)
|
||||
install(FILES ${startup_object}
|
||||
install(FILES $<TARGET_OBJECTS:${fq_target_name}>
|
||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||
RENAME $<TARGET_PROPERTY:${fq_target_name},OUTPUT_NAME>
|
||||
COMPONENT libc)
|
||||
endforeach()
|
||||
|
Loading…
Reference in New Issue
Block a user