Skip to content

Commit

Permalink
Merge pull request Homebrew#163921 from chenrui333/osqp-cmake
Browse files Browse the repository at this point in the history
osqp: use modern cmake syntax
  • Loading branch information
p-linnane authored Feb 23, 2024
2 parents 77ccdad + 9953ece commit 723ac6e
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions Formula/o/osqp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,32 @@ def install
# Install qdldl git submodule not included in release source archive.
(buildpath/"lin_sys/direct/qdldl/qdldl_sources").install resource("qdldl")

args = *std_cmake_args + %w[
-DENABLE_MKL_PARDISO=OFF
]

mkdir "build" do
system "cmake", *args, ".."
system "make"
system "make", "install"
end
system "cmake", "-S", ".", "-B", "build", "-DENABLE_MKL_PARDISO=OFF", *std_cmake_args
system "cmake", "--build", "build"
system "cmake", "--install", "build"

# Remove unnecessary qdldl install.
rm_rf include/"qdldl"
rm_rf lib/"cmake/qdldl"
rm lib/"libqdldl.a"
rm lib/shared_library("libqdldl")
rm_rf Dir[include/"qdldl", lib/"cmake/qdldl", lib/"libqdldl.a", lib/shared_library("libqdldl")]
end

test do
(testpath/"CMakeLists.txt").write <<~EOS
cmake_minimum_required(VERSION 3.2 FATAL_ERROR)
project(osqp_demo LANGUAGES C)
find_package(osqp CONFIG REQUIRED)
add_executable(osqp_demo osqp_demo.c)
target_link_libraries(osqp_demo PRIVATE osqp::osqp -lm)
add_executable(osqp_demo_static osqp_demo.c)
target_link_libraries(osqp_demo_static PRIVATE osqp::osqpstatic -lm)
EOS

# from https://github.com/osqp/osqp/blob/HEAD/tests/demo/test_demo.h
(testpath/"osqp_demo.c").write <<~EOS
#include <assert.h>
#include <osqp.h>
int main() {
c_float P_x[3] = { 4.0, 1.0, 2.0, };
c_int P_nnz = 3;
Expand Down Expand Up @@ -98,9 +93,10 @@ def install
return 0;
}
EOS
system "cmake", "."
system "make"
system "./osqp_demo"
system "./osqp_demo_static"

system "cmake", "-S", ".", "-B", "build"
system "cmake", "--build", "build"
system "./build/osqp_demo"
system "./build/osqp_demo_static"
end
end

0 comments on commit 723ac6e

Please sign in to comment.