From 2fb1acd74b530c9b1cfd77ff5fd29896960b8189 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Fri, 7 Feb 2020 11:07:22 +0100 Subject: [PATCH] Add check for cereal library in CMake Fixes #3547, replaces #3613 --- CMakeLists.txt | 3 +-- cmake/modules/Findcereal.cmake | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 cmake/modules/Findcereal.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 878f2373e..e4e686645 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -392,8 +392,7 @@ if (NOT GLEW_FOUND) endif () # Find the Cereal serialization library -add_library(cereal INTERFACE) -target_include_directories(cereal INTERFACE include) +find_package(cereal REQUIRED) # l10n set(L10N_DIR "${SLIC3R_RESOURCES_DIR}/localization") diff --git a/cmake/modules/Findcereal.cmake b/cmake/modules/Findcereal.cmake new file mode 100644 index 000000000..b4829757e --- /dev/null +++ b/cmake/modules/Findcereal.cmake @@ -0,0 +1,26 @@ +set(_q "") +if(${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY) + set(_q QUIET) + set(_quietly TRUE) +endif() +find_package(${CMAKE_FIND_PACKAGE_NAME} ${${CMAKE_FIND_PACKAGE_NAME}_FIND_VERSION} CONFIG ${_q}) + +if (NOT ${CMAKE_FIND_PACKAGE_NAME}_FOUND) + # Fall-back solution to find the Cereal serialization library header file + include(CheckIncludeFileCXX) + add_library(cereal INTERFACE) + target_include_directories(cereal INTERFACE include) + + if (_quietly) + set(CMAKE_REQUIRED_QUIET ON) + endif() + CHECK_INCLUDE_FILE_CXX("cereal/cereal.hpp" HAVE_CEREAL_H) + + if (NOT HAVE_CEREAL_H) + if (${CMAKE_FIND_PACKAGE_NAME}_FIND_REQUIRED) + message(FATAL_ERROR "Cereal library not found. Please install the dependency.") + elseif(NOT _quietly) + message(WARNING "Cereal library not found.") + endif() + endif () +endif()