Skip to content

Commit

Permalink
fix issue oxfordcontrol#45 - specify byproducts
Browse files Browse the repository at this point in the history
Build fails if ninja isn't aware of the byproducts for libclarabel_c
  • Loading branch information
codeinred committed Jun 6, 2024
1 parent d58b811 commit 1333c1a
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions rust_wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ set(CLARABEL_C_OUTPUT_DIR ${clarabel_c_output_directory} PARENT_SCOPE)


# -------------------------------------
# Cargo features configuration
# Cargo features configuration
#--------------------------------------

# A list of features to pass to rustc
# A list of features to pass to rustc
set(CLARABEL_BUILD_FEATURES "")

# SDP feature flag
if(NOT CLARABEL_FEATURE_SDP STREQUAL "none")

# Set the Rust feature flag
set(CLARABEL_BUILD_FEATURES "${CLARABEL_BUILD_FEATURES},${CLARABEL_FEATURE_SDP}")

# Define the FEATURE_SDP flag for all targets that link against clarabel_c
target_compile_definitions(libclarabel_c_static INTERFACE FEATURE_SDP)
target_compile_definitions(libclarabel_c_shared INTERFACE FEATURE_SDP)
Expand All @@ -42,7 +42,7 @@ if(CLARABEL_FEATURE_FAER_SPARSE)

# Set the Rust feature flag
set(CLARABEL_BUILD_FEATURES "${CLARABEL_BUILD_FEATURES},faer-sparse")

# Define the FEATURE_FAER_SPARSE flag for all targets that link against clarabel_c
target_compile_definitions(libclarabel_c_static INTERFACE FEATURE_FAER_SPARSE)
target_compile_definitions(libclarabel_c_shared INTERFACE FEATURE_FAER_SPARSE)
Expand All @@ -53,7 +53,7 @@ if(CLARABEL_FEATURE_SERDE)

# Set the Rust feature flag
set(CLARABEL_BUILD_FEATURES "${CLARABEL_BUILD_FEATURES},serde")

# Define the FEATURE_SERDE flag for all targets that link against clarabel_c
target_compile_definitions(libclarabel_c_static INTERFACE FEATURE_SERDE)
target_compile_definitions(libclarabel_c_shared INTERFACE FEATURE_SERDE)
Expand All @@ -70,6 +70,19 @@ message("-- Cargo options: " "${clarabel_c_build_flags}")
# -------------------------------------


# Get the path to the Rust library for linking
if(APPLE)
set(LIBCLARABEL_C_SHARED_PATH "${clarabel_c_output_directory}/libclarabel_c.dylib")
set(LIBCLARABEL_C_STATIC_PATH "${clarabel_c_output_directory}/libclarabel_c.a")
elseif(UNIX)
set(LIBCLARABEL_C_SHARED_PATH "${clarabel_c_output_directory}/libclarabel_c.so")
set(LIBCLARABEL_C_STATIC_PATH "${clarabel_c_output_directory}/libclarabel_c.a")
elseif(WIN32)
set(LIBCLARABEL_C_SHARED_PATH "${clarabel_c_output_directory}/clarabel_c.dll.lib")
set(LIBCLARABEL_C_STATIC_PATH "${clarabel_c_output_directory}/clarabel_c.lib")
endif()


# Add the cargo project as a custom target
add_custom_target(
libclarabel_c
Expand All @@ -81,19 +94,11 @@ add_custom_target(
COMMAND cbindgen --config cbindgen.toml --crate clarabel_c --output ./headers/clarabel.h --lang c
# Generate the C++ header
COMMAND cbindgen --config cbindgen.toml --crate clarabel_c --output ./headers/clarabel.hpp
BYPRODUCTS
"${LIBCLARABEL_C_SHARED_PATH}"
"${LIBCLARABEL_C_STATIC_PATH}"
)

# Get the path to the Rust library for linking
if(APPLE)
set(LIBCLARABEL_C_SHARED_PATH "${clarabel_c_output_directory}/libclarabel_c.dylib")
set(LIBCLARABEL_C_STATIC_PATH "${clarabel_c_output_directory}/libclarabel_c.a")
elseif(UNIX)
set(LIBCLARABEL_C_SHARED_PATH "${clarabel_c_output_directory}/libclarabel_c.so")
set(LIBCLARABEL_C_STATIC_PATH "${clarabel_c_output_directory}/libclarabel_c.a")
elseif(WIN32)
set(LIBCLARABEL_C_SHARED_PATH "${clarabel_c_output_directory}/clarabel_c.dll.lib")
set(LIBCLARABEL_C_STATIC_PATH "${clarabel_c_output_directory}/clarabel_c.lib")
endif()

# Wrap the Rust library in a CMake library target

Expand Down

0 comments on commit 1333c1a

Please sign in to comment.