diff --git a/bootimgtool/CMakeLists.txt b/bootimgtool/CMakeLists.txt index 56fd2b290..757d511da 100644 --- a/bootimgtool/CMakeLists.txt +++ b/bootimgtool/CMakeLists.txt @@ -49,14 +49,8 @@ foreach(variant ${variants}) ) endif() elseif(${variant} STREQUAL static) - set_target_properties( - ${bin_target} - PROPERTIES - LINK_FLAGS "-static" - LINK_SEARCH_START_STATIC ON - ) - android_link_allow_multiple_definitions(${bin_target}) + unix_link_executable_statically(${bin_target}) endif() # Install binary diff --git a/cmake/CompilerFlags.cmake b/cmake/CompilerFlags.cmake index 9bb3217eb..645521f3b 100644 --- a/cmake/CompilerFlags.cmake +++ b/cmake/CompilerFlags.cmake @@ -230,3 +230,20 @@ function(add_cxx_hack_to_all_targets) endforeach() endif() endfunction() + +function(unix_link_executable_statically first_target) + if(UNIX) + foreach(target "${first_target}" ${ARGN}) + set_property( + TARGET "${target}" + APPEND_STRING + PROPERTY LINK_FLAGS " -static" + ) + set_target_properties( + "${target}" + PROPERTIES + LINK_SEARCH_START_STATIC ON + ) + endforeach() + endif() +endfunction() diff --git a/mbbootui/CMakeLists.txt b/mbbootui/CMakeLists.txt index 6428b4ea6..651ae15a5 100644 --- a/mbbootui/CMakeLists.txt +++ b/mbbootui/CMakeLists.txt @@ -59,14 +59,8 @@ target_include_directories( ${CMAKE_SOURCE_DIR}/external/flatbuffers/include ) -set_target_properties( - mbbootui - PROPERTIES - LINK_FLAGS "-static" - LINK_SEARCH_START_STATIC ON -) - android_link_allow_multiple_definitions(mbbootui) +unix_link_executable_statically(mbbootui) target_link_libraries( mbbootui diff --git a/mbtool/CMakeLists.txt b/mbtool/CMakeLists.txt index b93318cee..be18a93b4 100644 --- a/mbtool/CMakeLists.txt +++ b/mbtool/CMakeLists.txt @@ -142,14 +142,8 @@ if(${MBP_BUILD_TARGET} STREQUAL android-system) -DRECOVERY ) - set_target_properties( - mbtool mbtool_recovery - PROPERTIES - LINK_FLAGS "-static" - LINK_SEARCH_START_STATIC ON - ) - android_link_allow_multiple_definitions(mbtool mbtool_recovery) + unix_link_executable_statically(mbtool mbtool_recovery) target_link_libraries( mbtool-util diff --git a/misc/CMakeLists.txt b/misc/CMakeLists.txt index 93be635e9..b44e44d59 100644 --- a/misc/CMakeLists.txt +++ b/misc/CMakeLists.txt @@ -62,10 +62,11 @@ if(${MBP_BUILD_TARGET} STREQUAL android-system) set_target_properties( fsck-wrapper PROPERTIES - LINK_FLAGS "-static -nostdlib" - LINK_SEARCH_START_STATIC ON + LINK_FLAGS "-nostdlib" ) + unix_link_executable_statically(fsck-wrapper) + install( TARGETS fsck-wrapper RUNTIME DESTINATION "${BIN_INSTALL_DIR}/" diff --git a/odinupdater/CMakeLists.txt b/odinupdater/CMakeLists.txt index 14e5104b5..551fc907b 100644 --- a/odinupdater/CMakeLists.txt +++ b/odinupdater/CMakeLists.txt @@ -2,14 +2,6 @@ if(${MBP_BUILD_TARGET} STREQUAL android-system) add_executable(odinupdater odinupdater.cpp) add_executable(fuse-sparse fuse-sparse.cpp) - set_target_properties( - odinupdater - fuse-sparse - PROPERTIES - LINK_FLAGS "-static" - LINK_SEARCH_START_STATIC ON - ) - target_link_libraries( odinupdater PRIVATE @@ -32,6 +24,7 @@ if(${MBP_BUILD_TARGET} STREQUAL android-system) ) android_link_allow_multiple_definitions(odinupdater fuse-sparse) + unix_link_executable_statically(odinupdater fuse-sparse) install( TARGETS odinupdater fuse-sparse