From eef93b932844110cf19a4b2741b528623b77998e Mon Sep 17 00:00:00 2001 From: Josh Ferrell Date: Mon, 1 Sep 2025 17:47:08 -0400 Subject: Add option to build rust api without linking to core --- CMakeLists.txt | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index 904fcf4f..3a28b964 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,33 +39,22 @@ if(BinaryNinjaCore_FOUND) target_link_directories(binaryninjaapi PUBLIC ${BinaryNinjaCore_LIBRARY_DIRS}) target_compile_definitions(binaryninjaapi PUBLIC ${BinaryNinjaCore_DEFINITIONS}) else() + add_subdirectory(stubs EXCLUDE_FROM_ALL) + + # Be sure to only link against the stubs archive file + add_dependencies(binaryninjaapi binaryninjacore_stubs) + if(APPLE) - target_link_options(binaryninjaapi PUBLIC -undefined dynamic_lookup) + target_link_libraries(binaryninjaapi PUBLIC "$/$.dylib") elseif(MSVC) - # Generate stubs.cpp with implementations of all the BNAPI functions - execute_process(COMMAND python ${PROJECT_SOURCE_DIR}/cmake/generate_stubs.py ${PROJECT_SOURCE_DIR}/binaryninjacore.h ${PROJECT_BINARY_DIR}/stubs) - - # Compile those stubs into a stub library we can use to fool the linker - add_library(binaryninjacore SHARED ${PROJECT_BINARY_DIR}/stubs/stubs.cpp) - set_target_properties(binaryninjacore - PROPERTIES OUTPUT_NAME binaryninjacore - SOVERSION 1 - ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/stubs - LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/stubs - RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/stubs - ) - target_include_directories(binaryninjacore PUBLIC ${PROJECT_SOURCE_DIR}) - - # Be sure to only link against the stubs archive file - add_dependencies(binaryninjaapi binaryninjacore) if(${CMAKE_GENERATOR} MATCHES "^Visual Studio") # Visual Studio's generator adds the config to the file path - target_link_libraries(binaryninjaapi PUBLIC "$/$/$.lib") + target_link_libraries(binaryninjaapi PUBLIC "$/$/$.lib") else() - target_link_libraries(binaryninjaapi PUBLIC "$/$.lib") + target_link_libraries(binaryninjaapi PUBLIC "$/$.lib") endif() else() - target_link_options(binaryninjaapi PUBLIC "LINKER:--allow-shlib-undefined") + target_link_libraries(binaryninjaapi PUBLIC "$/$.so.1") endif() endif() -- cgit v1.3.1