From 97e6575c3b4429a905a721942254a4d4942c338c Mon Sep 17 00:00:00 2001 From: Vikram Saran Date: Wed, 2 Apr 2025 16:08:05 +0200 Subject: [PATCH 1/8] docs: Update README.md --- README.md | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index b4da72f..76cbb88 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,30 @@ # stb cmake wrapper + The popular [stb libraries](https://github.com/nothings/stb) are a set of header-only libraries which are very easy to just copy and paste into existing codebases. However, if you have already set up a cmake based project is sometimes convenient to have proper cmake targets for the individual libraries. -This wrapper creates cmake targets for each library that takes care of adding the actual implementation for the libraries, i.e., adding the proper `STD_(...)_IMPLEMENTATION` define. +This wrapper creates cmake targets for each library that takes care of adding the actual implementation for the libraries, i.e., adding the proper `STB_(...)_IMPLEMENTATION` define. + +## Fork + +This is a fork to update the version of `stb`, fix some minor documentation issues, and update the cmake min target in the era of CMake 4.0 deprecating older versions. No other changes will be made (extending support to other libraries, etc.). + +## Consuming this library in cmake -After adding this wrapper to you project you have access to the `std::LIBRARY_NAME` targets. +After adding this wrapper to your project you have access to the `stb::LIBRARY_NAME` targets. For example, to use the image library you simply add this to your cmake script: + ```cmake -target_link_libraries(YOUR_TARGET PUBLIC std::image) +target_link_libraries(YOUR_TARGET PUBLIC stb::image) ``` -### Adding the wrapper to your project -1. Via [CPM](https://github.com/cpm-cmake/CPM.cmake): simply add `CPMAddPackage("gh:ovis-games/stb-cmake-wrapper@0.1")` to your cmake script. -2. Via git submodules: add a submodule to your repository and add `add_subdirectory(path/to/std-cmake-wrapper)`. Alternatively you can also copy and paste the conent of this repository instead of using git submodules. +## Adding the wrapper to your project + +1. Via [CPM](https://github.com/cpm-cmake/CPM.cmake): simply add `CPMAddPackage("gh:vikhik/stb-cmake-wrapper@0.2")` to your cmake script. +2. Via git submodules: add a submodule to your repository and add `add_subdirectory(path/to/stb-cmake-wrapper)`. +3. Alternatively you can also copy and paste the contents of this repository. + +## Library support -### Library support This list gives an overview of the currently supported libraries. The libraries currently not supported by the wrapper are the ones needing additional defines to work (textedit, voxel_render, tilemap_editor, connected_components). In addition, the vorbis library is currently not supported as it is a .c file but somehow acts as a header and I currently do not want look into it how it actually works. @@ -40,5 +51,6 @@ In addition, the vorbis library is currently not supported as it is a .c file bu - [x] [stb::leakcheck](https://github.com/nothings/stb/blob/master/stb_leakcheck.h) - [x] [stb::include](https://github.com/nothings/stb/blob/master/stb_include.h) -### License +## License + [MIT](LICENSE) From 0ccc5aa57ad57ac79dc9de0c65343a1b457239fe Mon Sep 17 00:00:00 2001 From: Vikram Saran Date: Wed, 2 Apr 2025 16:09:56 +0200 Subject: [PATCH 2/8] feat: Update submodule to latest --- stb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stb b/stb index 8b5f1f3..f056911 160000 --- a/stb +++ b/stb @@ -1 +1 @@ -Subproject commit 8b5f1f37b5b75829fc72d38e7b5d4bcbf8a26d55 +Subproject commit f0569113c93ad095470c54bf34a17b36646bbbb5 From 8ff2336287d90ec76b96c7ab3bf2b6144eddafe2 Mon Sep 17 00:00:00 2001 From: Vikram Saran Date: Wed, 2 Apr 2025 16:42:08 +0200 Subject: [PATCH 3/8] feat: Update cmake to be more modern * Use minimum version 3.11 for future compatibility * Use C instead of C++ for better compatibility with stb * Add support for stb::vorbis (use cmake_parse_arguments) * Update to image_resize2 * Add gitignore --- .gitignore | 1 + CMakeLists.txt | 73 +++++++++++++++++++++++++++++++++------------- README.md | 3 +- main.cpp => main.c | 0 4 files changed, 55 insertions(+), 22 deletions(-) create mode 100644 .gitignore rename main.cpp => main.c (100%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4fcb459 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build diff --git a/CMakeLists.txt b/CMakeLists.txt index 032dc1d..25b29e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,53 +1,86 @@ -cmake_minimum_required(VERSION 3.0) -project(stb-cmake-wrapper) +cmake_minimum_required(VERSION 3.11..3.31) +project(stb-cmake-wrapper + VERSION 0.2.0 + DESCRIPTION "CMake wrapper for stb libraries" + LANGUAGES C +) -function(add_stb_library library_name) - set(target_name stb-${library_name}) - string(TOUPPER ${library_name} uppercase_library_name) +function(add_stb_library) + set(oneValueArgs NAME EXT) + set(multiValueArgs) - add_library( - ${target_name} - main.cpp + cmake_parse_arguments( + PARSE_ARGV 0 arg + "${options}" + "${oneValueArgs}" + "${multiValueArgs}" ) - target_compile_definitions( + + if (NOT DEFINED arg_NAME) + message(FATAL_ERROR "NAME argument is required") + endif() + + if (NOT DEFINED arg_EXT) + set(arg_EXT "h") + endif() + + set(target_name stb-${arg_NAME}) + string(TOUPPER ${arg_NAME} upper_NAME) + + add_library( ${target_name} - PRIVATE - STB_${uppercase_library_name}_IMPLEMENTATION - STB_CMAKE_WRAPPER_LIBRARY_INCLUDE="stb_${library_name}.h" + main.c ) target_include_directories( ${target_name} PUBLIC stb ) - add_library(stb::${library_name} ALIAS stb-${library_name}) + target_compile_definitions( + ${target_name} + PRIVATE + STB_${upper_NAME}_IMPLEMENTATION + STB_CMAKE_WRAPPER_LIBRARY_INCLUDE="stb_${arg_NAME}.${arg_EXT}" + ) + add_library(stb::${arg_NAME} ALIAS stb-${arg_NAME}) + + if (MSVC) + # Suppress known warnings for MSVC (W4 has too many to bother with) + target_compile_options(${target_name} PRIVATE /W3 /WX /permissive- /wd4244) + target_compile_definitions(${target_name} PRIVATE _CRT_SECURE_NO_WARNINGS) + else() + target_compile_options(${target_name} PRIVATE -Wall -Wextra -pedantic -Werror) + endif() + + target_compile_features(${target_name} PRIVATE c_std_11) endfunction() set(libraries - # vorbis This is a .c file for some reason? hexwave image truetype image_write # The library is called image_writer but the header file is called image_write - image_resize + image_resize2 rect_pack perlin ds sprintf - # textedit Too many definitions needed so leave it out for now - # voxel_render + # textedit # Too many definitions needed so leave it out for now + # voxel_render # "Must defined STBVOX_CONFIG_MODE to select the mode" dxt easy_font - # tilemap_editor + # tilemap_editor # 'STBTE_DRAW_RECT' undefined; herringbone_wang_tile c_lexer divide - # connected_components + # connected_components # "You must define STBCC_GRID_COUNT_X_LOG2 and STBCC_GRID_COUNT_Y_LOG2 to define the max grid supported." leakcheck include ) foreach(library ${libraries}) - add_stb_library(${library}) + message(STATUS "Adding stb library: ${library}") + add_stb_library(NAME ${library}) endforeach() +add_stb_library(NAME vorbis EXT "c") diff --git a/README.md b/README.md index 76cbb88..e975bfd 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,8 @@ target_link_libraries(YOUR_TARGET PUBLIC stb::image) This list gives an overview of the currently supported libraries. The libraries currently not supported by the wrapper are the ones needing additional defines to work (textedit, voxel_render, tilemap_editor, connected_components). -In addition, the vorbis library is currently not supported as it is a .c file but somehow acts as a header and I currently do not want look into it how it actually works. -- [ ] [stb::vorbis](https://github.com/nothings/stb/blob/master/stb_vorbis.c) +- [x] [stb::vorbis](https://github.com/nothings/stb/blob/master/stb_vorbis.c) - [x] [stb::hexwave](https://github.com/nothings/stb/blob/master/stb_hexwave.h) - [x] [stb::image](https://github.com/nothings/stb/blob/master/stb_image.h) - [x] [stb::truetype](https://github.com/nothings/stb/blob/master/stb_truetype.h) diff --git a/main.cpp b/main.c similarity index 100% rename from main.cpp rename to main.c From 6ddfbd02ea9c3d7a191cadd24a89ddd9e070f0d5 Mon Sep 17 00:00:00 2001 From: Vikram Saran Date: Wed, 2 Apr 2025 16:50:19 +0200 Subject: [PATCH 4/8] fix: Disable warnings for gcc We trust stb... right? --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 25b29e4..e7e74ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,10 +46,13 @@ function(add_stb_library) if (MSVC) # Suppress known warnings for MSVC (W4 has too many to bother with) + # This, as of April 2025, compiles with no warnings at all target_compile_options(${target_name} PRIVATE /W3 /WX /permissive- /wd4244) target_compile_definitions(${target_name} PRIVATE _CRT_SECURE_NO_WARNINGS) else() - target_compile_options(${target_name} PRIVATE -Wall -Wextra -pedantic -Werror) + # There are a LOT of warnings with gcc/clang, so just disable them all... + # We _trust_ stb, right? + target_compile_options(${target_name} PRIVATE -w) endif() target_compile_features(${target_name} PRIVATE c_std_11) From 6af5fac7971ef0b079902ddca1eefb41b4320f82 Mon Sep 17 00:00:00 2001 From: Vikram Saran Date: Wed, 2 Apr 2025 16:51:21 +0200 Subject: [PATCH 5/8] ci: Create cmake-multi-platform.yml --- .github/workflows/cmake-multi-platform.yml | 75 ++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 .github/workflows/cmake-multi-platform.yml diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml new file mode 100644 index 0000000..7ab1b4d --- /dev/null +++ b/.github/workflows/cmake-multi-platform.yml @@ -0,0 +1,75 @@ +# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform. +# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml +name: CMake on multiple platforms + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. + fail-fast: false + + # Set up a matrix to run the following 3 configurations: + # 1. + # 2. + # 3. + # + # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. + matrix: + os: [ubuntu-latest, windows-latest] + build_type: [Release] + c_compiler: [gcc, clang, cl] + include: + - os: windows-latest + c_compiler: cl + cpp_compiler: cl + - os: ubuntu-latest + c_compiler: gcc + cpp_compiler: g++ + - os: ubuntu-latest + c_compiler: clang + cpp_compiler: clang++ + exclude: + - os: windows-latest + c_compiler: gcc + - os: windows-latest + c_compiler: clang + - os: ubuntu-latest + c_compiler: cl + + steps: + - uses: actions/checkout@v4 + + - name: Set reusable strings + # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. + id: strings + shell: bash + run: | + echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: > + cmake -B ${{ steps.strings.outputs.build-output-dir }} + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} + -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -S ${{ github.workspace }} + + - name: Build + # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} + + - name: Test + working-directory: ${{ steps.strings.outputs.build-output-dir }} + # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + run: ctest --build-config ${{ matrix.build_type }} From e323945214bf22dbb033427a79174683976c840c Mon Sep 17 00:00:00 2001 From: Vikram Saran Date: Wed, 2 Apr 2025 16:54:17 +0200 Subject: [PATCH 6/8] ci: Checkout submodules --- .github/workflows/cmake-multi-platform.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/cmake-multi-platform.yml b/.github/workflows/cmake-multi-platform.yml index 7ab1b4d..67c435d 100644 --- a/.github/workflows/cmake-multi-platform.yml +++ b/.github/workflows/cmake-multi-platform.yml @@ -46,6 +46,8 @@ jobs: steps: - uses: actions/checkout@v4 + with: + submodules: true - name: Set reusable strings # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. From c690942636ee6ae1f33aa747b98b00df60931f85 Mon Sep 17 00:00:00 2001 From: Vikram Saran Date: Wed, 2 Apr 2025 16:57:07 +0200 Subject: [PATCH 7/8] fix: Suppress additional incompatible function pointer type warnings for clang --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e7e74ca..3c02ccf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,7 @@ function(add_stb_library) else() # There are a LOT of warnings with gcc/clang, so just disable them all... # We _trust_ stb, right? - target_compile_options(${target_name} PRIVATE -w) + target_compile_options(${target_name} PRIVATE -w -Wno-incompatible-function-pointer-types) endif() target_compile_features(${target_name} PRIVATE c_std_11) From 42354501cc48f2bafc379d158473be1eda3172b7 Mon Sep 17 00:00:00 2001 From: Vikram Saran Date: Wed, 2 Apr 2025 16:58:58 +0200 Subject: [PATCH 8/8] docs: Remove a lie --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e975bfd..8b299c6 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ This wrapper creates cmake targets for each library that takes care of adding th ## Fork -This is a fork to update the version of `stb`, fix some minor documentation issues, and update the cmake min target in the era of CMake 4.0 deprecating older versions. No other changes will be made (extending support to other libraries, etc.). +This is a fork to update the version of `stb`, fix some minor documentation issues, and update the cmake min target in the era of CMake 4.0 deprecating older versions. ## Consuming this library in cmake