diff options
author | Ghostkeeper <rubend@tutanota.com> | 2018-05-08 18:14:07 +0300 |
---|---|---|
committer | Ghostkeeper <rubend@tutanota.com> | 2018-05-08 18:18:50 +0300 |
commit | 91b9ab15753b25c57b0f3fc8ae724206d53e8df8 (patch) | |
tree | 461be364b876a1c6f127440dbc256626fbbe517d /cmake | |
parent | 08c38253d17dd6232d25fa68ba808b6e9e786f5f (diff) |
Add find script for Stb
So that it finds an installation on your computer if you have it, and builds it from source if you don't have it.
Contributes to issue CURA-4513.
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/FindStb.cmake | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/cmake/FindStb.cmake b/cmake/FindStb.cmake new file mode 100644 index 000000000..b29a1816c --- /dev/null +++ b/cmake/FindStb.cmake @@ -0,0 +1,64 @@ +## Finds the Stb utility library on your computer. +# +# If Stb is not found on your computer, this script also gives the option to +# download the library and build it from source. +# +# This script exports the following parameters for use if you find the Stb +# package: +# - Stb_FOUND: Whether Stb has been found on your computer (or built from +# source). +# - Stb_INCLUDE_DIRS: The directory where the header files of Stb are located. + +#First try to find a PackageConfig for this library. +find_package(PkgConfig QUIET) +pkg_check_modules(PC_Stb QUIET Stb) + +find_path(Stb_INCLUDE_DIRS stb_image_resize.h #Search for something that is a little less prone to false positives than just stb.h. + HINTS ${PC_Stb_INCLUDEDIR} ${PC_Stb_INCLUDE_DIRS} + PATHS "$ENV{PROGRAMFILES}/stb" "$ENV{PROGRAMW6432}/stb" + PATH_SUFFIXES include/stb stb include +) + +include(FindPackageHandleStandardArgs) +set(_stb_find_required ${Stb_FIND_REQUIRED}) #Temporarily set to optional so that we don't get a message when it's not found but you want to build from source. +set(_stb_find_quietly ${Stb_FIND_QUIETLY}) +set(Stb_FIND_REQUIRED FALSE) +set(Stb_FIND_QUIETLY TRUE) +find_package_handle_standard_args(Stb DEFAULT_MSG Stb_INCLUDE_DIRS) +set(Stb_FIND_REQUIRED ${_stb_find_required}) +set(Stb_FIND_QUIETLY ${_stb_find_quietly}) + +if(Stb_FOUND) #Found an existing installation. + if(NOT Stb_FIND_QUIETLY) + message(STATUS "Found Stb installation at: ${Stb_INCLUDE_DIRS}") + endif() +else() + #Then optionally clone Stb ourselves. + option(BUILD_Stb "Build Stb from source." ON) #This is a lie actually, since Stb is header-only and doesn't need any building. We don't build the docs or tests. + if(BUILD_Stb) + if(NOT Stb_FIND_QUIETLY) + message(STATUS "Building Stb from source.") + endif() + + include(ExternalProject) + ExternalProject_Add(Stb + GIT_REPOSITORY "https://github.com/nothings/stb.git" + CONFIGURE_COMMAND "" #We don't want to actually go and build/test/generate it. Just need to download the headers. + BUILD_COMMAND "" + INSTALL_COMMAND "" #Assume that the user doesn't want to install all dependencies on his system. We just need to get them for building the application. + ) + set(Stb_INCLUDE_DIRS "${CMAKE_CURRENT_BINARY_DIR}/Stb-prefix/src/Stb") + set(Stb_FOUND TRUE) + if(NOT Stb_FIND_QUIETLY) + message(STATUS "Created Stb installation at: ${Stb_INCLUDE_DIRS}") + endif() + elseif(NOT Stb_FIND_QUIETLY) #Don't have an installation but don't want us to build it either? Screw you, then. + if(Stb_FIND_REQUIRED) + message(FATAL_ERROR "Could NOT find Stb.") + else() + message(WARNING "Could NOT find Stb.") + endif() + endif() +endif() + +mark_as_advanced(Stb_INCLUDE_DIRS)
\ No newline at end of file |