-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[stb] Add option for precompiled image #29686
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
benjiwolff
wants to merge
2
commits into
conan-io:master
Choose a base branch
from
benjiwolff:add-precompiled-image-option-to-stb
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+45
−2
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,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() | ||
|
|
This file contains hidden or 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,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 | ||
|
|
@@ -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 | ||
|
|
@@ -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") | ||
|
|
||
|
|
@@ -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" | ||
| 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")) | ||
|
|
@@ -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: | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing the |
||
| 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") | ||
This file contains hidden or 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,2 @@ | ||
| #define STB_IMAGE_IMPLEMENTATION | ||
| #include "stb_image.h" |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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