diff --git a/.gitignore b/.gitignore index 77ff7ad..6b89fac 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ scripts venv -build/ build-*/ compile_flags.txt ._* diff --git a/CMakeLists.txt b/CMakeLists.txt index 1776473..79f1fb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,16 @@ # SPDX-License-Identifier: BSD-3-Clause cmake_minimum_required(VERSION 3.20) -project(binsparse VERSION 1.0.0) + +set ( BINSPARSE_DATE "FIXME, 2026" ) +set ( BINSPARSE_VERSION_MAJOR 1 ) +set ( BINSPARSE_VERSION_MINOR 0 ) +set ( BINSPARSE_VERSION_PATCH 0 ) + +project(binsparse) + +set ( PROJECT_VERSION + "${BINSPARSE_VERSION_MAJOR}.${BINSPARSE_VERSION_MINOR}.${BINSPARSE_VERSION_PATCH}") cmake_policy(SET CMP0079 NEW) @@ -12,16 +21,45 @@ set(CMAKE_CXX_STANDARD 20) # FIXME: -march=native is not portable # set(CMAKE_C_FLAGS "-O3 -march=native") -set(CMAKE_C_FLAGS "-g ") -set(CMAKE_CXX_FLAGS "-g ") +# set(CMAKE_C_FLAGS "-g ") +# set(CMAKE_CXX_FLAGS "-g ") + +if ( NOT CMAKE_BUILD_TYPE ) + set ( CMAKE_BUILD_TYPE Release ) +endif ( ) + +if ( ${CMAKE_BUILD_TYPE} STREQUAL "Debug" ) + set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG}" ) + set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}" ) +else ( ) + set ( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE}" ) + set ( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}" ) +endif ( ) +message ( STATUS "Build type: ${CMAKE_BUILD_TYPE} ") +message ( STATUS "C flags: ${CMAKE_C_FLAGS}" ) +message ( STATUS "C++ flags: ${CMAKE_CXX_FLAGS}" ) option(ENABLE_SANITIZERS "Enable Clang sanitizers" OFF) include(GNUInstallDirs) -add_library(binsparse STATIC) +add_library(binsparse_static STATIC) add_library(binsparse_dynamic SHARED) +set_target_properties ( binsparse_static PROPERTIES + OUTPUT_NAME binsparse + VERSION "${BINSPARSE_VERSION_MAJOR}.${BINSPARSE_VERSION_MINOR}.${BINSPARSE_VERSION_PATCH}" + SOVERSION ${BINSPARSE_VERSION_MAJOR} + WINDOWS_EXPORT_ALL_SYMBOLS ON + ) + +set_target_properties ( binsparse_dynamic PROPERTIES + OUTPUT_NAME binsparse + VERSION "${BINSPARSE_VERSION_MAJOR}.${BINSPARSE_VERSION_MINOR}.${BINSPARSE_VERSION_PATCH}" + SOVERSION ${BINSPARSE_VERSION_MAJOR} + WINDOWS_EXPORT_ALL_SYMBOLS ON + ) + add_subdirectory(include) add_subdirectory(src) @@ -30,8 +68,9 @@ add_subdirectory(src) # these to `PRIVATE` to use them only when building binsparse. find_package(HDF5 REQUIRED COMPONENTS C) -target_link_libraries(binsparse PUBLIC ${HDF5_C_LIBRARIES}) +target_link_libraries(binsparse_static PUBLIC ${HDF5_C_LIBRARIES}) target_link_libraries(binsparse_dynamic PUBLIC ${HDF5_C_LIBRARIES}) +message ( STATUS "HD5F include: ${HDF5_INCLUDE_DIRS}" ) include(FetchContent) @@ -52,11 +91,11 @@ FetchContent_MakeAvailable(cJSON) set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_BACKUP}) configure_file(${cJSON_SOURCE_DIR}/cJSON.h ${CMAKE_BINARY_DIR}/include/cJSON/cJSON.h) -target_link_libraries(binsparse PRIVATE cjson) +target_link_libraries(binsparse_static PRIVATE cjson) target_link_libraries(binsparse_dynamic PRIVATE cjson) # Set up include directories properly for both build and install -target_include_directories(${PROJECT_NAME} +target_include_directories(binsparse_static PUBLIC $ $ @@ -73,8 +112,8 @@ target_include_directories(binsparse_dynamic ${HDF5_INCLUDE_DIRS}) # Installation rules - these are always needed when the library is built -install(TARGETS binsparse - EXPORT binsparse-targets +install(TARGETS binsparse_static + EXPORT binsparse-targets_static LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} @@ -93,8 +132,8 @@ install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/binsparse PATTERN "*.hpp") # Export targets -install(EXPORT binsparse-targets - FILE binsparse-targets.cmake +install(EXPORT binsparse-targets_static + FILE binsparse-targets_static.cmake NAMESPACE binsparse:: DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/binsparse) install(EXPORT binsparse-targets_dynamic @@ -124,8 +163,8 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) if (ENABLE_SANITIZERS) set(SANITIZER_FLAGS "-fsanitize=address,undefined") - target_compile_options(binsparse INTERFACE ${SANITIZER_FLAGS} -g -O1 -fno-omit-frame-pointer) - target_link_options(binsparse INTERFACE ${SANITIZER_FLAGS}) + target_compile_options(binsparse_static INTERFACE ${SANITIZER_FLAGS} -g -O1 -fno-omit-frame-pointer) + target_link_options(binsparse_static INTERFACE ${SANITIZER_FLAGS}) target_compile_options(binsparse_dynamic INTERFACE ${SANITIZER_FLAGS} -g -O1 -fno-omit-frame-pointer) target_link_options(binsparse_dynamic INTERFACE ${SANITIZER_FLAGS}) endif() diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5186f58 --- /dev/null +++ b/Makefile @@ -0,0 +1,37 @@ +#------------------------------------------------------------------------------- +# binsparse-reference-c/Makefile +#------------------------------------------------------------------------------- + +# SPDX-FileCopyrightText: 2024 Binsparse Developers +# SPDX-License-Identifier: BSD-3-Clause + +default: library + +library: + ( cd build && cmake $(CMAKE_OPTIONS) .. && cmake --build . --config Release ) + +debug: + ( cd build && cmake $(CMAKE_OPTIONS) -DCMAKE_BUILD_TYPE=Debug .. ; cmake --build . --config Debug ) + +all: library + +tests: + ( cd build ; make test ) + +install: + ( cd build && cmake --install . ) + +# remove any installed libraries and #include files +uninstall: + - xargs rm < build/install_manifest.txt + +# remove all files not in the distribution +clean: distclean + +purge: distclean + +distclean: + - $(RM) -rf build/* Config/*.tmp + +docs: + diff --git a/README.md b/README.md index 29a5a82..0d5a924 100644 --- a/README.md +++ b/README.md @@ -50,58 +50,20 @@ all dependencies except for: HDF5 should be automatically detected, provided an installation is present on the system. -```bash -bbrock@rjohns3-mobl2:~/src/binsparse-reference-c$ cmake -B build --- The C compiler identification is AppleClang 15.0.0.15000309 --- The CXX compiler identification is AppleClang 15.0.0.15000309 --- Detecting C compiler ABI info --- Detecting C compiler ABI info - done --- Check for working C compiler: /Library/Developer/CommandLineTools/usr/bin/cc - skipped --- Detecting C compile features --- Detecting C compile features - done --- Detecting CXX compiler ABI info --- Detecting CXX compiler ABI info - done --- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ - skipped --- Detecting CXX compile features --- Detecting CXX compile features - done --- Found HDF5: /opt/homebrew/Cellar/hdf5/1.14.3/lib/libhdf5.dylib;/opt/homebrew/opt/libaec/lib/libsz.dylib;/Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/lib/libz.tbd;/Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/lib/libdl.tbd;/Library/Developer/CommandLineTools/SDKs/MacOSX14.4.sdk/usr/lib/libm.tbd (found version "1.14.3") found components: C -CMake Deprecation Warning at build/_deps/cjson-src/CMakeLists.txt:2 (cmake_minimum_required): - Compatibility with CMake < 3.5 will be removed from a future version of - CMake. - - Update the VERSION argument value or use a ... suffix to tell - CMake that the project does not need compatibility with older versions. - - --- Performing Test FLAG_SUPPORTED_fvisibilityhidden --- Performing Test FLAG_SUPPORTED_fvisibilityhidden - Success --- Configuring done (6.4s) --- Generating done (0.2s) --- Build files have been written to: /Users/bbrock/src/binsparse-reference-c/build -bbrock@rjohns3-mobl2:~/src/binsparse-reference-c$ cd build/examples/ -bbrock@rjohns3-mobl2:~/src/binsparse-reference-c/build/examples$ make -[ 8%] Building C object _deps/cjson-build/CMakeFiles/cjson.dir/cJSON.c.o -[ 16%] Linking C shared library libcjson.dylib -ld: warning: search path '/opt/homebrew/Cellar/fmt/10.1.1/lib' not found -[ 16%] Built target cjson -[ 25%] Building C object examples/CMakeFiles/simple_matrix_write.dir/simple_matrix_write.c.o -[ 33%] Linking C executable simple_matrix_write -ld: warning: search path '/opt/homebrew/Cellar/fmt/10.1.1/lib' not found -[ 33%] Built target simple_matrix_write -[ 41%] Building C object examples/CMakeFiles/simple_matrix_read.dir/simple_matrix_read.c.o -[ 50%] Linking C executable simple_matrix_read -ld: warning: search path '/opt/homebrew/Cellar/fmt/10.1.1/lib' not found -[ 50%] Built target simple_matrix_read -[ 58%] Building C object examples/CMakeFiles/simple_read.dir/simple_read.c.o -[ 66%] Linking C executable simple_read -ld: warning: search path '/opt/homebrew/Cellar/fmt/10.1.1/lib' not found -[ 66%] Built target simple_read -[ 75%] Building C object examples/CMakeFiles/simple_write.dir/simple_write.c.o -[ 83%] Linking C executable simple_write -ld: warning: search path '/opt/homebrew/Cellar/fmt/10.1.1/lib' not found -[ 83%] Built target simple_write -[ 91%] Building C object examples/CMakeFiles/convert_binsparse.dir/convert_binsparse.c.o -[100%] Linking C executable convert_binsparse -ld: warning: search path '/opt/homebrew/Cellar/fmt/10.1.1/lib' not found -[100%] Built target convert_binsparse -``` +A simple top-level Makefile can be used to compile, test, and install +binsparse: + + make + make tests + sudu make install + +To remove all compiled files and libraries: + + make distclean + +FIXME: the above will segfault because assert(...) is removed for Release. +For now use: + + make debug + make tests + diff --git a/build/.gitignore b/build/.gitignore new file mode 100644 index 0000000..52e1532 --- /dev/null +++ b/build/.gitignore @@ -0,0 +1,4 @@ +# Ignore all files except this file. +* +*/ +!.gitignore diff --git a/cmake/binsparse-config.cmake.in b/cmake/binsparse-config.cmake.in index 052bc3b..79228bd 100644 --- a/cmake/binsparse-config.cmake.in +++ b/cmake/binsparse-config.cmake.in @@ -4,8 +4,8 @@ @PACKAGE_INIT@ -include("${CMAKE_CURRENT_LIST_DIR}/binsparse-targets.cmake") -check_required_components(binsparse) +include("${CMAKE_CURRENT_LIST_DIR}/binsparse-targets_static.cmake") +check_required_components(binsparse_static) # Include dependencies include(CMakeFindDependencyMacro) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index e090d7c..e0c6f73 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -4,7 +4,7 @@ function(add_example example_name) add_executable(${example_name} ${example_name}.c) - target_link_libraries(${example_name} binsparse) + target_link_libraries(${example_name} binsparse_static) endfunction() add_example(simple_matrix_write) diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt index 5053bab..56e08e7 100644 --- a/examples/cpp/CMakeLists.txt +++ b/examples/cpp/CMakeLists.txt @@ -4,7 +4,7 @@ function(add_example example_name) add_executable(${example_name}-cpp ${example_name}.cpp) - target_link_libraries(${example_name}-cpp binsparse) + target_link_libraries(${example_name}-cpp binsparse_static) endfunction() add_example(simple_matrix_write) diff --git a/include/binsparse/convert_matrix.h b/include/binsparse/convert_matrix.h index 3d2c12d..443155a 100644 --- a/include/binsparse/convert_matrix.h +++ b/include/binsparse/convert_matrix.h @@ -4,6 +4,10 @@ * SPDX-License-Identifier: BSD-3-Clause */ + +// FIXME: cannot use assert in production if it has any side effects when deleted +// with -NDEBUG + #pragma once #include @@ -30,7 +34,7 @@ bsp_convert_matrix_allocator(bsp_matrix_t matrix, bsp_matrix_format_t format, bsp_allocator_t allocator) { // Throw an error if matrix already in desired format. if (matrix.format == format) { - assert(false); + assert(false); // FIXME: this does not throw an error when binsparse compiled for prodction } if (format == BSP_COOR) { @@ -275,7 +279,7 @@ bsp_convert_matrix_allocator(bsp_matrix_t matrix, bsp_matrix_format_t format, free(indices); return result; } else { - assert(false); + assert(false); // FIXME remove assert(...) } } else { // Convert to any another format. @@ -493,7 +497,7 @@ bsp_convert_matrix_allocator(bsp_matrix_t matrix, bsp_matrix_format_t format, free(indices); return result; } else { - assert(false); + assert(false); // FIXME remove assert(...) in production } } } diff --git a/include/binsparse/types.h b/include/binsparse/types.h index a98e938..39232d6 100644 --- a/include/binsparse/types.h +++ b/include/binsparse/types.h @@ -87,7 +87,7 @@ static inline size_t bsp_type_size(bsp_type_t type) { } else if (type == BSP_COMPLEX_FLOAT64) { return sizeof(double _Complex); } else { - assert(false); + assert(false); // FIXME: assert(false) cannot appear in a production library } } diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f966494..bad5163 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: BSD-3-Clause -target_sources(binsparse PRIVATE +target_sources(binsparse_static PRIVATE read_matrix.c read_tensor.c write_matrix.c diff --git a/test/c/CMakeLists.txt b/test/c/CMakeLists.txt index dfa65da..21b6fee 100644 --- a/test/c/CMakeLists.txt +++ b/test/c/CMakeLists.txt @@ -3,7 +3,7 @@ # SPDX-License-Identifier: BSD-3-Clause add_executable(dvec_shape_test dvec_shape_test.c) -target_link_libraries(dvec_shape_test binsparse) +target_link_libraries(dvec_shape_test binsparse_static) add_test( NAME unit.dvec_shape diff --git a/test/c/dvec_shape_test.c b/test/c/dvec_shape_test.c index 1e0914a..f5cf2cf 100644 --- a/test/c/dvec_shape_test.c +++ b/test/c/dvec_shape_test.c @@ -4,6 +4,11 @@ * SPDX-License-Identifier: BSD-3-Clause */ +// FIXME asserts are empty if the library is compiled for Release. +// use a different macro. + +// FIXME this test segfaults if binsparse is compiled with Release flags (-O3) + #include #include #include