Imported Upstream version 1.72.0
[platform/upstream/boost.git] / libs / gil / test / header / CMakeLists.txt
1 #
2 # Copyright (c) 2018 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
9 # List headers in order: concepts, core, io, extensions
10 file(GLOB_RECURSE _hpp_concepts RELATIVE
11   "${CMAKE_SOURCE_DIR}/include/boost/gil"
12   "${CMAKE_SOURCE_DIR}/include/boost/gil/concepts/*.hpp")
13 list(APPEND _headers ${_hpp_concepts})
14
15 file(GLOB _hpp_core RELATIVE
16   "${CMAKE_SOURCE_DIR}/include/boost/gil"
17   "${CMAKE_SOURCE_DIR}/include/boost/gil/*.hpp")
18 list(APPEND _headers ${_hpp_core})
19
20 list(APPEND _ext_dirs extension/dynamic_image/)
21 if(GIL_ENABLE_EXT_NUMERIC)
22   list(APPEND _ext_dirs extension/numeric)
23 endif()
24 if(GIL_ENABLE_EXT_TOOLBOX)
25   list(APPEND _ext_dirs extension/toolbox)
26 endif()
27 if(GIL_ENABLE_EXT_IO)
28   list(APPEND _ext_dirs io)
29   list(APPEND _ext_dirs extension/io)
30 endif()
31
32 foreach(_dir ${_ext_dirs})
33   file(GLOB_RECURSE _hpp RELATIVE
34     "${CMAKE_SOURCE_DIR}/include/boost/gil"
35     "${CMAKE_SOURCE_DIR}/include/boost/gil/${_dir}/*.hpp")
36   list(APPEND _headers ${_hpp})
37 endforeach()
38
39 if(NOT GIL_ENABLE_EXT_IO_RAW)
40   list(FILTER _headers EXCLUDE REGEX "\\/raw[\\.\\/]")
41 endif()
42
43 #-----------------------------------------------------------------------------
44 # Target: test_headers_self_contained
45 # Bundles all targets of self-contained header tests,
46 # functional equivalent to self-contained header tests defined in Jamfile.
47 #-----------------------------------------------------------------------------
48 message(STATUS "Boost.GIL: Configuring self-contained header tests for all headers")
49 add_custom_target(test_headers_self_contained)
50
51 file(READ ${CMAKE_CURRENT_LIST_DIR}/main.cpp _main_content)
52
53 foreach(_header ${_headers})
54   string(REPLACE ".hpp" "" _target ${_header})
55   string(REPLACE "/" "-" _target ${_target})
56   set(_cpp ${CMAKE_BINARY_DIR}/test/headers/${_target}.cpp)
57   set(_target test_header_${_target})
58
59   string(REPLACE "BOOST_GIL_TEST_HEADER" "${_header}" _content "${_main_content}")
60   file(WRITE ${_cpp} "${_content}")
61   unset(_content)
62
63   add_executable(${_target})
64
65   target_sources(${_target}
66     PRIVATE
67       ${_cpp}
68       ${CMAKE_SOURCE_DIR}/include/boost/gil/${_header})
69   unset(_cpp)
70
71   target_link_libraries(${_target}
72     PRIVATE
73       gil_compile_options
74       gil_include_directories
75       gil_dependencies)
76
77   add_dependencies(test_headers_self_contained ${_target})
78
79   unset(_target)
80 endforeach()
81
82 #-----------------------------------------------------------------------------
83 # Target: test_headers_all_in_one
84 # Verifies compilation of all headers included in one translation unit.
85 # An extra advantage is that such translation unit can be analysed with clang-tidy, etc.
86 #-----------------------------------------------------------------------------
87 message(STATUS "Boost.GIL: Configuring all-in-one headers test for all headers")
88
89 set(_cpp ${CMAKE_BINARY_DIR}/test/headers/test_headers_all_in_one.cpp)
90 file(WRITE ${_cpp} "// All headers included in one translation unit\n")
91 foreach(_header ${_headers})
92   file(APPEND ${_cpp} "#include <boost/gil/${_header}>\n")
93 endforeach()
94 unset(_headers)
95 file(APPEND ${_cpp} "int main() { return 0; }\n")
96
97 add_executable(test_headers_all_in_one)
98
99 target_sources(test_headers_all_in_one PRIVATE ${_cpp})
100 unset(_cpp)
101
102 target_link_libraries(test_headers_all_in_one
103   PRIVATE
104     gil_compile_options
105     gil_include_directories
106     gil_dependencies)