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