Skip to content

Commit

Permalink
cmake: Move static executable linking logic to separate function
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Gunnerson <[email protected]>
  • Loading branch information
chenxiaolong committed Jul 3, 2018
1 parent e8073b5 commit 5fc1a07
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 31 deletions.
8 changes: 1 addition & 7 deletions bootimgtool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions cmake/CompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
8 changes: 1 addition & 7 deletions mbbootui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions mbtool/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions misc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}/"
Expand Down
9 changes: 1 addition & 8 deletions odinupdater/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5fc1a07

Please sign in to comment.