Skip to content

Commit e83e90e

Browse files
committed
Make bsp_read_matrix statically linked instead of header-only.
1 parent 3ea3cb3 commit e83e90e

File tree

9 files changed

+333
-285
lines changed

9 files changed

+333
-285
lines changed

CMakeLists.txt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,18 @@ set(CMAKE_CXX_STANDARD 20)
1313

1414
set(CMAKE_C_FLAGS "-O3 -march=native")
1515

16+
add_library(binsparse-rc STATIC)
17+
1618
add_subdirectory(include)
19+
add_subdirectory(src)
20+
21+
# NOTE: For now, both HDF5 and cJSON are `PUBLIC`, meaning that anything that
22+
# depends on `binsparse-rc` will also link/include HDF5 and cJSON. We can change
23+
# these to `PRIVATE` to use them only when building binsparse-rc.
1724

1825
find_package(HDF5 REQUIRED COMPONENTS C)
19-
target_link_libraries(binsparse-rc INTERFACE ${HDF5_C_LIBRARIES})
20-
target_include_directories(binsparse-rc INTERFACE . ${HDF5_INCLUDE_DIRS})
26+
target_link_libraries(binsparse-rc PUBLIC ${HDF5_C_LIBRARIES})
27+
target_include_directories(binsparse-rc PUBLIC . ${HDF5_INCLUDE_DIRS})
2128

2229
include(FetchContent)
2330
FetchContent_Declare(
@@ -28,8 +35,8 @@ FetchContent_Declare(
2835
FetchContent_MakeAvailable(cJSON)
2936

3037
configure_file(${cJSON_SOURCE_DIR}/cJSON.h ${CMAKE_BINARY_DIR}/include/cJSON/cJSON.h)
31-
target_include_directories(${PROJECT_NAME} INTERFACE ${CMAKE_BINARY_DIR}/include)
32-
target_link_libraries(${PROJECT_NAME} INTERFACE cjson)
38+
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_BINARY_DIR}/include)
39+
target_link_libraries(${PROJECT_NAME} PUBLIC cjson)
3340

3441
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
3542
add_subdirectory(examples)

include/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
#
33
# SPDX-License-Identifier: BSD-3-Clause
44

5-
add_library(binsparse-rc INTERFACE)
6-
target_include_directories(binsparse-rc INTERFACE .)
5+
target_include_directories(binsparse-rc PUBLIC .)

include/binsparse/hdf5_wrapper.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
// Write an array to a dataset / file
2323
// Returns 0 on success, nonzero on error.
24-
int bsp_write_array(hid_t f, const char* label, bsp_array_t array,
25-
int compression_level) {
24+
static inline int bsp_write_array(hid_t f, const char* label, bsp_array_t array,
25+
int compression_level) {
2626
if (array.type == BSP_COMPLEX_FLOAT32 || array.type == BSP_COMPLEX_FLOAT64) {
2727
array = bsp_complex_array_to_fp(array);
2828
}
@@ -76,8 +76,8 @@ int bsp_write_array(hid_t f, const char* label, bsp_array_t array,
7676
}
7777

7878
#if __STDC_VERSION__ >= 201112L
79-
bsp_array_t bsp_read_array_parallel(hid_t f, const char* label,
80-
int num_threads) {
79+
static inline bsp_array_t bsp_read_array_parallel(hid_t f, const char* label,
80+
int num_threads) {
8181
hid_t dset = H5Dopen2(f, label, H5P_DEFAULT);
8282

8383
if (dset == H5I_INVALID_HID) {
@@ -173,7 +173,7 @@ bsp_array_t bsp_read_array_parallel(hid_t f, const char* label,
173173
}
174174
#endif
175175

176-
bsp_array_t bsp_read_array(hid_t f, const char* label) {
176+
static inline bsp_array_t bsp_read_array(hid_t f, const char* label) {
177177
hid_t dset = H5Dopen2(f, label, H5P_DEFAULT);
178178

179179
if (dset == H5I_INVALID_HID) {
@@ -212,7 +212,8 @@ bsp_array_t bsp_read_array(hid_t f, const char* label) {
212212
return array;
213213
}
214214

215-
void bsp_write_attribute(hid_t f, const char* label, const char* string) {
215+
static inline void bsp_write_attribute(hid_t f, const char* label,
216+
const char* string) {
216217
hid_t strtype = H5Tcopy(H5T_C_S1);
217218
H5Tset_size(strtype, strlen(string));
218219
H5Tset_cset(strtype, H5T_CSET_UTF8);
@@ -228,7 +229,7 @@ void bsp_write_attribute(hid_t f, const char* label, const char* string) {
228229
H5Sclose(dataspace);
229230
}
230231

231-
char* bsp_read_attribute(hid_t f, const char* label) {
232+
static inline char* bsp_read_attribute(hid_t f, const char* label) {
232233
hid_t attribute = H5Aopen(f, label, H5P_DEFAULT);
233234
hid_t strtype = H5Aget_type(attribute);
234235

include/binsparse/matrix_market/matrix_market_inspector.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ typedef struct bsp_mm_metadata {
3232
char* comments;
3333
} bsp_mm_metadata;
3434

35-
bsp_mm_metadata bsp_mmread_metadata(const char* file_path) {
35+
static inline bsp_mm_metadata bsp_mmread_metadata(const char* file_path) {
3636
FILE* f = fopen(file_path, "r");
3737

3838
assert(f != NULL);

include/binsparse/matrix_market/matrix_market_read.h

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
#include <stdint.h>
1212
#include <stdlib.h>
1313

14+
#include <binsparse/matrix.h>
1415
#include <binsparse/matrix_market/coo_sort_tools.h>
1516
#include <binsparse/matrix_market/matrix_market_inspector.h>
1617
#include <binsparse/matrix_market/matrix_market_type_t.h>
1718

18-
bsp_matrix_t bsp_mmread_explicit_array(const char* file_path,
19-
bsp_type_t value_type,
20-
bsp_type_t index_type) {
19+
static inline bsp_matrix_t bsp_mmread_explicit_array(const char* file_path,
20+
bsp_type_t value_type,
21+
bsp_type_t index_type) {
2122
bsp_mm_metadata metadata = bsp_mmread_metadata(file_path);
2223

2324
bsp_matrix_market_type_t mm_type;
@@ -103,9 +104,9 @@ bsp_matrix_t bsp_mmread_explicit_array(const char* file_path,
103104
return matrix;
104105
}
105106

106-
bsp_matrix_t bsp_mmread_explicit_coordinate(const char* file_path,
107-
bsp_type_t value_type,
108-
bsp_type_t index_type) {
107+
static inline bsp_matrix_t
108+
bsp_mmread_explicit_coordinate(const char* file_path, bsp_type_t value_type,
109+
bsp_type_t index_type) {
109110
bsp_mm_metadata metadata = bsp_mmread_metadata(file_path);
110111

111112
bsp_matrix_market_type_t mm_type;
@@ -261,8 +262,9 @@ bsp_matrix_t bsp_mmread_explicit_coordinate(const char* file_path,
261262
return matrix;
262263
}
263264

264-
bsp_matrix_t bsp_mmread_explicit(const char* file_path, bsp_type_t value_type,
265-
bsp_type_t index_type) {
265+
static inline bsp_matrix_t bsp_mmread_explicit(const char* file_path,
266+
bsp_type_t value_type,
267+
bsp_type_t index_type) {
266268
bsp_mm_metadata metadata = bsp_mmread_metadata(file_path);
267269

268270
if (strcmp(metadata.format, "array") == 0) {
@@ -274,7 +276,7 @@ bsp_matrix_t bsp_mmread_explicit(const char* file_path, bsp_type_t value_type,
274276
}
275277
}
276278

277-
bsp_matrix_t bsp_mmread(const char* file_path) {
279+
static inline bsp_matrix_t bsp_mmread(const char* file_path) {
278280
bsp_mm_metadata metadata = bsp_mmread_metadata(file_path);
279281

280282
bsp_type_t value_type;

include/binsparse/matrix_market/matrix_market_write.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#include <binsparse/matrix_market/matrix_market_type_t.h>
1414

15-
void bsp_mmwrite(const char* file_path, bsp_matrix_t matrix) {
15+
static inline void bsp_mmwrite(const char* file_path, bsp_matrix_t matrix) {
1616
FILE* f = fopen(file_path, "w");
1717

1818
assert(f != NULL);

0 commit comments

Comments
 (0)