]>
Commit | Line | Data |
---|---|---|
b32b8144 | 1 | # Copyright Louis Dionne 2013-2017 |
7c673cae FG |
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 | ||
11fdf7f2 | 5 | cmake_minimum_required(VERSION 3.9) |
7c673cae FG |
6 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") |
7 | ||
b32b8144 FG |
8 | ############################################################################## |
9 | # Setup CMake options | |
10 | ############################################################################## | |
11 | option(BOOST_HANA_ENABLE_CONCEPT_CHECKS "Enable concept checking in the interface methods." ON) | |
12 | option(BOOST_HANA_ENABLE_DEBUG_MODE "Enable Hana's debug mode." OFF) | |
13 | option(BOOST_HANA_ENABLE_CPP17 "Build with C++17 instead of usual required C++ standard. Useful for testing." OFF) | |
14 | ||
15 | option(BOOST_HANA_ENABLE_STRING_UDL | |
16 | "Enable the GNU extension allowing the special string literal operator\ | |
17 | template, which enables the _s suffix for creating compile-time strings." ON) | |
18 | ||
19 | option(BOOST_HANA_ENABLE_EXCEPTIONS | |
20 | "Build with exceptions enabled. Note that Hana does not make use of exceptions,\ | |
21 | but this switch can be disabled when building the tests to assess that it is\ | |
22 | really the case." ON) | |
23 | ||
7c673cae FG |
24 | |
25 | ############################################################################## | |
26 | # Setup project | |
27 | # | |
28 | # We parse the canonical version number located in <boost/hana/version.hpp>. | |
29 | # This is done to allow the library to be used without requiring a proper | |
30 | # installation during which the version would be written to this header. | |
31 | ############################################################################## | |
32 | foreach(level MAJOR MINOR PATCH) | |
33 | file(STRINGS include/boost/hana/version.hpp | |
34 | _define_${level} | |
35 | REGEX "#define BOOST_HANA_${level}_VERSION") | |
36 | string(REGEX MATCH "([0-9]+)" _version_${level} "${_define_${level}}") | |
37 | endforeach() | |
38 | ||
39 | set(Boost.Hana_VERSION_STRING "${_version_MAJOR}.${_version_MINOR}.${_version_PATCH}") | |
40 | project(Boost.Hana VERSION ${Boost.Hana_VERSION_STRING} LANGUAGES CXX) | |
41 | ||
42 | # Perform checks to make sure we support the current compiler | |
43 | include(CheckCxxCompilerSupport) | |
44 | ||
45 | ||
46 | ############################################################################## | |
b32b8144 FG |
47 | # Setup the 'hana' header-only library target, along with its install target |
48 | # and exports. | |
7c673cae | 49 | ############################################################################## |
b32b8144 | 50 | include(CheckCXXCompilerFlag) |
7c673cae | 51 | add_library(hana INTERFACE) |
11fdf7f2 TL |
52 | target_include_directories(hana INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>") |
53 | if (BOOST_HANA_ENABLE_CPP17) | |
54 | target_compile_features(hana INTERFACE cxx_std_17) | |
55 | else() | |
56 | target_compile_features(hana INTERFACE cxx_std_14) | |
b32b8144 | 57 | endif() |
7c673cae | 58 | |
b32b8144 | 59 | # Export the `hana` library into a HanaConfig.cmake file |
11fdf7f2 TL |
60 | install(TARGETS hana |
61 | EXPORT HanaConfig | |
62 | INCLUDES DESTINATION include) | |
63 | install(EXPORT HanaConfig | |
64 | DESTINATION lib/cmake/hana) | |
65 | install(DIRECTORY include/boost | |
66 | DESTINATION include | |
67 | FILES_MATCHING PATTERN "*.hpp") | |
7c673cae | 68 | |
b32b8144 FG |
69 | # Also install an optional pkg-config file |
70 | configure_file(cmake/hana.pc.in hana.pc @ONLY) | |
71 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/hana.pc" DESTINATION lib/pkgconfig) | |
7c673cae FG |
72 | |
73 | ||
74 | ############################################################################## | |
b32b8144 | 75 | # Function to setup common compiler flags on tests and examples |
7c673cae | 76 | ############################################################################## |
b32b8144 FG |
77 | function(boost_hana_set_test_properties target) |
78 | target_link_libraries(${target} PRIVATE hana) | |
79 | set_target_properties(${target} PROPERTIES CXX_EXTENSIONS NO) | |
7c673cae | 80 | |
b32b8144 FG |
81 | macro(setflag testname flag) |
82 | check_cxx_compiler_flag(${flag} ${testname}) | |
83 | if (${testname}) | |
84 | target_compile_options(${target} PRIVATE ${flag}) | |
85 | endif() | |
86 | endmacro() | |
7c673cae | 87 | |
b32b8144 FG |
88 | setflag(BOOST_HANA_HAS_FDIAGNOSTICS_COLOR -fdiagnostics-color) |
89 | setflag(BOOST_HANA_HAS_FTEMPLATE_BACKTRACE_LIMIT -ftemplate-backtrace-limit=0) | |
90 | setflag(BOOST_HANA_HAS_PEDANTIC -pedantic) | |
91 | setflag(BOOST_HANA_HAS_WALL -Wall) | |
92 | setflag(BOOST_HANA_HAS_WERROR -Werror) | |
93 | setflag(BOOST_HANA_HAS_WEXTRA -Wextra) | |
94 | setflag(BOOST_HANA_HAS_WNO_UNUSED_LOCAL_TYPEDEFS -Wno-unused-local-typedefs) | |
95 | setflag(BOOST_HANA_HAS_WWRITE_STRINGS -Wwrite-strings) | |
7c673cae | 96 | |
b32b8144 FG |
97 | if (NOT BOOST_HANA_ENABLE_EXCEPTIONS) |
98 | setflag(BOOST_HANA_HAS_FNO_EXCEPTIONS -fno-exceptions) | |
99 | endif() | |
7c673cae | 100 | |
b32b8144 FG |
101 | if (NOT BOOST_HANA_ENABLE_CONCEPT_CHECKS) |
102 | target_compile_definitions(${target} PRIVATE -DBOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS) | |
7c673cae | 103 | endif() |
7c673cae | 104 | |
b32b8144 FG |
105 | if (BOOST_HANA_ENABLE_DEBUG_MODE) |
106 | target_compile_definitions(${target} PRIVATE -DBOOST_HANA_CONFIG_ENABLE_DEBUG_MODE) | |
107 | endif() | |
7c673cae | 108 | |
b32b8144 FG |
109 | if (BOOST_HANA_ENABLE_STRING_UDL) |
110 | target_compile_definitions(${target} PRIVATE -DBOOST_HANA_CONFIG_ENABLE_STRING_UDL) | |
111 | # GCC pretends to have the flag, but produces a "unrecognized command line option" | |
112 | # warning when we use it. | |
113 | if (NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") | |
114 | setflag(BOOST_HANA_HAS_WNO_GNU_STRING_UDL -Wno-gnu-string-literal-operator-template) | |
115 | endif() | |
116 | endif() | |
117 | endfunction() | |
7c673cae FG |
118 | |
119 | ||
120 | ############################################################################## | |
b32b8144 | 121 | # Look for the rest of Boost, which is an optional dependency of some tests. |
7c673cae | 122 | ############################################################################## |
11fdf7f2 | 123 | find_package(Boost 1.64) |
b32b8144 FG |
124 | if (NOT Boost_FOUND) |
125 | message(WARNING "The rest of Boost was not found; some tests and examples will be disabled.") | |
7c673cae FG |
126 | endif() |
127 | ||
128 | ||
129 | ############################################################################## | |
130 | # Setup custom functions to ease the creation of targets | |
131 | ############################################################################## | |
132 | # boost_hana_target_name_for(<output variable> <source file> [ext]) | |
133 | # | |
134 | # Return the target name associated to a source file. If the path of the | |
135 | # source file relative from the root of Hana is `path/to/source/file.ext`, | |
136 | # the target name associated to it will be `path.to.source.file`. | |
137 | # | |
138 | # The extension of the file should be specified as a last argument. If no | |
139 | # extension is specified, the `.cpp` extension is assumed. | |
140 | function(boost_hana_target_name_for out file) | |
141 | if (NOT ARGV2) | |
142 | set(_extension ".cpp") | |
143 | else() | |
144 | set(_extension "${ARGV2}") | |
145 | endif() | |
146 | ||
b32b8144 FG |
147 | file(RELATIVE_PATH _relative "${Boost.Hana_SOURCE_DIR}" "${file}") |
148 | string(REPLACE "${_extension}" "" _name "${_relative}") | |
149 | string(REGEX REPLACE "/" "." _name "${_name}") | |
7c673cae FG |
150 | set(${out} "${_name}" PARENT_SCOPE) |
151 | endfunction() | |
152 | ||
7c673cae FG |
153 | |
154 | ############################################################################## | |
155 | # Setup the `check` target to build and then run all the tests and examples. | |
156 | ############################################################################## | |
157 | add_custom_target(check | |
158 | COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure | |
b32b8144 | 159 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" |
11fdf7f2 TL |
160 | COMMENT "Build and then run all the tests and examples." |
161 | USES_TERMINAL) | |
7c673cae FG |
162 | |
163 | ||
164 | ############################################################################## | |
b32b8144 | 165 | # Setup subdirectories and testing |
7c673cae FG |
166 | ############################################################################## |
167 | enable_testing() | |
b32b8144 FG |
168 | find_program(MEMORYCHECK_COMMAND valgrind) |
169 | if (MEMORYCHECK_COMMAND) | |
170 | message(STATUS "Found Valgrind: ${MEMORYCHECK_COMMAND}") | |
171 | set(MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --error-exitcode=1") | |
172 | else() | |
173 | message("Valgrind not found") | |
174 | endif() | |
175 | include(CTest) | |
176 | ||
7c673cae FG |
177 | add_subdirectory(benchmark) |
178 | add_subdirectory(doc) | |
179 | add_subdirectory(example) | |
7c673cae | 180 | add_subdirectory(test) |