conan-io / conan-center-index

Recipes for the ConanCenter repository
https://conan.io/center
MIT License
928 stars 1.67k forks source link

[question] Should the STB recipe implementations be static libraries? #8398

Open Sebanisu opened 2 years ago

Sebanisu commented 2 years ago

The stb recipe is added via target_include_libraries(... stb::stb ...)

I was thinking maybe we should have static libraries added for the implimentations.

#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"

#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"

#define STB_DEFINE
#include "stb.h"

Where the library defined just includes the header after the #define or use target_compile_definitions. Then we can just add that to our include target_include_libraries(... stb::stb_main stb::image stb::image_write ...) and these libraries could have public includes of stb::stb

example cmake:

find_package(stb REQUIRED)
add_library(stbi_wrapper STATIC
        stbi.cpp)
target_link_libraries(stbi_wrapper
        PUBLIC stb::stb
        )
target_compile_definitions(stbi_wrapper
        PRIVATE STB_IMAGE_IMPLEMENTATION)

example cpp file:

#include <stb_image.h>

I used this in my project. I was getting a compiler error after enabling precompiled headers. So I used this small static library to offload the building of the implementation.

SpaceIm commented 2 years ago

C header only libraries with implementation macro are evil.

Regarding your suggestion:

Pros:

Cons:

Actually, I've implemented this logic in cgltf recipe, but I don't know whether it was a good idea.

Sebanisu commented 2 years ago

I think the default could be the current behavior so not to break anyone's code. I think having the recipe options could be nice to have.