diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c389bc34f..dd3e347689 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1515,6 +1515,7 @@ if(UNICORN_INSTALL AND NOT MSVC) ) endif() install(FILES $ DESTINATION ${CMAKE_INSTALL_LIBDIR}) + install(FILES $/$ DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(FILES ${UNICORN_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/unicorn) if (ATOMIC_LINKAGE_FIX) set(ATOMIC_LINK_PKG_CONFIG " -latomic") diff --git a/bindings/go/unicorn/cgo.go b/bindings/go/unicorn/cgo.go new file mode 100644 index 0000000000..88ea004fb6 --- /dev/null +++ b/bindings/go/unicorn/cgo.go @@ -0,0 +1,4 @@ +package unicorn + +// #cgo CFLAGS: -I../../../include -O3 -Wall -Werror +import "C" diff --git a/bindings/go/unicorn/cgo_dynamic.go b/bindings/go/unicorn/cgo_dynamic.go new file mode 100644 index 0000000000..49c3b8cf07 --- /dev/null +++ b/bindings/go/unicorn/cgo_dynamic.go @@ -0,0 +1,6 @@ +//go:build !static + +package unicorn + +// #cgo LDFLAGS: -lunicorn +import "C" diff --git a/bindings/go/unicorn/cgo_static.go b/bindings/go/unicorn/cgo_static.go new file mode 100644 index 0000000000..72cf081dac --- /dev/null +++ b/bindings/go/unicorn/cgo_static.go @@ -0,0 +1,7 @@ +//go:build static + +package unicorn + +// #cgo !darwin LDFLAGS: -lunicorn -lpthread -lm -latomic +// #cgo darwin LDFLAGS: -lunicorn.o +import "C" diff --git a/bindings/go/unicorn/unicorn.go b/bindings/go/unicorn/unicorn.go index 50b221adaa..802c816367 100644 --- a/bindings/go/unicorn/unicorn.go +++ b/bindings/go/unicorn/unicorn.go @@ -7,9 +7,6 @@ import ( ) /* -#cgo CFLAGS: -O3 -Wall -Werror -I../../../include -#cgo LDFLAGS: -L../../../ -lunicorn -Wl,-rpath,${SRCDIR}/../../../ -#cgo linux LDFLAGS: -L../../../ -lunicorn -lrt -Wl,-rpath,${SRCDIR}/../../../ #include #include "uc.h" */ diff --git a/bindings/python/setup.py b/bindings/python/setup.py index 2b3797a8a3..534be5a482 100755 --- a/bindings/python/setup.py +++ b/bindings/python/setup.py @@ -113,7 +113,7 @@ def build_libraries(): obj_dir = os.path.join(BUILD_DIR, conf) shutil.copy(os.path.join(obj_dir, LIBRARY_FILE), LIBS_DIR) - shutil.copy(os.path.join(BUILD_DIR, STATIC_LIBRARY_FILE), LIBS_DIR) + shutil.copy(os.path.join(obj_dir, STATIC_LIBRARY_FILE), LIBS_DIR) else: cmake_args = ["cmake", '-B', BUILD_DIR, '-S', UC_DIR, "-DCMAKE_BUILD_TYPE=" + conf] if os.getenv("TRACE"): diff --git a/cmake/bundle_static.cmake b/cmake/bundle_static.cmake index 613f832c67..0123fe65b0 100644 --- a/cmake/bundle_static.cmake +++ b/cmake/bundle_static.cmake @@ -40,76 +40,18 @@ function(bundle_static_library tgt_name bundled_tgt_name library_name) list(REMOVE_DUPLICATES static_libs) list(REMOVE_DUPLICATES dep_libs) - set(bundled_tgt_full_name - ${CMAKE_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${library_name}${CMAKE_STATIC_LIBRARY_SUFFIX}) - - if (APPLE) - find_program(lib_tool libtool REQUIRED) - - 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 OR MINGW) - file(WRITE ${CMAKE_BINARY_DIR}/${bundled_tgt_name}.ar.in - "CREATE ${bundled_tgt_full_name}\n" ) - - foreach(tgt IN LISTS static_libs) - 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) - - set(ar_tool ${CMAKE_AR}) - if (CMAKE_INTERPROCEDURAL_OPTIMIZATION) - 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(WIN32) - # https://stackoverflow.com/a/38096930/1806760 - get_filename_component(vs_bin_path "${CMAKE_LINKER}" DIRECTORY) - - find_program(lib_tool lib HINTS "${vs_bin_path}" REQUIRED) - - foreach(tgt IN LISTS static_libs) - list(APPEND static_libs_full_names $) - endforeach() - - add_custom_command( - COMMAND ${lib_tool} /NOLOGO /OUT:${bundled_tgt_full_name} ${static_libs_full_names} - OUTPUT ${bundled_tgt_full_name} - COMMENT "Bundling ${bundled_tgt_name}" - VERBATIM) - else() - message(FATAL_ERROR "Unknown bundle scenario!") - endif() - - add_custom_target(bundling_target ALL DEPENDS ${bundled_tgt_full_name}) - add_dependencies(bundling_target ${tgt_name}) - - add_library(${bundled_tgt_name} STATIC IMPORTED) - set_target_properties(${bundled_tgt_name} - PROPERTIES - IMPORTED_LOCATION ${bundled_tgt_full_name} - INTERFACE_INCLUDE_DIRECTORIES $ - INTERFACE_LINK_LIBRARIES "${dep_libs}") - #IMPORTED_LINK_INTERFACE_LIBRARIES "${dep_libs}") # Deprecated - add_dependencies(${bundled_tgt_name} bundling_target) - -endfunction() \ No newline at end of file + foreach(tgt IN LISTS static_libs) + list(APPEND static_libs_objects $) + endforeach() + + add_library(${bundled_tgt_name} STATIC ${static_libs_objects}) + set_target_properties(${bundled_tgt_name} PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES $ + INTERFACE_LINK_LIBRARIES "${dep_libs}" + OUTPUT_NAME "${library_name}" + SYMLINK_NAME "${library_name}.o" + ) + add_custom_command(TARGET ${bundled_tgt_name} POST_BUILD + COMMAND ${CMAKE_COMMAND} -E create_symlink "$" "$/$" + ) +endfunction()