Skip to content

Commit

Permalink
Add an option to determine if building all-in-one objects archive
Browse files Browse the repository at this point in the history
  • Loading branch information
wtdcode committed Jan 4, 2025
1 parent 80f0dac commit 996ad57
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 996ad57

Please sign in to comment.