BuildRequires: pkgconfig(hal-api-device)
BuildRequires: libtar-devel
BuildRequires: gtest-devel
+BuildRequires: glibc-devel-static
+BuildRequires: zlib-devel-static
Requires: upgrade-engine = %{version}-%{release}
Requires: parse-dynparts = %{version}-%{release}
find_package(PkgConfig)
-pkg_check_modules(DEPS REQUIRED IMPORTED_TARGET zlib)
-ADD_DEFINITIONS("-D_FILE_OFFSET_BITS=64")
+add_definitions("-D_FILE_OFFSET_BITS=64")
set(
upgrade-apply_SRCS
patch/brotli.c
sha1/sha1.c
)
+
add_executable(upgrade-apply ${upgrade-apply_SRCS})
-target_link_libraries(upgrade-apply PRIVATE PkgConfig::DEPS)
-# Unfortunately, libtar is neither CMake- nor pkgconfig-aware.
-# Even more unfortunately, pkgconfig detection of static libraries is broken for all version of CMake before 3.24,
-# and as of writing 3.24 is not even released yet (see https://gitlab.kitware.com/cmake/cmake/-/merge_requests/7070).
-# This would require a bit of hacking (but also libc.a) if we wanted full static linking,
-# but here we need something even different: static linking for all but libc.
-# This requires especially brutal hacks. Maybe we should use Meson next time? ;)
-# In the meantime, TODO: make this better.
-# Also, note that zlib has been used in the normal way (i.e. with dynamic linking).
-# That's because the current setup does have libz.so in the execution environment.
-# Though in the future, it might be good to make it consistent (TODO).
if(DEFINE_HOST_BUILD)
-set(ADD_LIBS libbrotlidec.a libbrotlicommon.a)
+ target_link_libraries(upgrade-apply PRIVATE libtar.a libz.a libbrotlidec.a libbrotlicommon.a)
else()
-set(ADD_LIBS libbrotlidec-static.a libbrotlicommon-static.a)
+ # Without this cmake inserts `-Bdynamic` at the end of link command, and the binary isn't fully static
+ set_target_properties(upgrade-apply PROPERTIES
+ LINK_SEARCH_START_STATIC ON
+ LINK_SEARCH_END_STATIC ON
+ )
+
+ target_link_options(upgrade-apply PRIVATE "-static")
+
+ target_link_libraries(upgrade-apply PRIVATE libtar.a libz.a libbrotlidec-static.a libbrotlicommon-static.a)
endif()
-target_link_libraries(upgrade-apply PRIVATE libtar.a ${ADD_LIBS})
-install(TARGETS upgrade-apply)
+install(TARGETS upgrade-apply)
\ No newline at end of file