Skip to content
Open
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
13 changes: 13 additions & 0 deletions recipes/stb/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.18)
project(stb LANGUAGES CXX)

set(STB_SOURCES "")
if(STB_IMAGE)
list(APPEND STB_SOURCES "stb_image.cpp")
endif()

if(STB_SOURCES)
add_library(${PROJECT_NAME} ${STB_SOURCES})
target_include_directories(${PROJECT_NAME} PRIVATE "${CMAKE_SOURCE_DIR}")
endif()

32 changes: 30 additions & 2 deletions recipes/stb/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from conan import ConanFile
from conan.tools.files import copy, get, rmdir
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import copy, get, rmdir, rm
from conan.tools.layout import basic_layout
from conan.tools.scm import Version
import os
Expand All @@ -19,10 +20,12 @@ class StbConan(ConanFile):
no_copy_source = True
options = {
"with_deprecated": [True, False],
"image": [True, False],
}

default_options = {
"with_deprecated": True,
"image": False,
}

@property
Expand All @@ -31,10 +34,18 @@ def _version(self):
# of the format cci.YYYYMMDD in tools.Version
return str(self.version)[4:]

@property
def _build_library(self):
return self.options.image

def config_options(self):
if Version(self._version) < "20210713":
del self.options.with_deprecated

def export_sources(self):
copy(self, pattern="CMakeLists.txt", src=self.recipe_folder, dst=os.path.join(self.export_sources_folder, "src"))
copy(self, pattern="stb_image.cpp", src=self.recipe_folder, dst=os.path.join(self.export_sources_folder, "src"))

def layout(self):
basic_layout(self, src_folder="src")

Expand All @@ -51,6 +62,20 @@ def package_id(self):
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def layout(self):
cmake_layout(self, src_folder="src")

def generate(self):
tc = CMakeToolchain(self)
if self.options.image:
tc.variables["STB_IMAGE"] = "ON"
Copy link
Contributor Author

@benjiwolff benjiwolff Mar 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am aware, that we are setting this variable and invoking cmake, just to compile 1 file.. I would prefer doing it without a build system, but I don't think conan offers something like that.
https://docs.conan.io/2/reference/tools.html

tc.generate()

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
copy(self, "*.h", src=self.source_folder, dst=os.path.join(self.package_folder, "include"))
Expand All @@ -61,10 +86,13 @@ def package(self):
if self.options.get_safe("with_deprecated"):
copy(self, "*.h", src=os.path.join(self.source_folder, "deprecated"), dst=os.path.join(self.package_folder, "include"))
copy(self, "stb_image.c", src=os.path.join(self.source_folder, "deprecated"), dst=os.path.join(self.package_folder, "include"))
copy(self, "lib*.a", src=self.build_folder, dst=os.path.join(self.package_folder, "lib"))
if not self.options.image:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the stb_image.h header is a breaking change I guess. Feel free to drop it.

rm(self, pattern="stb_image.h", folder=os.path.join(self.package_folder, "include"))

def package_info(self):
self.cpp_info.bindirs = []
self.cpp_info.libdirs = []
self.cpp_info.libs = ["stb"] if self._build_library else []
self.cpp_info.defines.append("STB_TEXTEDIT_KEYTYPE=unsigned")
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.append("m")
2 changes: 2 additions & 0 deletions recipes/stb/all/stb_image.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"