Skip to content
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

scripts
venv
build
build*
._*
69 changes: 57 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,88 @@
#
# SPDX-License-Identifier: BSD-3-Clause

cmake_minimum_required(VERSION 3.5)
project(binsparse-rc)
cmake_minimum_required(VERSION 3.20)
project(binsparse VERSION 1.0.0)

cmake_policy(SET CMP0079 NEW)

set(CMAKE_C_STANDARD 11)

set(CMAKE_CXX_STANDARD 20)

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

add_library(binsparse-rc STATIC)
include(GNUInstallDirs)

add_library(binsparse STATIC)

add_subdirectory(include)
add_subdirectory(src)

# NOTE: For now, both HDF5 and cJSON are `PUBLIC`, meaning that anything that
# depends on `binsparse-rc` will also link/include HDF5 and cJSON. We can change
# these to `PRIVATE` to use them only when building binsparse-rc.
# depends on `binsparse` will also link/include HDF5 and cJSON. We can change
# these to `PRIVATE` to use them only when building binsparse.

find_package(HDF5 REQUIRED COMPONENTS C)
target_link_libraries(binsparse-rc PUBLIC ${HDF5_C_LIBRARIES})
target_include_directories(binsparse-rc PUBLIC . ${HDF5_INCLUDE_DIRS})
target_link_libraries(binsparse PUBLIC ${HDF5_C_LIBRARIES})

include(FetchContent)
FetchContent_Declare(
cJSON
GIT_REPOSITORY https://github.com/DaveGamble/cJSON.git
GIT_TAG v1.7.17
# GIT_REPOSITORY https://github.com/DaveGamble/cJSON.git
GIT_REPOSITORY https://github.com/p1k0chu/cJSON.git
GIT_TAG 887642c0a93bd8a6616bf90daacac0ea7d4b095e
)
FetchContent_MakeAvailable(cJSON)

configure_file(${cJSON_SOURCE_DIR}/cJSON.h ${CMAKE_BINARY_DIR}/include/cJSON/cJSON.h)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_BINARY_DIR}/include)
target_link_libraries(${PROJECT_NAME} PUBLIC cjson)

# Set up include directories properly for both build and install
target_include_directories(${PROJECT_NAME}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
${HDF5_INCLUDE_DIRS})

if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
add_subdirectory(examples)
add_subdirectory(test)
endif()

# Installation rules - these are always needed when the library is built
install(TARGETS binsparse
EXPORT binsparse-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

# Install headers
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/binsparse
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.h"
PATTERN "*.hpp")

# Export targets
install(EXPORT binsparse-targets
FILE binsparse-targets.cmake
NAMESPACE binsparse::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/binsparse)

# Create and install package config files
include(CMakePackageConfigHelpers)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/binsparse-config-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)

configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/binsparse-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/binsparse-config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/binsparse)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/binsparse-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/binsparse-config-version.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/binsparse)
14 changes: 14 additions & 0 deletions cmake/binsparse-config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# SPDX-FileCopyrightText: 2024 Binsparse Developers
#
# SPDX-License-Identifier: BSD-3-Clause

@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/binsparse-targets.cmake")
check_required_components(binsparse)

# Include dependencies
include(CMakeFindDependencyMacro)
find_dependency(HDF5 COMPONENTS C)

# cJSON is bundled with binsparse, no need to find it externally
2 changes: 1 addition & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

function(add_example example_name)
add_executable(${example_name} ${example_name}.c)
target_link_libraries(${example_name} binsparse-rc)
target_link_libraries(${example_name} binsparse)
endfunction()

add_example(simple_matrix_write)
Expand Down
2 changes: 1 addition & 1 deletion examples/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

function(add_example example_name)
add_executable(${example_name}-cpp ${example_name}.cpp)
target_link_libraries(${example_name}-cpp binsparse-rc)
target_link_libraries(${example_name}-cpp binsparse)
endfunction()

add_example(simple_matrix_write)
Expand Down
2 changes: 1 addition & 1 deletion include/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
#
# SPDX-License-Identifier: BSD-3-Clause

target_include_directories(binsparse-rc PUBLIC .)
# No need for target_include_directories here - moved to main CMakeLists.txt
6 changes: 3 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: BSD-3-Clause

target_sources(binsparse-rc PRIVATE
src/read_matrix.c
src/write_matrix.c
target_sources(binsparse PRIVATE
read_matrix.c
write_matrix.c
)