diff options
author | Tim Schumacher <timschumi@gmx.de> | 2022-10-22 15:13:49 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-11-01 14:49:09 +0000 |
commit | 7834e26ddb6f0205b8a4688b5df339f50803cc48 (patch) | |
tree | d9340b20dc2d8cfada26feab06cddca015e25c39 /Meta/CMake | |
parent | 39fca21e11889481b32f805a26e48fec73b4b9d0 (diff) | |
download | serenity-7834e26ddb6f0205b8a4688b5df339f50803cc48.zip |
Everywhere: Explicitly link all binaries against the LibC target
Even though the toolchain implicitly links against -lc, it does not know
where it should get LibC from except for the sysroot. In the case of
Clang this causes it to pick up the LibC stub instead, which might be
slightly outdated and feature missing symbols.
This is currently not an issue that manifests because we pass through
the dependency on LibC and other libraries by accident, which causes
CMake to link against the LibC target (instead of just the library),
and thus points the linker at the build output directory.
Since we are looking to fix that in the upcoming commits, let's make
sure that everything will still be able to find the proper LibC first.
Diffstat (limited to 'Meta/CMake')
-rw-r--r-- | Meta/CMake/utils.cmake | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Meta/CMake/utils.cmake b/Meta/CMake/utils.cmake index b35493ee94..1a524287e5 100644 --- a/Meta/CMake/utils.cmake +++ b/Meta/CMake/utils.cmake @@ -2,6 +2,15 @@ include(${CMAKE_CURRENT_LIST_DIR}/serenity_components.cmake) include(${CMAKE_CURRENT_LIST_DIR}/code_generators.cmake) +function(serenity_set_implicit_links target_name) + # Make sure that CMake is aware of the implicit LibC dependency, and ensure + # that we are choosing the correct and updated LibC. + # The latter is a problem with Clang especially, since we might have the + # slightly outdated stub in the sysroot, but have not yet installed the freshly + # built LibC. + target_link_libraries(${target_name} LibC) +endfunction() + function(serenity_install_headers target_name) file(GLOB_RECURSE headers RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "*.h") foreach(header ${headers}) @@ -43,6 +52,7 @@ if (NOT COMMAND serenity_lib) install(TARGETS ${target_name} DESTINATION ${CMAKE_INSTALL_LIBDIR} OPTIONAL) set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name}) serenity_generated_sources(${target_name}) + serenity_set_implicit_links(${target_name}) endfunction() endif() @@ -56,6 +66,7 @@ if (NOT COMMAND serenity_lib_static) install(TARGETS ${target_name} DESTINATION ${CMAKE_INSTALL_LIBDIR} OPTIONAL) set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${fs_name}) serenity_generated_sources(${target_name}) + serenity_set_implicit_links(${target_name}) endfunction() endif() @@ -80,6 +91,7 @@ if (NOT COMMAND serenity_bin) set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL TRUE) install(TARGETS ${target_name} RUNTIME DESTINATION bin OPTIONAL) serenity_generated_sources(${target_name}) + serenity_set_implicit_links(${target_name}) endfunction() endif() @@ -96,6 +108,7 @@ function(serenity_test test_src sub_dir) add_executable(${test_name} ${TEST_SOURCES}) add_dependencies(ComponentTests ${test_name}) set_target_properties(${test_name} PROPERTIES EXCLUDE_FROM_ALL TRUE) + serenity_set_implicit_links(${test_name}) target_link_libraries(${test_name} LibTest LibCore) foreach(lib ${SERENITY_TEST_LIBS}) target_link_libraries(${test_name} ${lib}) |