cmake: add option to build unicorn as a static library (#1275)

This commit is contained in:
scribam
2020-05-31 18:00:07 +02:00
committed by GitHub
parent 99be837364
commit 582e6968fd

View File

@ -21,6 +21,8 @@ set(UNICORN_VERSION_MAJOR 1)
set(UNICORN_VERSION_MINOR 0) set(UNICORN_VERSION_MINOR 0)
set(UNICORN_VERSION_PATCH 2) set(UNICORN_VERSION_PATCH 2)
option(UNICORN_BUILD_SHARED "Build shared instead of static library" ON)
if(NOT UNICORN_ARCH) if(NOT UNICORN_ARCH)
# build all architectures # build all architectures
set(UNICORN_ARCH "x86 arm aarch64 m68k mips sparc") set(UNICORN_ARCH "x86 arm aarch64 m68k mips sparc")
@ -830,9 +832,15 @@ else()
) )
endif() endif()
add_library(unicorn SHARED if (UNICORN_BUILD_SHARED)
${UNICORN_SRCS} add_library(unicorn SHARED
) ${UNICORN_SRCS}
)
else()
add_library(unicorn STATIC
${UNICORN_SRCS}
)
endif()
if (UNICORN_HAS_X86) if (UNICORN_HAS_X86)
set(UNICRON_COMPILE_OPTIONS ${UNICRON_COMPILE_OPTIONS} -DUNICORN_HAS_X86) set(UNICRON_COMPILE_OPTIONS ${UNICRON_COMPILE_OPTIONS} -DUNICORN_HAS_X86)
@ -865,19 +873,21 @@ if (UNICORN_HAS_SPARC)
set(UNICRON_SAMPLE_FILE ${UNICRON_SAMPLE_FILE} sample_sparc) set(UNICRON_SAMPLE_FILE ${UNICRON_SAMPLE_FILE} sample_sparc)
endif() endif()
target_compile_options(unicorn PRIVATE
${UNICRON_COMPILE_OPTIONS}
)
if(MSVC) if(MSVC)
target_compile_options(unicorn PRIVATE if (UNICORN_BUILD_SHARED)
${UNICRON_COMPILE_OPTIONS} target_compile_options(unicorn PRIVATE
-DUNICORN_SHARED -DUNICORN_SHARED
) )
endif()
target_link_libraries(unicorn target_link_libraries(unicorn
${UNICRON_LINK_LIBRARIES} ${UNICRON_LINK_LIBRARIES}
) )
else() else()
target_compile_options(unicorn PRIVATE
${UNICRON_COMPILE_OPTIONS}
)
target_link_libraries(unicorn target_link_libraries(unicorn
${UNICRON_LINK_LIBRARIES} ${UNICRON_LINK_LIBRARIES}
m m