gracicot / stb-cmake

A CMake packaged stb library
MIT License
7 stars 4 forks source link

Request for better readme/instructions #1

Open Falkgaard opened 4 years ago

Falkgaard commented 4 years ago

Hi,

Could you please make the readme a proper readme? I'm not quite sure how to use it after adding the submodule, doing a recursive init & update, and then adding a corresponding add_subdirectory() in my root CMakeLists.txt.

No matter if I do #include "stb/stb_image.h" or #include "stb_image.h" it gives me fatal errors. ("No such file or directory")

gracicot commented 4 years ago

Hi,

This repository was done pretty quick and dirty, and honestly I'm surprised to see the amount of activity it does right now. Seems like I'm not alone with this need.

There are two main ways to consume packages in CMake. The first is via find_package, and is usually the preferred way. The second is via add_subdirectory. This essentially make a mega-project where all the dependencies are part of it.


For the find_package way

Normally, you would either install the library (either system wide or in a project subdirectory) or use its build tree directly. Both should be done with find_package(stb REQUIRED).

So in essence, you should get the repository and build it using CMake. Then, should should either install it or set its root directory like this:

set(stb_ROOT "/path/to/std-cmake/build/")

Then do the find_package and target_link_libraries(your-target PUBLIC stb::image)

Since I exported the targets and the build tree, CMake will pick up the config correctly.


The add_subdirectory way

Well, in that case simply add the subdirectory. You'll also need to link your target to it:

# if you don't use stb in your public interface, change PUBLIC to PRIVATE
target_link_libraries(your-target PUBLIC stb::image)

I think I'll work on this project soon to make it more viable in general and make it more "official"