-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
227 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,138 @@ | ||
cmake_minimum_required(VERSION 3.26) | ||
project(naughty-buffers LANGUAGES C VERSION 1.1.0) | ||
include(CTest) | ||
project(naughty-buffers LANGUAGES C VERSION 1.1.1) | ||
|
||
set(CMAKE_C_STANDARD 99) | ||
set(CMAKE_POSITION_INDEPENDENT_CODE ON) | ||
set(CMAKE_C_EXTENSIONS OFF) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
set(CMAKE_C_VISIBILITY_PRESET hidden) | ||
set(CMAKE_CXX_VISIBILITY_PRESET hidden) | ||
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES) | ||
include(GNUInstallDirs) | ||
include(GenerateExportHeader) | ||
include(CMakePackageConfigHelpers) | ||
|
||
add_subdirectory(src) | ||
set( | ||
CMAKE_C_STANDARD 99 | ||
CMAKE_POSITION_INDEPENDENT_CODE ON | ||
CMAKE_C_EXTENSIONS OFF | ||
CMAKE_CXX_EXTENSIONS OFF | ||
CMAKE_C_VISIBILITY_PRESET hidden | ||
CMAKE_CXX_VISIBILITY_PRESET hidden | ||
) | ||
|
||
set(NAUGHTY_BUFFERS_PUBLIC_HEADERS | ||
include/naughty-buffers/buffer.h | ||
include/naughty-buffers/array-generator.h | ||
${CMAKE_CURRENT_BINARY_DIR}/naughty-buffers/naughty-buffers-export.h | ||
) | ||
|
||
add_library(naughty-buffers-objects OBJECT | ||
src/naughty-buffers/buffer.c | ||
src/naughty-buffers/memory.h | ||
src/naughty-buffers/memory.c | ||
${NAUGHTY_BUFFERS_PUBLIC_HEADERS} | ||
) | ||
|
||
target_include_directories(naughty-buffers-objects PUBLIC | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> | ||
$<INSTALL_INTERFACE:include> | ||
) | ||
|
||
set_property(TARGET naughty-buffers-objects PROPERTY POSITION_INDEPENDENT_CODE 1) | ||
|
||
# shared version | ||
add_library(naughty-buffers SHARED $<TARGET_OBJECTS:naughty-buffers-objects>) | ||
add_library(naughty-buffers::naughty-buffers ALIAS naughty-buffers) | ||
|
||
generate_export_header(naughty-buffers | ||
BASE_NAME naughty-buffers | ||
EXPORT_FILE_NAME naughty-buffers/naughty-buffers-export.h | ||
) | ||
|
||
set_target_properties(naughty-buffers PROPERTIES | ||
VERSION ${naughty-buffers_VERSION} | ||
SO_VERSION ${naughty-buffers_VERSION_MAJOR} | ||
PUBLIC_HEADER "${NAUGHTY_BUFFERS_PUBLIC_HEADERS}" | ||
OUTPUT_NAME "naughty-buffers" | ||
RUNTIME_OUTPUT_NAME naughty-buffers-${naughty-buffers_VERSION} | ||
) | ||
|
||
target_include_directories(naughty-buffers PUBLIC | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> | ||
$<INSTALL_INTERFACE:include> | ||
) | ||
|
||
# static vertsion | ||
|
||
add_library(naughty-buffers-static STATIC $<TARGET_OBJECTS:naughty-buffers-objects>) | ||
add_library(naughty-buffers::naughty-buffers-static ALIAS naughty-buffers-static) | ||
|
||
set_target_properties(naughty-buffers-static PROPERTIES | ||
VERSION ${naughty-buffers_VERSION} | ||
SO_VERSION ${naughty-buffers_VERSION_MAJOR} | ||
PUBLIC_HEADER "${NAUGHTY_BUFFERS_PUBLIC_HEADERS}" | ||
OUTPUT_NAME "naughty-buffers-static" | ||
RUNTIME_OUTPUT_NAME naughty-buffers-${naughty-buffers_VERSION}-static | ||
) | ||
|
||
target_include_directories(naughty-buffers-static PUBLIC | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> | ||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> | ||
$<INSTALL_INTERFACE:include> | ||
) | ||
|
||
if (NOT CMAKE_BUILD_TYPE MATCHES "Release") | ||
target_compile_options(naughty-buffers-objects PRIVATE | ||
$<$<OR:$<C_COMPILER_ID:Clang>,$<C_COMPILER_ID:GNU>>:-Wall -Wextra -pedantic -fvisibility=hidden -Werror> | ||
$<$<C_COMPILER_ID:MSVC>:/W3 /WX /wd4820 /wd4668 /wd4204> | ||
) | ||
endif () | ||
|
||
install(TARGETS naughty-buffers naughty-buffers-static | ||
EXPORT naughty-buffers | ||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
COMPONENT "Naughty Buffers Runtime" | ||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
COMPONENT "Naughty Buffers Runtime" | ||
NAMELINK_COMPONENT "Naughty Buffers Development" | ||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
COMPONENT "Naughty Buffers Development" | ||
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/naughty-buffers | ||
COMPONENT "Naughty Buffers Development" | ||
) | ||
|
||
export( | ||
TARGETS naughty-buffers naughty-buffers-static | ||
NAMESPACE naughty-buffers:: | ||
FILE "${CMAKE_CURRENT_BINARY_DIR}/naughty-buffers-config.cmake" | ||
) | ||
|
||
install(EXPORT naughty-buffers | ||
FILE naughty-buffers-config.cmake | ||
NAMESPACE naughty-buffers:: | ||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/naughty-buffers | ||
) | ||
|
||
write_basic_package_version_file( | ||
"${CMAKE_CURRENT_BINARY_DIR}/naughty-buffers-config-version.cmake" | ||
VERSION ${naughty-buffers_VERSION} | ||
COMPATIBILITY SameMajorVersion | ||
) | ||
|
||
install( | ||
FILES | ||
"${CMAKE_CURRENT_BINARY_DIR}/naughty-buffers-config-version.cmake" | ||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/naughty-buffers | ||
COMPONENT "Naughty Buffers Development" | ||
) | ||
|
||
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) | ||
include(CTest) | ||
add_subdirectory(src/tests) | ||
endif () | ||
|
||
if (CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_EXAMPLES) | ||
add_subdirectory(src/examples) | ||
endif () | ||
|
||
if (BUILD_DOCUMENTATION) | ||
add_subdirectory(doc) | ||
endif() | ||
|
||
include(cmake/setup-exports.cmake) | ||
include(cmake/naughty-buffers-cpack.cmake) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "naughty-buffers/buffer.h" | ||
#include <assert.h> | ||
#include <stdlib.h> | ||
|
||
void iterator_works() { | ||
struct nb_buffer buffer; | ||
nb_init(&buffer, sizeof(uint32_t)); | ||
int count = rand() % 300; | ||
|
||
for (uint32_t i = 0; i < count; i++) { | ||
uint32_t value = rand(); | ||
nb_push(&buffer, &value); | ||
} | ||
|
||
struct nb_buffer_iterator itr = nb_iterator(&buffer); | ||
|
||
size_t i = 0; | ||
for (void * block = itr.begin; block != itr.end; block += itr.increment) { | ||
uint32_t * read_value = block; | ||
uint32_t * expected_value = nb_at(&buffer, i); | ||
assert(read_value == expected_value); | ||
i++; | ||
} | ||
|
||
nb_release(&buffer); | ||
} | ||
|
||
|
||
int main(void) { | ||
iterator_works(); | ||
return 0; | ||
} |