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