diff --git a/CMakeLists.txt b/CMakeLists.txt index 75b339bdbe..1bd776cdca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -339,15 +339,19 @@ if (NOT STB_IMAGE_FOUND) # Now we have to also ensure these header files get installed. install(FILES ${CMAKE_BINARY_DIR}/deps/${STB_DIR}/stb_image.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) install(FILES ${CMAKE_BINARY_DIR}/deps/${STB_DIR}/stb_image_write.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) + add_definitions(-DHAS_STB) else () list(GET STB_IMAGE_DOWNLOAD_STATUS_LIST 1 STB_DOWNLOAD_ERROR) - message(FATAL_ERROR + message(WARNING "Could not download stb! Error code ${STB_DOWNLOAD_STATUS}: ${STB_DOWNLOAD_ERROR}! Error log: ${STB_DOWNLOAD_LOG}") endif () else () - message(SEND_ERROR - "stb/stb_image.h not installed. Image utilites will not be available!") + message(WARNING + "stb/stb_image.h is not installed. Image utilites will not be available!") endif () +else () + # Already has STB installed. + add_definitions(-DHAS_STB) endif () # Find ensmallen. diff --git a/src/mlpack/core/data/load_image.hpp b/src/mlpack/core/data/load_image.hpp index 2aaa31625a..3a5665dfd4 100644 --- a/src/mlpack/core/data/load_image.hpp +++ b/src/mlpack/core/data/load_image.hpp @@ -13,6 +13,8 @@ #ifndef MLPACK_CORE_DATA_LOAD_IMAGE_HPP #define MLPACK_CORE_DATA_LOAD_IMAGE_HPP +#ifdef HAS_STB // Compile this only if stb is present. + #include #include #include @@ -204,4 +206,6 @@ class Image // Include implementation of Image. #include "load_image_impl.hpp" -#endif +#endif // HAS_STB. + +#endif \ No newline at end of file diff --git a/src/mlpack/core/data/load_image_impl.hpp b/src/mlpack/core/data/load_image_impl.hpp index 4359b534a8..8e021b693a 100644 --- a/src/mlpack/core/data/load_image_impl.hpp +++ b/src/mlpack/core/data/load_image_impl.hpp @@ -13,6 +13,8 @@ #ifndef MLPACK_CORE_DATA_LOAD_IMAGE_IMPL_HPP #define MLPACK_CORE_DATA_LOAD_IMAGE_IMPL_HPP +#ifdef HAS_STB // Compile this only if stb is present. + // In case it hasn't been included yet. #include "load_image.hpp" @@ -302,4 +304,6 @@ bool Image::LoadDir(const std::string& dirPath, } // namespace data } // namespace mlpack -#endif +#endif // HAS_STB. + +#endif \ No newline at end of file diff --git a/src/mlpack/tests/image_load_test.cpp b/src/mlpack/tests/image_load_test.cpp index 6bdde1186f..2e85bbd640 100644 --- a/src/mlpack/tests/image_load_test.cpp +++ b/src/mlpack/tests/image_load_test.cpp @@ -17,6 +17,8 @@ using namespace mlpack; using namespace std; +#ifdef HAS_STB // Compile this only if stb is present. + BOOST_AUTO_TEST_SUITE(ImageLoadTest); /** @@ -160,3 +162,5 @@ BOOST_AUTO_TEST_CASE(SaveMultipleImageTest) } BOOST_AUTO_TEST_SUITE_END(); + +#endif // HAS_STB. \ No newline at end of file