Add an option to determine if building all-in-one objects archive

This commit is contained in:
mio
2025-01-04 17:35:09 +08:00
parent 80f0dac6f0
commit 996ad57e34

View File

@@ -81,6 +81,7 @@ include(cmake/bundle_static.cmake)
# Also we would like users to link a native cmake target, instead of a custom target for better
# compatability.
option(BUILD_SHARED_LIBS "Build shared instead of static library" ${PROJECT_IS_TOP_LEVEL})
option(UNICORN_LEGACY_STATIC_ARCHIVE "Enable Unicorn v1 style all-in-one objects archive for libunicorn.a" ${PROJECT_IS_TOP_LEVEL})
option(UNICORN_FUZZ "Enable fuzzing" OFF)
option(UNICORN_LOGGING "Enable logging" OFF)
option(UNICORN_BUILD_TESTS "Build unicorn tests" ${PROJECT_IS_TOP_LEVEL})
@@ -1442,16 +1443,18 @@ if (BUILD_SHARED_LIBS)
endif()
# Black magic for generating static archives...
if (BUILD_SHARED_LIBS)
if (MSVC)
# Avoid the import lib built by MVSC clash with our archive.
set_target_properties(unicorn PROPERTIES ARCHIVE_OUTPUT_NAME "unicorn-import")
if (UNICORN_LEGACY_STATIC_ARCHIVE)
if (BUILD_SHARED_LIBS)
if (MSVC)
# Avoid the import lib built by MVSC clash with our archive.
set_target_properties(unicorn PROPERTIES ARCHIVE_OUTPUT_NAME "unicorn-import")
endif()
bundle_static_library(unicorn_static unicorn_archive unicorn)
else()
# Rename the "static" lib to avoid filename clash.
set_target_properties(unicorn PROPERTIES OUTPUT_NAME "unicorn-static")
bundle_static_library(unicorn unicorn_archive unicorn)
endif()
bundle_static_library(unicorn_static unicorn_archive unicorn)
else()
# Rename the "static" lib to avoid filename clash.
set_target_properties(unicorn PROPERTIES OUTPUT_NAME "unicorn-static")
bundle_static_library(unicorn unicorn_archive unicorn)
endif()
if(UNICORN_FUZZ)
@@ -1514,8 +1517,10 @@ if(UNICORN_INSTALL AND NOT MSVC)
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()
install(FILES $<TARGET_FILE:unicorn_archive> DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES $<TARGET_FILE_DIR:unicorn_archive>/$<TARGET_PROPERTY:unicorn_archive,SYMLINK_NAME> DESTINATION ${CMAKE_INSTALL_LIBDIR})
if (UNICORN_LEGACY_STATIC_ARCHIVE)
install(FILES $<TARGET_FILE:unicorn_archive> DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES $<TARGET_FILE_DIR:unicorn_archive>/$<TARGET_PROPERTY:unicorn_archive,SYMLINK_NAME> DESTINATION ${CMAKE_INSTALL_LIBDIR})
endif()
install(FILES ${UNICORN_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/unicorn)
if (ATOMIC_LINKAGE_FIX)
set(ATOMIC_LINK_PKG_CONFIG " -latomic")