ImHex/plugins/example_rust/CMakeLists.txt

44 lines
1.7 KiB
CMake
Raw Normal View History

build/plugins: Added initial support for Rust plugins (#327) * build: Added initial support for Rust plugins * github: Install correct rust version * github: Fixed rustup command * github: Fix swapped win/linux commands * github: Install linux rust toolchain on Linux * github: Add rustup parameters to correct command * build: libimhex-rust -> hex * rust-plugins: Disable optimization to export functions correctly * build: Use cdylib instead of dylib * build: Fixed rust building and artifact copying * build: Fixed installing plugins * build: Fix copying and installing on Windows * github: Added windows debugging * github: Use curl instead of wget * github: Added debug on failure * github: Update path variable with rust toolchain path * build/github: Set rust location so cmake can find it * build: Remove leftovers * api: Added rust wrappers for the ImHexAPI * rust: Fixed compile flags with older gcc/clang * build: Enable concepts for cxx.rs * build: Explicitly set compiler for cxx.rs * rust: Added imgui-rs to libimhex-rust * rust: Export functions with double underscore prefix on mac * rust: Export functions adjusted for ABI * Add Rust target folder to gitignore * Add vendored imgui-rs copy * Add Context::current() to vendored imgui-rs * Fix libimhex not exporting cimgui symbols * Simplify plugin export mangling * build: Fixed cimgui linking * build: Only specify --export-all-symbols on Windows * Add context setting to Rust plugins * rust: Cleanup * deps: Update curl Co-authored-by: jam1garner <8260240+jam1garner@users.noreply.github.com>
2021-10-16 09:37:29 +00:00
cmake_minimum_required(VERSION 3.16)
# Change this to the name of your plugin #
project(example_rust)
# ---- No need to change anything from here downwards unless you know what you're doing ---- #
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CARGO_CMD ${RUST_PATH}cargo build)
set(TARGET_DIR "debug")
else ()
set(CARGO_CMD ${RUST_PATH}cargo build --release)
set(TARGET_DIR "release")
endif ()
if (WIN32)
set(PLUGIN_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/${TARGET_DIR}/${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}")
else ()
set(PLUGIN_OUTPUT_PATH "${CMAKE_CURRENT_BINARY_DIR}/${TARGET_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${PROJECT_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}")
endif ()
get_target_property(LIBIMHEX_SOURCE_DIRECTORY libimhex SOURCE_DIR)
add_custom_target(${PROJECT_NAME} ALL
COMMAND ${CMAKE_COMMAND} -E env
CARGO_TARGET_DIR=${CMAKE_CURRENT_BINARY_DIR}
LIBIMHEX_SOURCE_DIRECTORY=${LIBIMHEX_SOURCE_DIRECTORY}
LIBIMHEX_OUTPUT_DIRECTORY=$<TARGET_FILE_DIR:libimhex>
CXX_COMPILER=${CMAKE_CXX_COMPILER}
${CARGO_CMD}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${PLUGIN_OUTPUT_PATH} "${CMAKE_CURRENT_BINARY_DIR}/../${PROJECT_NAME}.hexplug"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
VERBATIM
USES_TERMINAL
)
set_target_properties(${PROJECT_NAME} PROPERTIES LOCATION ${CMAKE_CURRENT_BINARY_DIR})
set_target_properties(${PROJECT_NAME} PROPERTIES RUST_PROJECT 1)
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE Rust)
add_compile_definitions(IMHEX_PLUGIN_NAME=${PROJECT_NAME})
if (NOT TARGET libimhex)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../libimhex ${CMAKE_CURRENT_BINARY_DIR}/plugins/libimhex)
endif()