-
-
Notifications
You must be signed in to change notification settings - Fork 651
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
54 additions
and
49 deletions.
There are no files selected for viewing
Binary file not shown.
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# Check if Rust's package manager, Cargo, is installed | ||
find_program(CARGO cargo) | ||
if (NOT CARGO) | ||
message(FATAL_ERROR "Cargo (Rust package manager) not found. Please install Rust and Cargo to continue.") | ||
endif () | ||
|
||
# Determine the correct library extension based on the operating system | ||
if (${CMAKE_SYSTEM_NAME} MATCHES "Windows") | ||
set(RUST_LIB_EXT "beats.lib") | ||
else () | ||
set(RUST_LIB_EXT "libbeats.a") | ||
endif () | ||
|
||
# Determine the build mode (Release, Debug, or RelWithDebInfo) for Rust compilation | ||
if (CMAKE_BUILD_TYPE MATCHES Debug) | ||
set(RUST_BUILD_FLAG "") | ||
elseif (CMAKE_BUILD_TYPE MATCHES RelWithDebInfo) | ||
set(RUST_BUILD_FLAG "--profile=relwithdebinfo") | ||
elseif (CMAKE_BUILD_TYPE MATCHES Release) | ||
set(RUST_BUILD_FLAG " --release ") | ||
endif () | ||
|
||
# Set base paths for the Rust target directory and full library path | ||
set(RUST_LIB_FULL_PATH ${CMAKE_CURRENT_BINARY_DIR}/beats-rust/${CMAKE_BUILD_TYPE}/${BEATS_LIB_EXT}) | ||
|
||
# Define Rust source files that the compilation depends on | ||
file(GLOB RUST_SOURCE_FILES "${CMAKE_SOURCE_DIR}/beats-rust/src/*.rs") | ||
|
||
# Always compile the Rust library when any .rs file is modified | ||
add_custom_command( | ||
OUTPUT ${RUST_LIB_FULL_PATH} | ||
COMMAND cargo build ${RUST_BUILD_FLAG} --target-dir=${CMAKE_CURRENT_BINARY_DIR}/beats-rust | ||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/beats-rust | ||
DEPENDS ${RUST_SOURCE_FILES} | ||
COMMENT " Compiling the Rust library " | ||
) | ||
|
||
# Add a custom target that depends on the Rust library | ||
add_custom_target( | ||
RustLibTarget ALL | ||
DEPENDS ${RUST_LIB_FULL_PATH} | ||
) | ||
|
||
# Make the main project depend on the custom Rust target | ||
add_dependencies(${PROJECT_NAME} RustLibTarget) |
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,2 +1,4 @@ | ||
/target | ||
/Cargo.lock | ||
*.lib | ||
*.a |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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