1# 2# Copyright (c) 2017-2019 Mateusz Loskot <mateusz at loskot dot net> 3# 4# Distributed under the Boost Software License, Version 1.0. 5# (See accompanying file LICENSE_1_0.txt or copy at 6# http://www.boost.org/LICENSE_1_0.txt) 7# 8# **WARNING:** 9# The CMake configuration is only provided for convenience 10# of contributors. It does not export or install any targets, 11# deploy config files or support subproject workflow. 12# 13cmake_minimum_required(VERSION 3.10) 14 15#----------------------------------------------------------------------------- 16# Options 17#----------------------------------------------------------------------------- 18option(BOOST_GIL_BUILD_EXAMPLES "Build examples" ON) 19option(BOOST_GIL_BUILD_HEADER_TESTS "Enable self-contained header tests" ON) 20option(BOOST_GIL_ENABLE_EXT_DYNAMIC_IMAGE "Enable Dynamic Image extension, tests and examples" ON) 21option(BOOST_GIL_ENABLE_EXT_IO "Enable IO extension, tests and examples (require libjpeg, libpng, libtiff)" ON) 22option(BOOST_GIL_ENABLE_EXT_NUMERIC "Enable Numeric extension, tests and examples" ON) 23option(BOOST_GIL_ENABLE_EXT_TOOLBOX "Enable Toolbox extension, tests and examples" ON) 24option(BOOST_GIL_USE_CONAN "Use Conan to install dependencies" OFF) 25option(BOOST_GIL_USE_CLANG_TIDY "Set CMAKE_CXX_CLANG_TIDY property on targets to enable clang-tidy linting" OFF) 26set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard version to use (default is 11)") 27 28#----------------------------------------------------------------------------- 29# Project 30#----------------------------------------------------------------------------- 31project(Boost.GIL 32 LANGUAGES CXX 33 DESCRIPTION "Boost.GIL - Generic Image Library | Requires C++11 since Boost 1.68") 34 35list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_BINARY_DIR}/cmake) 36 37#----------------------------------------------------------------------------- 38# C++ language version and compilation flags 39#----------------------------------------------------------------------------- 40message(STATUS "Boost.GIL: Require C++${CMAKE_CXX_STANDARD}") 41set(CMAKE_CXX_STANDARD_REQUIRED ON) 42set(CMAKE_CXX_EXTENSIONS OFF) 43 44# Avoid warnings flood on Travis CI, AppVeyor, CircleCI, Azure Pipelines 45if(DEFINED ENV{CI} OR DEFINED ENV{AGENT_JOBSTATUS} OR DEFINED ENV{GITHUB_ACTIONS}) 46 set(BOOST_GIL_BUILD_CI ON) 47 message(STATUS "Boost.GIL: Turning off detailed compiler warnings for CI build short log") 48else() 49 set(BOOST_GIL_BUILD_CI OFF) 50 message(STATUS "Boost.GIL: Turning on detailed compiler warnings") 51endif() 52 53add_library(gil_compile_options INTERFACE) 54 55# See https://cmake.org/pipermail/cmake/2018-December/068716.html 56if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 57 string(REGEX REPLACE "/W3" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) 58 string(REGEX REPLACE "-W3" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) 59endif() 60 61# See https://svn.boost.org/trac10/wiki/Guidelines/WarningsGuidelines 62target_compile_options(gil_compile_options 63 INTERFACE 64 $<$<AND:$<CXX_COMPILER_ID:MSVC>,$<BOOL:${BOOST_GIL_BUILD_CI}>>:-W1> 65 $<$<AND:$<CXX_COMPILER_ID:MSVC>,$<NOT:$<BOOL:${BOOST_GIL_BUILD_CI}>>>:-W4> 66 $<$<CXX_COMPILER_ID:MSVC>:-bigobj> 67 $<$<CXX_COMPILER_ID:MSVC>:-FC> # Need absolute path for __FILE__ used in tests 68 $<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-fstrict-aliasing> 69 $<$<AND:$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>,$<NOT:$<BOOL:${BOOST_GIL_BUILD_CI}>>>:-Wall -Wconversion -Wextra -Wfloat-equal -Wshadow -Wsign-promo -Wstrict-aliasing -Wunused-parameter -pedantic>) 70 71target_compile_definitions(gil_compile_options 72 INTERFACE 73 $<$<CXX_COMPILER_ID:MSVC>:_CRT_NONSTDC_NO_DEPRECATE> 74 $<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_DEPRECATE> 75 $<$<CXX_COMPILER_ID:MSVC>:_CRT_SECURE_NO_WARNINGS> 76 $<$<CXX_COMPILER_ID:MSVC>:NOMINMAX> 77 $<$<CXX_COMPILER_ID:MSVC>:BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE>) 78 79#----------------------------------------------------------------------------- 80# Dependency target 81#----------------------------------------------------------------------------- 82add_library(gil_dependencies INTERFACE) 83 84#----------------------------------------------------------------------------- 85# Dependency: Boost 86# - look for stage Build 87# - look for default installation location 88# - look for location specified with BOOST_ROOT 89#----------------------------------------------------------------------------- 90if(NOT DEFINED BOOST_ROOT AND NOT DEFINED ENV{BOOST_ROOT}) 91 message(STATUS "Boost.GIL: Looking for Boost from current source tree and libraries from stage.") 92 message(STATUS "Boost.GIL: Disable stage look-up with passing -DBOOST_ROOT=/path/to/your/boost.") 93 get_filename_component(_boost_root ../../ ABSOLUTE) 94 if(EXISTS ${_boost_root}/boost-build.jam) 95 set(BOOST_ROOT ${_boost_root}) 96 message(STATUS "Boost.GIL: Using Boost libraries from stage directory in BOOST_ROOT=${BOOST_ROOT}") 97 endif() 98endif() 99 100set(Boost_DETAILED_FAILURE_MSG ON) 101if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 102 set(Boost_USE_STATIC_LIBS ON) 103 set(Boost_USE_STATIC_RUNTIME OFF) 104endif() 105 106find_package(Boost 1.72.0 REQUIRED COMPONENTS filesystem) 107message(STATUS "Boost.GIL: Using Boost_INCLUDE_DIRS=${Boost_INCLUDE_DIRS}") 108message(STATUS "Boost.GIL: Using Boost_LIBRARY_DIRS=${Boost_LIBRARY_DIRS}") 109 110target_link_libraries(gil_dependencies INTERFACE Boost::filesystem) 111 112if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 113 target_link_libraries(gil_dependencies INTERFACE Boost::disable_autolinking) 114endif() 115 116target_compile_definitions(gil_dependencies 117 INTERFACE 118 $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:BOOST_TEST_DYN_LINK>) 119 120#----------------------------------------------------------------------------- 121# Dependency: libpng, libjpeg, libtiff, libraw via Vcpkg or Conan 122#----------------------------------------------------------------------------- 123if(BOOST_GIL_USE_CONAN) 124 # Download automatically, you can also just copy the conan.cmake file 125 if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake") 126 message(STATUS "Boost.GIL: Downloading conan.cmake from https://github.com/conan-io/cmake-conan") 127 file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/v0.15/conan.cmake" 128 "${CMAKE_BINARY_DIR}/conan.cmake") 129 endif() 130 131 # NOTE: See RelWithDebInfo for Release builds, http://docs.conan.io/en/latest/howtos/vs2017_cmake.html 132 set(_build_type_saved ${CMAKE_BUILD_TYPE}) 133 if(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") 134 set(CMAKE_BUILD_TYPE "Release") 135 endif() 136 137 include(${CMAKE_BINARY_DIR}/conan.cmake) 138 conan_cmake_run(CONANFILE conanfile.txt BASIC_SETUP CMAKE_TARGETS BUILD missing) 139 140 set(CMAKE_BUILD_TYPE ${_build_type_saved}) 141 unset(_build_type_saved) 142endif() 143 144if(BOOST_GIL_ENABLE_EXT_IO) 145 if (BOOST_GIL_USE_CONAN) 146 target_link_libraries(gil_dependencies 147 INTERFACE 148 CONAN_PKG::libjpeg 149 CONAN_PKG::libpng 150 CONAN_PKG::libtiff) 151 else() 152 find_package(JPEG REQUIRED) 153 find_package(PNG REQUIRED) 154 find_package(TIFF REQUIRED) 155 target_include_directories(gil_dependencies 156 INTERFACE 157 ${JPEG_INCLUDE_DIR}) 158 159 target_link_libraries(gil_dependencies 160 INTERFACE 161 ${JPEG_LIBRARIES} 162 PNG::PNG 163 TIFF::TIFF) 164 165 if (TIFF_LIBRARY) 166 set(TIFFXX_NAMES tiffxx) 167 foreach(name ${TIFFXX_NAMES}) 168 list(APPEND TIFFXX_NAMES_DEBUG "${name}d") 169 endforeach() 170 find_library(TIFFXX_LIBRARY_RELEASE NAMES ${TIFFXX_NAMES}) 171 find_library(TIFFXX_LIBRARY_DEBUG NAMES ${TIFFXX_NAMES_DEBUG}) 172 find_path(TIFFXX_INCLUDE_DIR NAMES tiffio.hxx) 173 include(SelectLibraryConfigurations) 174 select_library_configurations(TIFFXX) 175 mark_as_advanced(TIFFXX_LIBRARY_RELEASE TIFFXX_LIBRARY_DEBUG) 176 include(FindPackageHandleStandardArgs) 177 find_package_handle_standard_args(TIFFXX REQUIRED_VARS TIFFXX_LIBRARY TIFFXX_INCLUDE_DIR) 178 target_include_directories(gil_dependencies INTERFACE ${TIFFXX_INCLUDE_DIR}) 179 target_link_libraries(gil_dependencies INTERFACE ${TIFFXX_LIBRARY}) 180 endif() 181 182 # LibRaw is optional, because it is not easy to install pre-built libraw on Windows and Mac OSX 183 if(NOT EXISTS "${CMAKE_BINARY_DIR}/cmake/FindLibRaw.cmake") 184 message(STATUS "Boost.GIL: Downloading FindLibRaw.cmake from https://github.com/LibRaw/LibRaw-cmake") 185 file(DOWNLOAD 186 "https://raw.githubusercontent.com/LibRaw/LibRaw-cmake/master/cmake/modules/FindLibRaw.cmake" 187 "${CMAKE_BINARY_DIR}/cmake/FindLibRaw.cmake") 188 endif() 189 find_package(LibRaw) 190 set(BOOST_GIL_ENABLE_EXT_IO_RAW ${LibRaw_FOUND} CACHE BOOL "Enable IO RAW extension (requires libraw)" FORCE) 191 if(BOOST_GIL_ENABLE_EXT_IO_RAW) 192 target_include_directories(gil_dependencies INTERFACE ${LibRaw_INCLUDE_DIR}) 193 target_link_libraries(gil_dependencies INTERFACE ${LibRaw_LIBRARIES}) 194 target_compile_definitions(gil_dependencies INTERFACE ${LibRaw_DEFINITIONS}) 195 endif() 196 endif() 197endif() 198 199#----------------------------------------------------------------------------- 200# clang-tidy 201# - default checks specified in .clang-tidy configuration file 202#----------------------------------------------------------------------------- 203if(BOOST_GIL_USE_CLANG_TIDY AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.6) 204 find_program(_clang_tidy 205 NAMES clang-tidy-7 clang-tidy-6.0 clang-tidy-5.0 clang-tidy-4.0 clang-tidy 206 DOC "Path to clang-tidy executable") 207 208 if(_clang_tidy) 209 message(STATUS "Boost.GIL: Configuring ${_clang_tidy} to run linting analysis for targets") 210 set(CMAKE_CXX_CLANG_TIDY ${_clang_tidy}) 211 endif() 212 unset(_clang_tidy) 213endif() 214 215#----------------------------------------------------------------------------- 216# Common include directories 217# 218# The boostorg/gil repository includes must come first, 219# before Boost includes from cloned Boost superproject or installed distribution. 220# Otherwise IDEs may see the wrong file (ie. due to boost/ symlinks or 221# GIL headers from installed Boost instead of this clone of boostog/gil). 222#----------------------------------------------------------------------------- 223add_library(gil_include_directories INTERFACE) 224target_include_directories(gil_include_directories 225 BEFORE 226 INTERFACE 227 ${CMAKE_CURRENT_SOURCE_DIR}/include 228 ${CMAKE_CURRENT_SOURCE_DIR}/test) 229 230#----------------------------------------------------------------------------- 231# Tests 232#----------------------------------------------------------------------------- 233include(CTest) 234 235if(BUILD_TESTING) 236 # On CI services, test the self-contained headers on-demand only to avoid build timeouts. 237 # CI environment is common for Travis CI, AppVeyor, CircleCI, etc. 238 # On Boost regression builds, CMake does not run, but Boost.Build, 239 # so the header tests are not enabled there either. 240 if(DEFINED ENV{CI}) 241 set(BOOST_GIL_BUILD_HEADER_TESTS OFF) 242 endif() 243 244 add_subdirectory(test) 245endif() 246 247#----------------------------------------------------------------------------- 248# Examples 249#----------------------------------------------------------------------------- 250if(BOOST_GIL_BUILD_EXAMPLES AND BOOST_GIL_ENABLE_EXT_IO) 251 add_subdirectory(example) 252endif() 253