본문으로 건너뛰기

여러 Static 라이브러리를 하나로 묶기

set(STATIC_LIBS lib1 lib2 lib3)

add_custom_target(merged_static_lib ALL DEPENDS ${STATIC_LIBS})

add_custom_command(TARGET merged_static_lib POST_BUILD
COMMAND echo "CREATE libfoo.a" > merge.mri
)

foreach(lib IN LISTS STATIC_LIBS)
add_custom_command(TARGET merged_static_lib POST_BUILD
COMMAND echo "ADDLIB $<TARGET_FILE:${lib}>" >> merge.mri
)
endforeach()

add_custom_command(TARGET merged_static_lib POST_BUILD
COMMAND echo "SAVE" >> merge.mri
COMMAND echo "END" >> merge.mri
COMMAND ar -M < merge.mri
COMMAND rm merge.mri
)