CMakeLists.txt 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. # Copyright Louis Dionne 2015
  2. # Modified Work Copyright Barrett Adair 2015-2017
  3. # Distributed under the Boost Software License, Version 1.0.
  4. # (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  5. cmake_minimum_required(VERSION 3.0)
  6. project(boost_callable_traits CXX)
  7. list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
  8. enable_testing()
  9. set (CMAKE_CXX_STANDARD ${boost_callable_traits_CXX_STD})
  10. # Setting up CMake options and compiler flags (more flags can be set on a per-target basis or in subdirectories)
  11. include(CheckCXXCompilerFlag)
  12. macro(boost_callable_traits_append_flag testname flag)
  13. check_cxx_compiler_flag(${flag} ${testname})
  14. if (${testname})
  15. add_compile_options(${flag})
  16. endif()
  17. endmacro()
  18. if(NOT MSVC OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
  19. # enable all warnings and treat them all as errors
  20. boost_callable_traits_append_flag(boost_callable_traits_HAS_WERROR -Werror)
  21. boost_callable_traits_append_flag(boost_callable_traits_HAS_WX -WX)
  22. boost_callable_traits_append_flag(boost_callable_traits_HAS_W -W)
  23. boost_callable_traits_append_flag(boost_callable_traits_HAS_WALL -Wall)
  24. boost_callable_traits_append_flag(boost_callable_traits_HAS_WEXTRA -Wextra)
  25. endif()
  26. if(MSVC)
  27. # MSVC/Clang-cl builds need -Qunused-arguments
  28. boost_callable_traits_append_flag(boost_callable_traits_HAS_QUNUSED_ARGUMENTS -Qunused-arguments)
  29. else()
  30. # for better template error debugging
  31. boost_callable_traits_append_flag(boost_callable_traits_HAS_FTEMPLATE_BACKTRACE_LIMIT -ftemplate-backtrace-limit=0)
  32. # enforce strict standards compliance
  33. boost_callable_traits_append_flag(boost_callable_traits_HAS_PEDANTIC -pedantic)
  34. # use the most recent C++ standard available
  35. boost_callable_traits_append_flag(boost_callable_traits_HAS_STDCXX0x -std=c++0x)
  36. boost_callable_traits_append_flag(boost_callable_traits_HAS_STDCXX1y -std=c++1y)
  37. boost_callable_traits_append_flag(boost_callable_traits_HAS_STDCXX1z -std=c++1z)
  38. boost_callable_traits_append_flag(boost_callable_traits_HAS_STDCXX17 -std=c++17)
  39. boost_callable_traits_append_flag(boost_callable_traits_HAS_STDCXX2a -std=c++2a)
  40. endif()
  41. # transactional memory - currently only available in GCC 6 and later
  42. if(NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
  43. boost_callable_traits_append_flag(boost_callable_traits_HAS_FGNU_TM -fgnu-tm)
  44. endif()
  45. add_library(boost_callable_traits INTERFACE)
  46. set_property(TARGET boost_callable_traits PROPERTY EXPORT_NAME callable_traits)
  47. add_library(Boost::callable_traits ALIAS boost_callable_traits)
  48. target_include_directories(boost_callable_traits INTERFACE
  49. "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
  50. $<INSTALL_INTERFACE:include>)
  51. if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
  52. #
  53. #find_package(Doxygen)
  54. ##find_package(Meta)
  55. #find_package(PythonInterp 2.7)
  56. #find_package(Ruby 2.1)
  57. ##############################################################################
  58. # boost_callable_traits_target_name_for(<output variable> <source file> [ext])
  59. # Returns the target name associated to a source file. If the path of the
  60. # source file relative from the root of boost_callable_traits is `path/to/source/file.ext`,
  61. # the target name associated to it will be `path.to.source.file`.
  62. #
  63. # The extension of the file should be specified as a last argument. If no
  64. # extension is specified, the `.cpp` extension is assumed.
  65. ##############################################################################
  66. function(boost_callable_traits_target_name_for out file)
  67. if (NOT ARGV2)
  68. set(_extension ".cpp")
  69. else()
  70. set(_extension "${ARGV2}")
  71. endif()
  72. file(RELATIVE_PATH _relative ${boost_callable_traits_SOURCE_DIR} ${file})
  73. string(REPLACE "${_extension}" "" _name ${_relative})
  74. string(REGEX REPLACE "/" "." _name ${_name})
  75. set(${out} "${_name}" PARENT_SCOPE)
  76. endfunction()
  77. ##############################################################################
  78. # boost_callable_traits_add_test(<name> <command> [<arg>...])
  79. # Creates a test called `name`, which runs the given `command` with the given args.
  80. ##############################################################################
  81. function(boost_callable_traits_add_test name)
  82. if (boost_callable_traits_ENABLE_MEMCHECK)
  83. add_test(${name} ${Valgrind_EXECUTABLE} --leak-check=full --error-exitcode=1 ${ARGN})
  84. else()
  85. add_test(${name} ${ARGN})
  86. endif()
  87. endfunction()
  88. ##############################################################################
  89. # Setup the `check` target to build and then run all the tests and examples.
  90. ##############################################################################
  91. add_custom_target(callable_traits_check
  92. COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure
  93. WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
  94. COMMENT "Build and then run all the tests and examples.")
  95. if (NOT TARGET check)
  96. add_custom_target(check DEPENDS callable_traits_check)
  97. else()
  98. add_dependencies(check callable_traits_check)
  99. endif()
  100. add_subdirectory(example)
  101. add_subdirectory(test)
  102. ##############################################################################
  103. # Setup the 'install' target and the package config file.
  104. ##############################################################################
  105. install(TARGETS boost_callable_traits EXPORT CallableTraitsConfig)
  106. install(EXPORT CallableTraitsConfig DESTINATION lib/cmake/CallableTraits)
  107. install(DIRECTORY include/boost DESTINATION include FILES_MATCHING PATTERN "*.hpp")
  108. endif()