mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
CMake: Make libc.a self-contained
Previously, libc.a contained undefined symbols from ssp and libsystem, which caused static compilation to fail. We now generate libc.a with a custom CMake rule that combines all object files from libc, ssp and libsystem to form libc.a Closes #5758.
This commit is contained in:
parent
ad40c5f9a9
commit
ae67cabe11
Notes:
sideshowbarker
2024-07-18 21:14:00 +09:00
Author: https://github.com/itamar8910 Commit: https://github.com/SerenityOS/serenity/commit/ae67cabe11b Pull-request: https://github.com/SerenityOS/serenity/pull/5808 Issue: https://github.com/SerenityOS/serenity/issues/5758
@ -85,11 +85,31 @@ add_custom_command(
|
|||||||
|
|
||||||
set(SOURCES ${LIBC_SOURCES} ${AK_SOURCES} ${ELF_SOURCES} ${ASM_SOURCES})
|
set(SOURCES ${LIBC_SOURCES} ${AK_SOURCES} ${ELF_SOURCES} ${ASM_SOURCES})
|
||||||
|
|
||||||
serenity_libc_static(LibCStatic c)
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++")
|
||||||
target_link_libraries(LibCStatic crt0 ssp system)
|
add_library(LibCStaticWithoutDeps STATIC ${SOURCES})
|
||||||
add_dependencies(LibCStatic LibM LibSystem)
|
target_link_libraries(LibCStaticWithoutDeps crt0 ssp)
|
||||||
|
add_dependencies(LibCStaticWithoutDeps LibM LibSystem)
|
||||||
|
|
||||||
|
add_custom_target(LibCStatic
|
||||||
|
COMMAND ${CMAKE_AR} -x $<TARGET_FILE:LibCStaticWithoutDeps>
|
||||||
|
COMMAND ${CMAKE_AR} -x $<TARGET_FILE:ssp>
|
||||||
|
COMMAND ${CMAKE_AR} -x $<TARGET_FILE:LibSystemStatic>
|
||||||
|
COMMAND ${CMAKE_AR} -qcs ${CMAKE_CURRENT_BINARY_DIR}/libc.a *.o
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
DEPENDS LibCStaticWithoutDeps ssp LibSystemStatic
|
||||||
|
)
|
||||||
|
|
||||||
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libc.a DESTINATION ${CMAKE_INSTALL_PREFIX}/usr/lib/)
|
||||||
|
file(GLOB TEMP_OBJ_FILES ${CMAKE_CURRENT_BINARY_DIR}/*.o)
|
||||||
|
set_property(
|
||||||
|
TARGET LibCStatic
|
||||||
|
APPEND
|
||||||
|
PROPERTY ADDITIONAL_CLEAN_FILES ${TEMP_OBJ_FILES}
|
||||||
|
)
|
||||||
|
|
||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libstdc++")
|
||||||
serenity_libc(LibC c)
|
serenity_libc(LibC c)
|
||||||
target_link_libraries(LibC crt0 ssp system)
|
target_link_libraries(LibC crt0 ssp system)
|
||||||
add_dependencies(LibC LibM LibSystem)
|
|
||||||
|
# We mark LibCStatic as a dependency of LibC because this triggers the build of the LibCStatic target
|
||||||
|
add_dependencies(LibC LibM LibSystem LibCStatic)
|
||||||
|
@ -5,3 +5,6 @@ set(SOURCES
|
|||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdlib")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nostdlib")
|
||||||
serenity_libc(LibSystem system)
|
serenity_libc(LibSystem system)
|
||||||
target_include_directories(LibSystem PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
target_include_directories(LibSystem PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
|
||||||
|
add_library(LibSystemStatic STATIC ${SOURCES})
|
||||||
|
target_include_directories(LibSystemStatic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
Loading…
Reference in New Issue
Block a user