diff --git a/bundle_static.cmake b/bundle_static.cmake index c7f06c7d..0d7f91a9 100644 --- a/bundle_static.cmake +++ b/bundle_static.cmake @@ -38,33 +38,45 @@ function(bundle_static_library tgt_name bundled_tgt_name) set(bundled_tgt_full_name ${CMAKE_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${bundled_tgt_name}${CMAKE_STATIC_LIBRARY_SUFFIX}) - if (UNIX OR APPLE) + if (APPLE) + find_program(lib_tool libtool) + + foreach(tgt IN LISTS static_libs) + list(APPEND static_libs_full_names $) + endforeach() + + add_custom_command( + COMMAND ${lib_tool} -static -o ${bundled_tgt_full_name} ${static_libs_full_names} + OUTPUT ${bundled_tgt_full_name} + COMMENT "Bundling ${bundled_tgt_name}" + VERBATIM) + elseif(UNIX) file(WRITE ${CMAKE_BINARY_DIR}/${bundled_tgt_name}.ar.in - "CREATE ${bundled_tgt_full_name}\n" ) + "CREATE ${bundled_tgt_full_name}\n" ) foreach(tgt IN LISTS static_libs) - file(APPEND ${CMAKE_BINARY_DIR}/${bundled_tgt_name}.ar.in + file(APPEND ${CMAKE_BINARY_DIR}/${bundled_tgt_name}.ar.in "ADDLIB $\n") endforeach() - + file(APPEND ${CMAKE_BINARY_DIR}/${bundled_tgt_name}.ar.in "SAVE\n") file(APPEND ${CMAKE_BINARY_DIR}/${bundled_tgt_name}.ar.in "END\n") file(GENERATE - OUTPUT ${CMAKE_BINARY_DIR}/${bundled_tgt_name}.ar - INPUT ${CMAKE_BINARY_DIR}/${bundled_tgt_name}.ar.in) + OUTPUT ${CMAKE_BINARY_DIR}/${bundled_tgt_name}.ar + INPUT ${CMAKE_BINARY_DIR}/${bundled_tgt_name}.ar.in) set(ar_tool ${CMAKE_AR}) if (CMAKE_INTERPROCEDURAL_OPTIMIZATION) - set(ar_tool ${CMAKE_CXX_COMPILER_AR}) + set(ar_tool ${CMAKE_CXX_COMPILER_AR}) endif() add_custom_command( - COMMAND ${ar_tool} -M < ${CMAKE_BINARY_DIR}/${bundled_tgt_name}.ar - OUTPUT ${bundled_tgt_full_name} - COMMENT "Bundling ${bundled_tgt_name}" - VERBATIM) - elseif(MSVC) + COMMAND ${ar_tool} -M < ${CMAKE_BINARY_DIR}/${bundled_tgt_name}.ar + OUTPUT ${bundled_tgt_full_name} + COMMENT "Bundling ${bundled_tgt_name}" + VERBATIM) + elseif(WIN32) find_program(lib_tool lib) foreach(tgt IN LISTS static_libs)