CMakeLists.txt 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. add_custom_target(examples COMMENT "Build all the examples.")
  5. add_dependencies(hana_check examples)
  6. ##############################################################################
  7. # Take note of files that depend on Boost
  8. ##############################################################################
  9. list(APPEND EXAMPLES_REQUIRING_BOOST
  10. "ext/boost/*.cpp"
  11. "tutorial/appendix_mpl.cpp"
  12. "tutorial/ext/fusion_to_hana.cpp"
  13. "tutorial/ext/mpl_vector.cpp"
  14. "tutorial/integral.cpp"
  15. "tutorial/introduction.cpp"
  16. "tutorial/mpl_cheatsheet.cpp"
  17. "tutorial/quadrants.cpp"
  18. "tutorial/quickstart.switchAny.cpp"
  19. "tutorial/rationale.container.cpp"
  20. "tutorial/type.cpp"
  21. "type/basic_type.cpp")
  22. file(GLOB_RECURSE EXAMPLES_REQUIRING_BOOST ${EXAMPLES_REQUIRING_BOOST})
  23. ##############################################################################
  24. # Caveats: Take note of examples that are not supported.
  25. ##############################################################################
  26. if (NOT Boost_FOUND)
  27. list(APPEND EXCLUDED_EXAMPLES ${EXAMPLES_REQUIRING_BOOST})
  28. endif()
  29. list(APPEND EXCLUDED_EXAMPLES "cmake_integration/main.cpp")
  30. ##############################################################################
  31. # Add all the examples
  32. ##############################################################################
  33. file(GLOB_RECURSE EXAMPLES "*.cpp")
  34. file(GLOB_RECURSE EXCLUDED_EXAMPLES ${EXCLUDED_EXAMPLES})
  35. list(REMOVE_ITEM EXAMPLES "" ${EXCLUDED_EXAMPLES})
  36. # Several examples have unused parameters because the name of the parameters
  37. # are useful for illustration, even if the implementation is not actually
  38. # presented. We don't want to generate warnings for that or need to comment
  39. # out all unused parameter names.
  40. include(CheckCXXCompilerFlag)
  41. check_cxx_compiler_flag(-Wno-unused-parameter BOOST_HANA_HAS_WNO_UNUSED_PARAMETER)
  42. check_cxx_compiler_flag(-Wno-unused-lambda-capture BOOST_HANA_HAS_WNO_UNUSED_LAMBDA_CAPTURE)
  43. foreach(_file IN LISTS EXAMPLES)
  44. boost_hana_target_name_for(_target "${_file}")
  45. add_executable(${_target} EXCLUDE_FROM_ALL "${_file}")
  46. add_test(${_target} "${CMAKE_CURRENT_BINARY_DIR}/${_target}")
  47. boost_hana_set_test_properties(${_target})
  48. if (_file IN_LIST EXAMPLES_REQUIRING_BOOST)
  49. target_link_libraries(${_target} PRIVATE Boost::boost)
  50. endif()
  51. if (BOOST_HANA_HAS_WNO_UNUSED_PARAMETER)
  52. target_compile_options(${_target} PRIVATE -Wno-unused-parameter)
  53. endif()
  54. if (BOOST_HANA_HAS_WNO_UNUSED_LAMBDA_CAPTURE)
  55. target_compile_options(${_target} PRIVATE -Wno-unused-lambda-capture)
  56. endif()
  57. add_dependencies(examples ${_target})
  58. endforeach()