From d58b811a34694cbc8b818985e6671132374e22cc Mon Sep 17 00:00:00 2001 From: Alecto Irene Perez Date: Thu, 6 Jun 2024 13:33:38 -0400 Subject: [PATCH 1/3] fix issue #44 - eigen requires at least c++14 support --- examples/cpp/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt index e3f3bbb..3d67a57 100644 --- a/examples/cpp/CMakeLists.txt +++ b/examples/cpp/CMakeLists.txt @@ -1,5 +1,5 @@ # Define a list of target names -set(CPP_EXAMPLES +set(CPP_EXAMPLES example_expcone example_lp example_powcone @@ -14,7 +14,7 @@ set(CPP_EXAMPLES # Define an executable target for each example foreach(EXAMPLE_NAME ${CPP_EXAMPLES}) add_executable("cpp_${EXAMPLE_NAME}" ${EXAMPLE_NAME}.cpp) - target_compile_features("cpp_${EXAMPLE_NAME}" PRIVATE cxx_std_11) # Use C++11 + target_compile_features("cpp_${EXAMPLE_NAME}" PRIVATE cxx_std_14) # Eigen requires at least c++14 support # Link to clarabel built from the Rust wrapper target_link_libraries("cpp_${EXAMPLE_NAME}" PRIVATE libclarabel_c_shared) From 1333c1ad897db1af5493a7e7afdac83093df4518 Mon Sep 17 00:00:00 2001 From: Alecto Irene Perez Date: Thu, 6 Jun 2024 13:34:57 -0400 Subject: [PATCH 2/3] fix issue #45 - specify byproducts Build fails if ninja isn't aware of the byproducts for libclarabel_c --- rust_wrapper/CMakeLists.txt | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/rust_wrapper/CMakeLists.txt b/rust_wrapper/CMakeLists.txt index 14ed1ca..0499b49 100644 --- a/rust_wrapper/CMakeLists.txt +++ b/rust_wrapper/CMakeLists.txt @@ -20,10 +20,10 @@ 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 @@ -31,7 +31,7 @@ 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) @@ -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) @@ -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) @@ -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 @@ -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 From 144af5827f3ff8da1b53fe7a5c7018bf33181f02 Mon Sep 17 00:00:00 2001 From: Alecto Irene Perez Date: Thu, 6 Jun 2024 13:40:12 -0400 Subject: [PATCH 3/3] fix issue #46 - support use via `add_subdirectory` This commit allows Clarabel.cpp to be consumed by other CMake projects via a call to `add_subdirectory`: ```cmake add_subdirectory(path/to/clarabel.cpp) ``` Other projects might have Clarabel.cpp as a git submodule, and this makes it easier to do so. --- CMakeLists.txt | 9 +++++++-- rust_wrapper/CMakeLists.txt | 10 +++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3fd3245..9ed8613 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,11 +12,16 @@ set(CMAKE_CXX_STANDARD_REQUIRED True) set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED True) +# Set the root directory of the project. This is needed +# so that Clarabel.cpp can be consumed by other projects via +# `add_subdirectory` +set(CLARABEL_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") + #---------------------------------------------- # Clarabel feature configuration #---------------------------------------------- set(CLARABEL_FEATURE_SDP "none" CACHE STRING "Package for SDP to be selected") -set_property(CACHE CLARABEL_FEATURE_SDP PROPERTY STRINGS +set_property(CACHE CLARABEL_FEATURE_SDP PROPERTY STRINGS none sdp-accelerate sdp-netlib @@ -55,4 +60,4 @@ option(CLARABEL_BUILD_TESTS "Build the unit tests for Clarabel.cpp" false) if(CLARABEL_BUILD_TESTS) enable_testing() add_subdirectory(tests) -endif() \ No newline at end of file +endif() diff --git a/rust_wrapper/CMakeLists.txt b/rust_wrapper/CMakeLists.txt index 0499b49..fa55493 100644 --- a/rust_wrapper/CMakeLists.txt +++ b/rust_wrapper/CMakeLists.txt @@ -10,10 +10,10 @@ add_library(libclarabel_c_shared INTERFACE) # Debug/Release flags if(CMAKE_BUILD_TYPE MATCHES Release) set(clarabel_c_build_flags "--release") - set(clarabel_c_output_directory "${CMAKE_SOURCE_DIR}/rust_wrapper/target/release") + set(clarabel_c_output_directory "${CLARABEL_ROOT_DIR}/rust_wrapper/target/release") else() set(clarabel_c_build_flags "") - set(clarabel_c_output_directory "${CMAKE_SOURCE_DIR}/rust_wrapper/target/debug") + set(clarabel_c_output_directory "${CLARABEL_ROOT_DIR}/rust_wrapper/target/debug") endif() set(CLARABEL_C_OUTPUT_DIR ${clarabel_c_output_directory} PARENT_SCOPE) @@ -86,7 +86,7 @@ endif() # Add the cargo project as a custom target add_custom_target( libclarabel_c - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/rust_wrapper + WORKING_DIRECTORY ${CLARABEL_ROOT_DIR}/rust_wrapper # Commands for building the Rust library COMMAND cargo build ${clarabel_c_build_flags} COMMAND cargo install cbindgen --version 0.24.5 @@ -104,10 +104,10 @@ add_custom_target( # Static library target_link_libraries(libclarabel_c_static INTERFACE ${LIBCLARABEL_C_STATIC_PATH}) -target_include_directories(libclarabel_c_static INTERFACE ${CMAKE_SOURCE_DIR}/include) +target_include_directories(libclarabel_c_static INTERFACE ${CLARABEL_ROOT_DIR}/include) add_dependencies(libclarabel_c_static libclarabel_c) # Shared library target_link_libraries(libclarabel_c_shared INTERFACE ${LIBCLARABEL_C_SHARED_PATH}) -target_include_directories(libclarabel_c_shared INTERFACE ${CMAKE_SOURCE_DIR}/include) +target_include_directories(libclarabel_c_shared INTERFACE ${CLARABEL_ROOT_DIR}/include) add_dependencies(libclarabel_c_shared libclarabel_c)