2 # Copyright (c) 2017-2019 Mateusz Loskot <mateusz at loskot dot net>
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)
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.
13 cmake_minimum_required(VERSION 3.10)
15 #-----------------------------------------------------------------------------
17 #-----------------------------------------------------------------------------
18 option(GIL_BUILD_EXAMPLES "Build examples" ON)
19 option(GIL_BUILD_HEADER_TESTS "Enable self-contained header tests" ON)
20 option(GIL_ENABLE_EXT_DYNAMIC_IMAGE "Enable Dynamic Image extension, tests and examples" ON)
21 option(GIL_ENABLE_EXT_IO "Enable IO extension, tests and examples (require libjpeg, libpng, libtiff)" ON)
22 option(GIL_ENABLE_EXT_NUMERIC "Enable Numeric extension, tests and examples" ON)
23 option(GIL_ENABLE_EXT_TOOLBOX "Enable Toolbox extension, tests and examples" ON)
24 option(GIL_USE_CONAN "Use Conan to install dependencies" OFF)
25 option(GIL_USE_CLANG_TIDY "Set CMAKE_CXX_CLANG_TIDY property on targets to enable clang-tidy linting" OFF)
26 set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard version to use (default is 11)")
28 #-----------------------------------------------------------------------------
30 #-----------------------------------------------------------------------------
33 DESCRIPTION "Boost.GIL - Generic Image Library | Requires C++11 since Boost 1.68")
35 list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_BINARY_DIR}/cmake)
37 #-----------------------------------------------------------------------------
38 # C++ language version and compilation flags
39 #-----------------------------------------------------------------------------
40 message(STATUS "Boost.GIL: Require C++${CMAKE_CXX_STANDARD}")
41 set(CMAKE_CXX_STANDARD_REQUIRED ON)
42 set(CMAKE_CXX_EXTENSIONS OFF)
44 add_library(gil_compile_options INTERFACE)
46 # See https://cmake.org/pipermail/cmake/2018-December/068716.html
47 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
48 string(REGEX REPLACE "/W3" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
49 string(REGEX REPLACE "-W3" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
52 # See https://svn.boost.org/trac10/wiki/Guidelines/WarningsGuidelines
54 target_compile_options(gil_compile_options
56 $<$<CXX_COMPILER_ID:MSVC>:-W4>
57 $<$<CXX_COMPILER_ID:MSVC>:-bigobj>
58 $<$<CXX_COMPILER_ID:MSVC>:-FC> # Need absolute path for __FILE__ used in tests
59 $<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-fstrict-aliasing -pedantic>)
61 # Do not mix warnings due to strict compilation level with linter warnings
62 if(NOT CMAKE_CXX_CLANG_TIDY)
63 target_compile_options(gil_compile_options
65 $<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wall -Wconversion -Wextra -Wfloat-equal -Wshadow -Wsign-promo -Wstrict-aliasing -Wunused-parameter>)
68 target_compile_definitions(gil_compile_options
70 $<$<CXX_COMPILER_ID:MSVC>:_CRT_NONSTDC_NO_DEPRECATE>
71 $<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_DEPRECATE>
72 $<$<CXX_COMPILER_ID:MSVC>:_CRT_SECURE_NO_WARNINGS>
73 $<$<CXX_COMPILER_ID:MSVC>:NOMINMAX>
74 $<$<CXX_COMPILER_ID:MSVC>:BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE>)
76 #-----------------------------------------------------------------------------
78 #-----------------------------------------------------------------------------
79 add_library(gil_dependencies INTERFACE)
81 #-----------------------------------------------------------------------------
83 # - look for stage Build
84 # - look for default installation location
85 # - look for location specified with BOOST_ROOT
86 #-----------------------------------------------------------------------------
87 if(NOT DEFINED BOOST_ROOT AND NOT DEFINED ENV{BOOST_ROOT})
88 message(STATUS "Boost.GIL: Looking for Boost from current source tree and libraries from stage.")
89 message(STATUS "Boost.GIL: Disable stage look-up with passing -DBOOST_ROOT=/path/to/your/boost.")
90 get_filename_component(_boost_root ../../ ABSOLUTE)
91 if(EXISTS ${_boost_root}/boost-build.jam)
92 set(BOOST_ROOT ${_boost_root})
93 message(STATUS "Boost.GIL: Using Boost libraries from stage directory in BOOST_ROOT=${BOOST_ROOT}")
97 set(Boost_DETAILED_FAILURE_MSG ON)
98 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
99 set(Boost_USE_STATIC_LIBS ON)
100 set(Boost_USE_STATIC_RUNTIME OFF)
103 find_package(Boost 1.68.0 REQUIRED
107 message(STATUS "Boost.GIL: Using Boost_INCLUDE_DIRS=${Boost_INCLUDE_DIRS}")
108 message(STATUS "Boost.GIL: Using Boost_LIBRARY_DIRS=${Boost_LIBRARY_DIRS}")
110 target_link_libraries(gil_dependencies
113 Boost::unit_test_framework)
115 if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
116 target_link_libraries(gil_dependencies INTERFACE Boost::disable_autolinking)
119 target_compile_definitions(gil_dependencies
121 $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:BOOST_TEST_DYN_LINK>)
123 #-----------------------------------------------------------------------------
124 # Dependency: libpng, libjpeg, libtiff, libraw via Vcpkg or Conan
125 #-----------------------------------------------------------------------------
127 # Download automatically, you can also just copy the conan.cmake file
128 if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
129 message(STATUS "Boost.GIL: Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
130 file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/v0.14/conan.cmake"
131 "${CMAKE_BINARY_DIR}/conan.cmake")
134 # NOTE: See RelWithDebInfo for Release builds, http://docs.conan.io/en/latest/howtos/vs2017_cmake.html
135 set(_build_type_saved ${CMAKE_BUILD_TYPE})
136 if(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
137 set(CMAKE_BUILD_TYPE "Release")
140 include(${CMAKE_BINARY_DIR}/conan.cmake)
141 conan_cmake_run(CONANFILE conanfile.txt BASIC_SETUP CMAKE_TARGETS BUILD missing)
143 set(CMAKE_BUILD_TYPE ${_build_type_saved})
144 unset(_build_type_saved)
147 if(GIL_ENABLE_EXT_IO)
149 target_link_libraries(gil_dependencies
155 find_package(JPEG REQUIRED)
156 find_package(PNG REQUIRED)
157 find_package(TIFF REQUIRED)
158 target_include_directories(gil_dependencies
162 target_link_libraries(gil_dependencies
169 # Typically, Linux packages provide C++ stream interface for TIFF
170 find_path(TIFFXX_INCLUDE_DIR NAMES tiffio.hxx)
171 find_library(TIFFXX_LIBRARY NAMES tiffxx)
172 target_include_directories(gil_dependencies INTERFACE ${TIFFXX_INCLUDE_DIR})
173 target_link_libraries(gil_dependencies INTERFACE ${TIFFXX_LIBRARY})
176 # LibRaw is optional, because it is not easy to install pre-built libraw on Windows and Mac OSX
177 if(NOT EXISTS "${CMAKE_BINARY_DIR}/cmake/FindLibRaw.cmake")
178 message(STATUS "Boost.GIL: Downloading FindLibRaw.cmake from https://github.com/LibRaw/LibRaw-cmake")
180 "https://raw.githubusercontent.com/LibRaw/LibRaw-cmake/master/cmake/modules/FindLibRaw.cmake"
181 "${CMAKE_BINARY_DIR}/cmake/FindLibRaw.cmake")
184 set(GIL_ENABLE_EXT_IO_RAW ${LibRaw_FOUND} CACHE BOOL "Enable IO RAW extension (requires libraw)" FORCE)
185 if(GIL_ENABLE_EXT_IO_RAW)
186 target_include_directories(gil_dependencies INTERFACE ${LibRaw_INCLUDE_DIR})
187 target_link_libraries(gil_dependencies INTERFACE ${LibRaw_LIBRARIES})
188 target_compile_definitions(gil_dependencies INTERFACE ${LibRaw_DEFINITIONS})
193 #-----------------------------------------------------------------------------
195 # - default checks specified in .clang-tidy configuration file
196 #-----------------------------------------------------------------------------
197 if(GIL_USE_CLANG_TIDY AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.6)
198 find_program(_clang_tidy
199 NAMES clang-tidy-7 clang-tidy-6.0 clang-tidy-5.0 clang-tidy-4.0 clang-tidy
200 DOC "Path to clang-tidy executable")
203 message(STATUS "Boost.GIL: Configuring ${_clang_tidy} to run linting analysis for targets")
204 set(CMAKE_CXX_CLANG_TIDY ${_clang_tidy})
209 #-----------------------------------------------------------------------------
210 # Common include directories
212 # The boostorg/gil repository includes must come first,
213 # before Boost includes from cloned Boost superproject or installed distribution.
214 # Otherwise IDEs may see the wrong file (ie. due to boost/ symlinks or
215 # GIL headers from installed Boost instead of this clone of boostog/gil).
216 #-----------------------------------------------------------------------------
217 add_library(gil_include_directories INTERFACE)
218 target_include_directories(gil_include_directories
221 ${CMAKE_CURRENT_SOURCE_DIR}/include
222 ${CMAKE_CURRENT_SOURCE_DIR}/test)
224 #-----------------------------------------------------------------------------
226 #-----------------------------------------------------------------------------
229 # On CI services, test the self-contained headers on-demand only to avoid build timeouts.
230 # CI environment is common for Travis CI, AppVeyor, CircleCI, etc.
231 # On Boost regression builds, CMake does not run, but Boost.Build,
232 # so the header tests are not enabled there either.
234 set(GIL_BUILD_HEADER_TESTS OFF)
237 add_subdirectory(test)
239 #-----------------------------------------------------------------------------
241 #-----------------------------------------------------------------------------
242 if(GIL_BUILD_EXAMPLES AND GIL_ENABLE_EXT_IO)
243 add_subdirectory(example)