Skip to content

Commit

Permalink
Merge pull request #8 from FreyJo/main
Browse files Browse the repository at this point in the history
Build C examples using Cmake and free memory
  • Loading branch information
RSchwan authored Mar 27, 2024
2 parents 0343f0c + 62c0e1d commit 4f07306
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 3 deletions.
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

0 comments on commit 4f07306

Please sign in to comment.