• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright Louis Dionne 2013-2017
2# Distributed under the Boost Software License, Version 1.0.
3# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
4
5add_custom_target(examples COMMENT "Build all the examples.")
6add_dependencies(hana_check examples)
7
8
9##############################################################################
10# Take note of files that depend on Boost
11##############################################################################
12list(APPEND EXAMPLES_REQUIRING_BOOST
13        "ext/boost/*.cpp"
14        "tutorial/appendix_mpl.cpp"
15        "tutorial/ext/fusion_to_hana.cpp"
16        "tutorial/ext/mpl_vector.cpp"
17        "tutorial/integral.cpp"
18        "tutorial/introduction.cpp"
19        "tutorial/mpl_cheatsheet.cpp"
20        "tutorial/quadrants.cpp"
21        "tutorial/quickstart.switchAny.cpp"
22        "tutorial/rationale.container.cpp"
23        "tutorial/type.cpp"
24        "type/basic_type.cpp")
25file(GLOB_RECURSE EXAMPLES_REQUIRING_BOOST ${EXAMPLES_REQUIRING_BOOST})
26
27
28##############################################################################
29# Caveats: Take note of examples that are not supported.
30##############################################################################
31if (NOT Boost_FOUND)
32    list(APPEND EXCLUDED_EXAMPLES ${EXAMPLES_REQUIRING_BOOST})
33endif()
34
35list(APPEND EXCLUDED_EXAMPLES "cmake_integration/main.cpp")
36
37
38##############################################################################
39# Add all the examples
40##############################################################################
41file(GLOB_RECURSE EXAMPLES "*.cpp")
42file(GLOB_RECURSE EXCLUDED_EXAMPLES ${EXCLUDED_EXAMPLES})
43list(REMOVE_ITEM EXAMPLES "" ${EXCLUDED_EXAMPLES})
44
45# Several examples have unused parameters because the name of the parameters
46# are useful for illustration, even if the implementation is not actually
47# presented. We don't want to generate warnings for that or need to comment
48# out all unused parameter names.
49include(CheckCXXCompilerFlag)
50check_cxx_compiler_flag(-Wno-unused-parameter BOOST_HANA_HAS_WNO_UNUSED_PARAMETER)
51check_cxx_compiler_flag(-Wno-unused-lambda-capture BOOST_HANA_HAS_WNO_UNUSED_LAMBDA_CAPTURE)
52
53foreach(_file IN LISTS EXAMPLES)
54    boost_hana_target_name_for(_target "${_file}")
55    add_executable(${_target} EXCLUDE_FROM_ALL "${_file}")
56    add_test(${_target} "${CMAKE_CURRENT_BINARY_DIR}/${_target}")
57    boost_hana_set_test_properties(${_target})
58    if (_file IN_LIST EXAMPLES_REQUIRING_BOOST)
59        target_link_libraries(${_target} PRIVATE Boost::boost)
60    endif()
61    if (BOOST_HANA_HAS_WNO_UNUSED_PARAMETER)
62        target_compile_options(${_target} PRIVATE -Wno-unused-parameter)
63    endif()
64    if (BOOST_HANA_HAS_WNO_UNUSED_LAMBDA_CAPTURE)
65        target_compile_options(${_target} PRIVATE -Wno-unused-lambda-capture)
66    endif()
67    add_dependencies(examples ${_target})
68endforeach()
69