Refine static libs on Linux/MacOS
This commit is contained in:
@@ -1086,9 +1086,13 @@ if(NOT MSVC AND NOT ANDROID_ABI)
|
|||||||
target_link_libraries(unicorn-common PRIVATE pthread)
|
target_link_libraries(unicorn-common PRIVATE pthread)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_library(unicorn
|
if (BUILD_SHARED_LIBS)
|
||||||
${UNICORN_SRCS}
|
set(UNICORN_LIB_NAME "unicorn")
|
||||||
)
|
else()
|
||||||
|
set(UNICORN_LIB_NAME "unicorn-static") # This static lib is useless and it's just an intermediate target
|
||||||
|
endif()
|
||||||
|
|
||||||
|
add_library(${UNICORN_LIB_NAME} ${UNICORN_SRCS})
|
||||||
|
|
||||||
if(BUILD_SHARED_LIBS)
|
if(BUILD_SHARED_LIBS)
|
||||||
if(ANDROID_ABI)
|
if(ANDROID_ABI)
|
||||||
@@ -1181,7 +1185,7 @@ target_compile_options(unicorn-common PRIVATE
|
|||||||
${UNICORN_COMPILE_OPTIONS}
|
${UNICORN_COMPILE_OPTIONS}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_compile_options(unicorn PRIVATE
|
target_compile_options(${UNICORN_LIB_NAME} PRIVATE
|
||||||
${UNICORN_COMPILE_OPTIONS}
|
${UNICORN_COMPILE_OPTIONS}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1195,24 +1199,29 @@ endif()
|
|||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
if(BUILD_SHARED_LIBS)
|
if(BUILD_SHARED_LIBS)
|
||||||
target_compile_options(unicorn PRIVATE
|
target_compile_options(${UNICORN_LIB_NAME} PRIVATE
|
||||||
-DUNICORN_SHARED
|
-DUNICORN_SHARED
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_link_libraries(unicorn PRIVATE
|
target_link_libraries(${UNICORN_LIB_NAME} PRIVATE
|
||||||
${UNICORN_LINK_LIBRARIES}
|
${UNICORN_LINK_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
set_target_properties(unicorn PROPERTIES
|
set_target_properties(${UNICORN_LIB_NAME} PROPERTIES
|
||||||
VERSION "${UNICORN_VERSION_MAJOR}.${UNICORN_VERSION_MINOR}"
|
VERSION "${UNICORN_VERSION_MAJOR}.${UNICORN_VERSION_MINOR}"
|
||||||
)
|
)
|
||||||
else()
|
else()
|
||||||
target_link_libraries(unicorn PRIVATE
|
target_link_libraries(${UNICORN_LIB_NAME} PRIVATE
|
||||||
${UNICORN_LINK_LIBRARIES}
|
${UNICORN_LINK_LIBRARIES}
|
||||||
m
|
m
|
||||||
)
|
)
|
||||||
set_target_properties(unicorn PROPERTIES
|
|
||||||
|
target_link_libraries(${UNICORN_LIB_NAME} PUBLIC
|
||||||
|
m
|
||||||
|
)
|
||||||
|
|
||||||
|
set_target_properties(${UNICORN_LIB_NAME} PROPERTIES
|
||||||
VERSION ${UNICORN_VERSION_MAJOR}
|
VERSION ${UNICORN_VERSION_MAJOR}
|
||||||
SOVERSION ${UNICORN_VERSION_MAJOR}
|
SOVERSION ${UNICORN_VERSION_MAJOR}
|
||||||
)
|
)
|
||||||
@@ -1233,6 +1242,13 @@ else()
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
target_include_directories(${UNICORN_LIB_NAME} PUBLIC
|
||||||
|
include
|
||||||
|
)
|
||||||
|
|
||||||
|
if (NOT BUILD_SHARED_LIBS)
|
||||||
|
bundle_static_library(${UNICORN_LIB_NAME} unicorn) # Bundle our real unicorn static lib
|
||||||
|
endif()
|
||||||
|
|
||||||
if(UNICORN_FUZZ)
|
if(UNICORN_FUZZ)
|
||||||
set(UNICORN_FUZZ_SUFFIX "arm_arm;arm_armbe;arm_thumb;arm64_arm;arm64_armbe;m68k_be;mips_32be;mips_32le;sparc_32be;x86_16;x86_32;x86_64;s390x_be")
|
set(UNICORN_FUZZ_SUFFIX "arm_arm;arm_armbe;arm_thumb;arm64_arm;arm64_armbe;m68k_be;mips_32be;mips_32le;sparc_32be;x86_16;x86_32;x86_64;s390x_be")
|
||||||
@@ -1277,29 +1293,28 @@ if(UNICORN_BUILD_TESTS)
|
|||||||
endforeach()
|
endforeach()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_include_directories(unicorn PUBLIC
|
|
||||||
include
|
|
||||||
)
|
|
||||||
|
|
||||||
if (NOT BUILD_SHARED_LIBS)
|
|
||||||
bundle_static_library(unicorn unicorn-static)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
if(UNICORN_INSTALL AND NOT MSVC)
|
if(UNICORN_INSTALL AND NOT MSVC)
|
||||||
include("GNUInstallDirs")
|
include("GNUInstallDirs")
|
||||||
file(GLOB UNICORN_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/unicorn/*.h)
|
file(GLOB UNICORN_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/unicorn/*.h)
|
||||||
install(TARGETS unicorn
|
set(config_libs "-lunicorn")
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
if (BUILD_SHARED_LIBS)
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
install(TARGETS unicorn
|
||||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
)
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
install(FILES $<TARGET_FILE:unicorn> DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||||
|
set(config_libs "${config_libs} -lpthread -lm")
|
||||||
|
endif()
|
||||||
install(FILES ${UNICORN_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/unicorn)
|
install(FILES ${UNICORN_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/unicorn)
|
||||||
file(WRITE ${CMAKE_BINARY_DIR}/unicorn.pc "Name: unicorn\n\
|
file(WRITE ${CMAKE_BINARY_DIR}/unicorn.pc "Name: unicorn\n\
|
||||||
Description: Unicorn emulator engine\n\
|
Description: Unicorn emulator engine\n\
|
||||||
Version: ${UNICORN_VERSION_MAJOR}.${UNICORN_VERSION_MINOR}.${UNICORN_VERSION_PATCH}\n\
|
Version: ${UNICORN_VERSION_MAJOR}.${UNICORN_VERSION_MINOR}.${UNICORN_VERSION_PATCH}\n\
|
||||||
libdir=${CMAKE_INSTALL_FULL_LIBDIR}\n\
|
libdir=${CMAKE_INSTALL_FULL_LIBDIR}\n\
|
||||||
includedir=${CMAKE_INSTALL_FULL_INCLUDEDIR}\n\
|
includedir=${CMAKE_INSTALL_FULL_INCLUDEDIR}\n\
|
||||||
Libs: -L\$\{libdir\} -lunicorn\n\
|
Libs: -L\$\{libdir\} ${config_libs}\n\
|
||||||
Cflags: -I\$\{includedir\}\n"
|
Cflags: -I\$\{includedir\}\n"
|
||||||
)
|
)
|
||||||
install(FILES ${CMAKE_BINARY_DIR}/unicorn.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
install(FILES ${CMAKE_BINARY_DIR}/unicorn.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||||
|
|||||||
@@ -26,14 +26,18 @@ function(bundle_static_library tgt_name bundled_tgt_name)
|
|||||||
set_property(GLOBAL PROPERTY _${tgt_name}_static_bundle_${dependency} ON)
|
set_property(GLOBAL PROPERTY _${tgt_name}_static_bundle_${dependency} ON)
|
||||||
_recursively_collect_dependencies(${dependency})
|
_recursively_collect_dependencies(${dependency})
|
||||||
endif()
|
endif()
|
||||||
|
else()
|
||||||
|
list(APPEND dep_libs ${dependency})
|
||||||
endif()
|
endif()
|
||||||
endforeach()
|
endforeach()
|
||||||
set(static_libs ${static_libs} PARENT_SCOPE)
|
set(static_libs ${static_libs} PARENT_SCOPE)
|
||||||
|
set(dep_libs ${dep_libs} PARENT_SCOPE)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
_recursively_collect_dependencies(${tgt_name})
|
_recursively_collect_dependencies(${tgt_name})
|
||||||
|
|
||||||
list(REMOVE_DUPLICATES static_libs)
|
list(REMOVE_DUPLICATES static_libs)
|
||||||
|
list(REMOVE_DUPLICATES dep_libs)
|
||||||
|
|
||||||
set(bundled_tgt_full_name
|
set(bundled_tgt_full_name
|
||||||
${CMAKE_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${bundled_tgt_name}${CMAKE_STATIC_LIBRARY_SUFFIX})
|
${CMAKE_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${bundled_tgt_name}${CMAKE_STATIC_LIBRARY_SUFFIX})
|
||||||
@@ -99,7 +103,9 @@ function(bundle_static_library tgt_name bundled_tgt_name)
|
|||||||
set_target_properties(${bundled_tgt_name}
|
set_target_properties(${bundled_tgt_name}
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
IMPORTED_LOCATION ${bundled_tgt_full_name}
|
IMPORTED_LOCATION ${bundled_tgt_full_name}
|
||||||
INTERFACE_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:${tgt_name},INTERFACE_INCLUDE_DIRECTORIES>)
|
INTERFACE_INCLUDE_DIRECTORIES $<TARGET_PROPERTY:${tgt_name},INTERFACE_INCLUDE_DIRECTORIES>
|
||||||
|
INTERFACE_LINK_LIBRARIES "${dep_libs}")
|
||||||
|
#IMPORTED_LINK_INTERFACE_LIBRARIES "${dep_libs}") # Deprecated
|
||||||
add_dependencies(${bundled_tgt_name} bundling_target)
|
add_dependencies(${bundled_tgt_name} bundling_target)
|
||||||
|
|
||||||
endfunction()
|
endfunction()
|
||||||
Reference in New Issue
Block a user