Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build C examples using Cmake and free memory #8

Merged
merged 3 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ option(BUILD_MATLAB_INTERFACE "Build Matlab interface" OFF)

#### Tests/Benchmarks options ####
option(BUILD_TESTS "Build tests" ON)
option(BUILD_EXAMPLES "Build examples" ON)
option(BUILD_MAROS_MESZAROS_TEST "Build maros meszaros tests" OFF)
option(BUILD_BENCHMARKS "Build benchmarks" OFF)

Expand Down Expand Up @@ -200,6 +201,10 @@ if (BUILD_BENCHMARKS)
add_subdirectory(benchmarks)
endif()

if (BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

install(
DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
Expand Down
6 changes: 4 additions & 2 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ project(piqp_examples)

set(CMAKE_CXX_STANDARD 14)

find_package(piqp REQUIRED)
# find_package(piqp REQUIRED)

add_subdirectory(c)
if (BUILD_C_INTERFACE)
add_subdirectory(c)
endif()
add_subdirectory(cpp)
4 changes: 4 additions & 0 deletions examples/c/c_dense_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,9 @@ int main()
printf("status = %d\n", status);
printf("x = %f %f\n", work->result->x[0], work->result->x[1]);

piqp_cleanup(work);
free(settings);
free(data);

return 0;
}
4 changes: 4 additions & 0 deletions examples/c/c_sparse_example.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,9 @@ int main()
printf("status = %d\n", status);
printf("x = %f %f\n", work->result->x[0], work->result->x[1]);

piqp_cleanup(work);
free(settings);
free(data);

return 0;
}
3 changes: 2 additions & 1 deletion interfaces/matlab/make_piqp.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ function make_piqp(varargin)
'-DBUILD_C_INTERFACE=OFF ' ...
'-DBUILD_MATLAB_INTERFACE=ON ' ...
'-DBUILD_TESTS=OFF ' ...
'-DBUILD_EXAMPLES=OFF ' ...
'-DBUILD_BENCHMARKS=OFF'];

% Add specific generators for windows linux or mac
Expand Down Expand Up @@ -138,7 +139,7 @@ function make_piqp(varargin)

% Setup directory and copy files
pkg_name = sprintf('piqp-matlab-%s64', platform);
if exist(pkg_name, 'dir')
if exist(fullfile(piqp_matlab_dir, pkg_name), 'dir')
rmdir(pkg_name, 's');
end
mkdir(pkg_name);
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def build_extension(self, ext: CMakeExtension) -> None:
f"-DBUILD_PYTHON_INTERFACE=ON",
f"-DBUILD_C_INTERFACE=OFF",
f"-DBUILD_TESTS=OFF",
f"-DBUILD_EXAMPLES=OFF",
f"-DBUILD_BENCHMARKS=OFF",
f"-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=true"
]
Expand Down
Loading