-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- clean target still needs to be fixed Signed-off-by: aw <aw@pionix.de>
- Loading branch information
Showing
4 changed files
with
68 additions
and
49 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,83 @@ | ||
include(cxxrs) | ||
|
||
find_program(CXXBRIDGE cxxbridge PATHS "$ENV{HOME}/.cargo/bin/") | ||
if (CXXBRIDGE STREQUAL "CXXBRIDGE-NOTFOUND") | ||
message("Could not find cxxbridge, trying to install with `cargo install cxxbridge-cmd'") | ||
find_program(CARGO cargo PATHS "$ENV{HOME}/.cargo/bin/") | ||
if (CARGO STREQUAL "CARGO-NOTFOUND") | ||
message(FATAL_ERROR "Requires cargo available in path, install via rustup https://rustup.rs/") | ||
endif() | ||
execute_process(COMMAND ${CARGO} install cxxbridge-cmd --version 1.0.107) | ||
find_program(CXXBRIDGE cxxbridge PATHS "$ENV{HOME}/.cargo/bin/") | ||
endif() | ||
|
||
emit_cxxrs_header() | ||
emit_cxxrs_for_module(everestrs) | ||
set(CXXBRIDGE_BINARY ${CMAKE_CURRENT_BINARY_DIR}/cargo/bin/cxxbridge) | ||
if (NOT EXISTS ${CXXBRIDGE_BINARY}) | ||
message(STATUS "Fetching rust cxxbridge cli tool") | ||
execute_process( | ||
COMMAND | ||
cargo install cxxbridge-cmd --root ${CMAKE_CURRENT_BINARY_DIR}/cargo | ||
WORKING_DIRECTORY | ||
${CMAKE_CURRENT_BINARY_DIR} | ||
RESULT_VARIABLE | ||
CARGO_INSTALL_RESULT | ||
OUTPUT_QUIET | ||
ERROR_VARIABLE | ||
CARGO_INSTALL_ERROR | ||
) | ||
|
||
if (CARGO_INSTALL_RESULT) | ||
message(FATAL_ERROR "cargo install cxxbridge-cmd failed with:\n${CARGO_INSTALL_ERROR}") | ||
endif () | ||
endif () | ||
|
||
set(CXXBRIDGE_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/cxxbridge) | ||
set(EVERESTRS_FFI_HEADER ${CXXBRIDGE_OUTPUT_DIR}/lib.rs.h) | ||
set(EVERESTRS_FFI_SOURCE ${CXXBRIDGE_OUTPUT_DIR}/lib.rs.cc) | ||
set(CXXBRIDGE_HEADER ${CXXBRIDGE_OUTPUT_DIR}/rust.h) | ||
|
||
add_custom_command( | ||
OUTPUT | ||
${CXXBRIDGE_OUTPUT_DIR} | ||
${EVERESTRS_FFI_HEADER} | ||
${EVERESTRS_FFI_SOURCE} | ||
${CXXBRIDGE_HEADER} | ||
COMMAND | ||
${CMAKE_COMMAND} -E make_directory ${CXXBRIDGE_OUTPUT_DIR} | ||
COMMAND | ||
${CXXBRIDGE_BINARY} --header -o ${CXXBRIDGE_HEADER} | ||
COMMAND | ||
${CXXBRIDGE_BINARY} ${CMAKE_CURRENT_SOURCE_DIR}/everestrs/src/lib.rs --header -o ${EVERESTRS_FFI_HEADER} | ||
COMMAND | ||
${CXXBRIDGE_BINARY} ${CMAKE_CURRENT_SOURCE_DIR}/everestrs/src/lib.rs -o ${EVERESTRS_FFI_SOURCE} | ||
DEPENDS | ||
everestrs/src/lib.rs | ||
COMMENT "Generating cxxbridge glue for everestrs" | ||
VERBATIM | ||
DEPENDS | ||
${CXXBRIDGE_BINARY} | ||
) | ||
|
||
add_library(everestrs_sys STATIC | ||
${EVERESTRS_FFI_SOURCE} | ||
everestrs_sys/everestrs_sys.cpp | ||
) | ||
add_library(everest::everestrs_sys ALIAS everestrs_sys) | ||
|
||
set_property( | ||
TARGET | ||
framework | ||
everestrs_sys | ||
PROPERTY | ||
EVERESTRS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/everestrs | ||
) | ||
|
||
# FIXME (aw): this is still broken | ||
# we need a custom target, which does builds the everestrs/lib.rs.h first | ||
# because everestrs_sys depends on it | ||
add_library(everestrs_sys STATIC | ||
${CMAKE_CURRENT_BINARY_DIR}/cxxbridge/everestrs/lib.rs.cc | ||
everestrs_sys/everestrs_sys.cpp | ||
set_property( | ||
TARGET | ||
everestrs_sys | ||
PROPERTY | ||
EVERESTRS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/everestrs | ||
) | ||
|
||
target_include_directories(everestrs_sys PRIVATE | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
${CMAKE_CURRENT_BINARY_DIR}/cxxbridge | ||
target_include_directories(everestrs_sys | ||
PRIVATE | ||
${CMAKE_CURRENT_SOURCE_DIR} | ||
${CMAKE_CURRENT_BINARY_DIR} | ||
) | ||
|
||
# This is a requirement that linking works on systems enforcing PIE. | ||
# This is a requirement that linking works on systems enforcing PIE | ||
# FIXME (aw): investicate why this is really necessary | ||
set_property(TARGET everestrs_sys PROPERTY POSITION_INDEPENDENT_CODE ON) | ||
target_link_libraries(everestrs_sys | ||
PRIVATE | ||
everest::framework | ||
everest::log | ||
everest::framework | ||
everest::log | ||
) | ||
|
||
install(TARGETS everestrs_sys LIBRARY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters