CMakeLists.txt 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. #
  13. cmake_minimum_required(VERSION 3.10)
  14. #-----------------------------------------------------------------------------
  15. # Options
  16. #-----------------------------------------------------------------------------
  17. option(GIL_BUILD_EXAMPLES "Build examples" ON)
  18. option(GIL_BUILD_HEADER_TESTS "Enable self-contained header tests" ON)
  19. option(GIL_ENABLE_EXT_DYNAMIC_IMAGE "Enable Dynamic Image extension, tests and examples" ON)
  20. option(GIL_ENABLE_EXT_IO "Enable IO extension, tests and examples (require libjpeg, libpng, libtiff)" ON)
  21. option(GIL_ENABLE_EXT_NUMERIC "Enable Numeric extension, tests and examples" ON)
  22. option(GIL_ENABLE_EXT_TOOLBOX "Enable Toolbox extension, tests and examples" ON)
  23. option(GIL_USE_CONAN "Use Conan to install dependencies" OFF)
  24. option(GIL_USE_CLANG_TIDY "Set CMAKE_CXX_CLANG_TIDY property on targets to enable clang-tidy linting" OFF)
  25. set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard version to use (default is 11)")
  26. #-----------------------------------------------------------------------------
  27. # Project
  28. #-----------------------------------------------------------------------------
  29. project(Boost.GIL
  30. LANGUAGES CXX
  31. DESCRIPTION "Boost.GIL - Generic Image Library | Requires C++11 since Boost 1.68")
  32. list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_BINARY_DIR}/cmake)
  33. #-----------------------------------------------------------------------------
  34. # C++ language version and compilation flags
  35. #-----------------------------------------------------------------------------
  36. message(STATUS "Boost.GIL: Require C++${CMAKE_CXX_STANDARD}")
  37. set(CMAKE_CXX_STANDARD_REQUIRED ON)
  38. set(CMAKE_CXX_EXTENSIONS OFF)
  39. add_library(gil_compile_options INTERFACE)
  40. # See https://cmake.org/pipermail/cmake/2018-December/068716.html
  41. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
  42. string(REGEX REPLACE "/W3" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
  43. string(REGEX REPLACE "-W3" "" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
  44. endif()
  45. # See https://svn.boost.org/trac10/wiki/Guidelines/WarningsGuidelines
  46. target_compile_options(gil_compile_options
  47. INTERFACE
  48. $<$<CXX_COMPILER_ID:MSVC>:-W4>
  49. $<$<CXX_COMPILER_ID:MSVC>:-bigobj>
  50. $<$<CXX_COMPILER_ID:MSVC>:-FC> # Need absolute path for __FILE__ used in tests
  51. $<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-fstrict-aliasing -pedantic>)
  52. # Do not mix warnings due to strict compilation level with linter warnings
  53. if(NOT CMAKE_CXX_CLANG_TIDY)
  54. target_compile_options(gil_compile_options
  55. INTERFACE
  56. $<$<OR:$<CXX_COMPILER_ID:GNU>,$<CXX_COMPILER_ID:Clang>>:-Wall -Wconversion -Wextra -Wfloat-equal -Wshadow -Wsign-promo -Wstrict-aliasing -Wunused-parameter>)
  57. endif()
  58. target_compile_definitions(gil_compile_options
  59. INTERFACE
  60. $<$<CXX_COMPILER_ID:MSVC>:_CRT_NONSTDC_NO_DEPRECATE>
  61. $<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_DEPRECATE>
  62. $<$<CXX_COMPILER_ID:MSVC>:_CRT_SECURE_NO_WARNINGS>
  63. $<$<CXX_COMPILER_ID:MSVC>:NOMINMAX>
  64. $<$<CXX_COMPILER_ID:MSVC>:BOOST_CONFIG_SUPPRESS_OUTDATED_MESSAGE>)
  65. #-----------------------------------------------------------------------------
  66. # Dependency target
  67. #-----------------------------------------------------------------------------
  68. add_library(gil_dependencies INTERFACE)
  69. #-----------------------------------------------------------------------------
  70. # Dependency: Boost
  71. # - look for stage Build
  72. # - look for default installation location
  73. # - look for location specified with BOOST_ROOT
  74. #-----------------------------------------------------------------------------
  75. if(NOT DEFINED BOOST_ROOT AND NOT DEFINED ENV{BOOST_ROOT})
  76. message(STATUS "Boost.GIL: Looking for Boost from current source tree and libraries from stage.")
  77. message(STATUS "Boost.GIL: Disable stage look-up with passing -DBOOST_ROOT=/path/to/your/boost.")
  78. get_filename_component(_boost_root ../../ ABSOLUTE)
  79. if(EXISTS ${_boost_root}/boost-build.jam)
  80. set(BOOST_ROOT ${_boost_root})
  81. message(STATUS "Boost.GIL: Using Boost libraries from stage directory in BOOST_ROOT=${BOOST_ROOT}")
  82. endif()
  83. endif()
  84. set(Boost_DETAILED_FAILURE_MSG ON)
  85. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
  86. set(Boost_USE_STATIC_LIBS ON)
  87. set(Boost_USE_STATIC_RUNTIME OFF)
  88. endif()
  89. find_package(Boost 1.68.0 REQUIRED
  90. COMPONENTS
  91. filesystem
  92. unit_test_framework)
  93. message(STATUS "Boost.GIL: Using Boost_INCLUDE_DIRS=${Boost_INCLUDE_DIRS}")
  94. message(STATUS "Boost.GIL: Using Boost_LIBRARY_DIRS=${Boost_LIBRARY_DIRS}")
  95. target_link_libraries(gil_dependencies
  96. INTERFACE
  97. Boost::filesystem
  98. Boost::unit_test_framework)
  99. if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
  100. target_link_libraries(gil_dependencies INTERFACE Boost::disable_autolinking)
  101. endif()
  102. target_compile_definitions(gil_dependencies
  103. INTERFACE
  104. $<$<NOT:$<CXX_COMPILER_ID:MSVC>>:BOOST_TEST_DYN_LINK>)
  105. #-----------------------------------------------------------------------------
  106. # Dependency: libpng, libjpeg, libtiff, libraw via Vcpkg or Conan
  107. #-----------------------------------------------------------------------------
  108. if(GIL_USE_CONAN)
  109. # Download automatically, you can also just copy the conan.cmake file
  110. if(NOT EXISTS "${CMAKE_BINARY_DIR}/conan.cmake")
  111. message(STATUS "Boost.GIL: Downloading conan.cmake from https://github.com/conan-io/cmake-conan")
  112. file(DOWNLOAD "https://raw.githubusercontent.com/conan-io/cmake-conan/v0.14/conan.cmake"
  113. "${CMAKE_BINARY_DIR}/conan.cmake")
  114. endif()
  115. # NOTE: See RelWithDebInfo for Release builds, http://docs.conan.io/en/latest/howtos/vs2017_cmake.html
  116. set(_build_type_saved ${CMAKE_BUILD_TYPE})
  117. if(CMAKE_BUILD_TYPE STREQUAL "MinSizeRel" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
  118. set(CMAKE_BUILD_TYPE "Release")
  119. endif()
  120. include(${CMAKE_BINARY_DIR}/conan.cmake)
  121. conan_cmake_run(CONANFILE conanfile.txt BASIC_SETUP CMAKE_TARGETS BUILD missing)
  122. set(CMAKE_BUILD_TYPE ${_build_type_saved})
  123. unset(_build_type_saved)
  124. endif()
  125. if(GIL_ENABLE_EXT_IO)
  126. if (GIL_USE_CONAN)
  127. target_link_libraries(gil_dependencies
  128. INTERFACE
  129. CONAN_PKG::libjpeg
  130. CONAN_PKG::libpng
  131. CONAN_PKG::libtiff)
  132. else()
  133. find_package(JPEG REQUIRED)
  134. find_package(PNG REQUIRED)
  135. find_package(TIFF REQUIRED)
  136. target_include_directories(gil_dependencies
  137. INTERFACE
  138. ${JPEG_INCLUDE_DIR})
  139. target_link_libraries(gil_dependencies
  140. INTERFACE
  141. ${JPEG_LIBRARIES}
  142. PNG::PNG
  143. TIFF::TIFF)
  144. if(UNIX)
  145. # Typically, Linux packages provide C++ stream interface for TIFF
  146. find_path(TIFFXX_INCLUDE_DIR NAMES tiffio.hxx)
  147. find_library(TIFFXX_LIBRARY NAMES tiffxx)
  148. target_include_directories(gil_dependencies INTERFACE ${TIFFXX_INCLUDE_DIR})
  149. target_link_libraries(gil_dependencies INTERFACE ${TIFFXX_LIBRARY})
  150. endif()
  151. # LibRaw is optional, because it is not easy to install pre-built libraw on Windows and Mac OSX
  152. if(NOT EXISTS "${CMAKE_BINARY_DIR}/cmake/FindLibRaw.cmake")
  153. message(STATUS "Boost.GIL: Downloading FindLibRaw.cmake from https://github.com/LibRaw/LibRaw-cmake")
  154. file(DOWNLOAD
  155. "https://raw.githubusercontent.com/LibRaw/LibRaw-cmake/master/cmake/modules/FindLibRaw.cmake"
  156. "${CMAKE_BINARY_DIR}/cmake/FindLibRaw.cmake")
  157. endif()
  158. find_package(LibRaw)
  159. set(GIL_ENABLE_EXT_IO_RAW ${LibRaw_FOUND} CACHE BOOL "Enable IO RAW extension (requires libraw)" FORCE)
  160. if(GIL_ENABLE_EXT_IO_RAW)
  161. target_include_directories(gil_dependencies INTERFACE ${LibRaw_INCLUDE_DIR})
  162. target_link_libraries(gil_dependencies INTERFACE ${LibRaw_LIBRARIES})
  163. target_compile_definitions(gil_dependencies INTERFACE ${LibRaw_DEFINITIONS})
  164. endif()
  165. endif()
  166. endif()
  167. #-----------------------------------------------------------------------------
  168. # clang-tidy
  169. # - default checks specified in .clang-tidy configuration file
  170. #-----------------------------------------------------------------------------
  171. if(GIL_USE_CLANG_TIDY AND CMAKE_VERSION VERSION_GREATER_EQUAL 3.6)
  172. find_program(_clang_tidy
  173. NAMES clang-tidy-7 clang-tidy-6.0 clang-tidy-5.0 clang-tidy-4.0 clang-tidy
  174. DOC "Path to clang-tidy executable")
  175. if(_clang_tidy)
  176. message(STATUS "Boost.GIL: Configuring ${_clang_tidy} to run linting analysis for targets")
  177. set(CMAKE_CXX_CLANG_TIDY ${_clang_tidy})
  178. endif()
  179. unset(_clang_tidy)
  180. endif()
  181. #-----------------------------------------------------------------------------
  182. # Common include directories
  183. #
  184. # The boostorg/gil repository includes must come first,
  185. # before Boost includes from cloned Boost superproject or installed distribution.
  186. # Otherwise IDEs may see the wrong file (ie. due to boost/ symlinks or
  187. # GIL headers from installed Boost instead of this clone of boostog/gil).
  188. #-----------------------------------------------------------------------------
  189. add_library(gil_include_directories INTERFACE)
  190. target_include_directories(gil_include_directories
  191. BEFORE
  192. INTERFACE
  193. ${CMAKE_CURRENT_SOURCE_DIR}/include
  194. ${CMAKE_CURRENT_SOURCE_DIR}/test)
  195. #-----------------------------------------------------------------------------
  196. # Tests
  197. #-----------------------------------------------------------------------------
  198. enable_testing()
  199. # On CI services, test the self-contained headers on-demand only to avoid build timeouts.
  200. # CI environment is common for Travis CI, AppVeyor, CircleCI, etc.
  201. # On Boost regression builds, CMake does not run, but Boost.Build,
  202. # so the header tests are not enabled there either.
  203. if(DEFINED ENV{CI})
  204. set(GIL_BUILD_HEADER_TESTS OFF)
  205. endif()
  206. add_subdirectory(test)
  207. #-----------------------------------------------------------------------------
  208. # Examples
  209. #-----------------------------------------------------------------------------
  210. if(GIL_BUILD_EXAMPLES AND GIL_ENABLE_EXT_IO)
  211. add_subdirectory(example)
  212. endif()