]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | # Copyright Louis Dionne 2013-2016 |
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 | ||
5 | cmake_minimum_required(VERSION 3.1) | |
6 | list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") | |
7 | ||
8 | ||
9 | ############################################################################## | |
10 | # Setup project | |
11 | # | |
12 | # We parse the canonical version number located in <boost/hana/version.hpp>. | |
13 | # This is done to allow the library to be used without requiring a proper | |
14 | # installation during which the version would be written to this header. | |
15 | ############################################################################## | |
16 | foreach(level MAJOR MINOR PATCH) | |
17 | file(STRINGS include/boost/hana/version.hpp | |
18 | _define_${level} | |
19 | REGEX "#define BOOST_HANA_${level}_VERSION") | |
20 | string(REGEX MATCH "([0-9]+)" _version_${level} "${_define_${level}}") | |
21 | endforeach() | |
22 | ||
23 | set(Boost.Hana_VERSION_STRING "${_version_MAJOR}.${_version_MINOR}.${_version_PATCH}") | |
24 | project(Boost.Hana VERSION ${Boost.Hana_VERSION_STRING} LANGUAGES CXX) | |
25 | ||
26 | # Perform checks to make sure we support the current compiler | |
27 | include(CheckCxxCompilerSupport) | |
28 | ||
29 | ||
30 | ############################################################################## | |
31 | # Setup the 'hana' header-only library target. | |
32 | ############################################################################## | |
33 | add_library(hana INTERFACE) | |
34 | target_include_directories(hana INTERFACE include) | |
35 | ||
36 | ||
37 | ############################################################################## | |
38 | # Setup CMake options | |
39 | ############################################################################## | |
40 | option(BOOST_HANA_ENABLE_WERROR "Fail and stop if a warning is triggered." OFF) | |
41 | option(BOOST_HANA_ENABLE_MEMCHECK "Run the unit tests and examples under Valgrind if it is found." OFF) | |
42 | option(BOOST_HANA_ENABLE_CONCEPT_CHECKS "Enable concept checking in the interface methods." ON) | |
43 | option(BOOST_HANA_ENABLE_DEBUG_MODE "Enable Hana's debug mode." OFF) | |
44 | ||
45 | option(BOOST_HANA_ENABLE_STRING_UDL | |
46 | "Enable the GNU extension allowing the special string literal operator\ | |
47 | template, which enables the _s suffix for creating compile-time strings." ON) | |
48 | ||
49 | option(BOOST_HANA_ENABLE_EXCEPTIONS | |
50 | "Build with exceptions enabled. Note that Hana does not make use of exceptions,\ | |
51 | but this switch can be disabled when building the tests to assess that it is\ | |
52 | really the case." ON) | |
53 | ||
54 | ||
55 | ############################################################################## | |
56 | # Setup compiler flags (more can be set on a per-target basis or in subdirectories) | |
57 | ############################################################################## | |
58 | include(CheckCXXCompilerFlag) | |
59 | macro(boost_hana_append_flag testname flag) | |
60 | check_cxx_compiler_flag(${flag} ${testname}) | |
61 | if (${testname}) | |
62 | add_compile_options(${flag}) | |
63 | endif() | |
64 | endmacro() | |
65 | ||
66 | # Compiler flags controlled by CMake options above | |
67 | if (BOOST_HANA_ENABLE_WERROR) | |
68 | boost_hana_append_flag(BOOST_HANA_HAS_WERROR -Werror) | |
69 | boost_hana_append_flag(BOOST_HANA_HAS_WX -WX) | |
70 | endif() | |
71 | ||
72 | if (NOT BOOST_HANA_ENABLE_CONCEPT_CHECKS) | |
73 | add_definitions(-DBOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS) | |
74 | endif() | |
75 | ||
76 | if (BOOST_HANA_ENABLE_DEBUG_MODE) | |
77 | add_definitions(-DBOOST_HANA_CONFIG_ENABLE_DEBUG_MODE) | |
78 | endif() | |
79 | ||
80 | if (BOOST_HANA_ENABLE_STRING_UDL) | |
81 | add_definitions(-DBOOST_HANA_CONFIG_ENABLE_STRING_UDL) | |
82 | # GCC pretends to have the flag, but produces a "unrecognized command line option" | |
83 | # warning when we use it. | |
84 | if (NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") | |
85 | boost_hana_append_flag(BOOST_HANA_HAS_WNO_GNU_STRING_UDL | |
86 | -Wno-gnu-string-literal-operator-template) | |
87 | endif() | |
88 | endif() | |
89 | ||
90 | if (NOT BOOST_HANA_ENABLE_EXCEPTIONS) | |
91 | boost_hana_append_flag(BOOST_HANA_HAS_FNO_EXCEPTIONS -fno-exceptions) | |
92 | endif() | |
93 | ||
94 | # Other compiler flags | |
95 | boost_hana_append_flag(BOOST_HANA_HAS_FDIAGNOSTICS_COLOR -fdiagnostics-color) | |
96 | boost_hana_append_flag(BOOST_HANA_HAS_FTEMPLATE_BACKTRACE_LIMIT -ftemplate-backtrace-limit=0) | |
97 | boost_hana_append_flag(BOOST_HANA_HAS_PEDANTIC -pedantic) | |
98 | boost_hana_append_flag(BOOST_HANA_HAS_STDCXX1Y -std=c++1y) | |
99 | boost_hana_append_flag(BOOST_HANA_HAS_QUNUSED_ARGUMENTS -Qunused-arguments) | |
100 | boost_hana_append_flag(BOOST_HANA_HAS_W -W) | |
101 | boost_hana_append_flag(BOOST_HANA_HAS_WALL -Wall) | |
102 | boost_hana_append_flag(BOOST_HANA_HAS_WEXTRA -Wextra) | |
103 | boost_hana_append_flag(BOOST_HANA_HAS_WNO_UNUSED_LOCAL_TYPEDEFS -Wno-unused-local-typedefs) | |
104 | boost_hana_append_flag(BOOST_HANA_HAS_WWRITE_STRINGS -Wwrite-strings) | |
105 | ||
106 | ||
107 | ############################################################################## | |
108 | # Setup include paths. More include paths can be added in subdirectories. | |
109 | ############################################################################## | |
110 | include_directories(${Boost.Hana_SOURCE_DIR}/include) | |
111 | ||
112 | find_package(Boost 1.59) | |
113 | if (Boost_FOUND) | |
114 | include_directories(${Boost_INCLUDE_DIRS}) | |
115 | else() | |
116 | message(WARNING | |
117 | "The Boost library headers were not found; targets depending " | |
118 | "on Boost won't be available.") | |
119 | endif() | |
120 | ||
121 | ||
122 | ############################################################################## | |
123 | # Setup custom functions to ease the creation of targets | |
124 | ############################################################################## | |
125 | # boost_hana_target_name_for(<output variable> <source file> [ext]) | |
126 | # | |
127 | # Return the target name associated to a source file. If the path of the | |
128 | # source file relative from the root of Hana is `path/to/source/file.ext`, | |
129 | # the target name associated to it will be `path.to.source.file`. | |
130 | # | |
131 | # The extension of the file should be specified as a last argument. If no | |
132 | # extension is specified, the `.cpp` extension is assumed. | |
133 | function(boost_hana_target_name_for out file) | |
134 | if (NOT ARGV2) | |
135 | set(_extension ".cpp") | |
136 | else() | |
137 | set(_extension "${ARGV2}") | |
138 | endif() | |
139 | ||
140 | file(RELATIVE_PATH _relative ${Boost.Hana_SOURCE_DIR} ${file}) | |
141 | string(REPLACE "${_extension}" "" _name ${_relative}) | |
142 | string(REGEX REPLACE "/" "." _name ${_name}) | |
143 | set(${out} "${_name}" PARENT_SCOPE) | |
144 | endfunction() | |
145 | ||
146 | # boost_hana_add_test(<name> <command> [<arg>...]) | |
147 | # | |
148 | # Creates a test called `name`, which runs the given `command` with the given | |
149 | # `arg`uments. However, if `BOOST_HANA_ENABLE_MEMCHECK` is set to `ON`, the | |
150 | # test will run the provided command under the memory checker. | |
151 | if (BOOST_HANA_ENABLE_MEMCHECK) | |
152 | find_package(Valgrind REQUIRED) | |
153 | function(boost_hana_add_test name) | |
154 | add_test(${name} ${Valgrind_EXECUTABLE} --leak-check=full --error-exitcode=1 ${ARGN}) | |
155 | endfunction() | |
156 | else() | |
157 | function(boost_hana_add_test name) | |
158 | add_test(${name} ${ARGN}) | |
159 | endfunction() | |
160 | endif() | |
161 | ||
162 | ||
163 | ############################################################################## | |
164 | # Setup the `check` target to build and then run all the tests and examples. | |
165 | ############################################################################## | |
166 | add_custom_target(check | |
167 | COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure | |
168 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} | |
169 | COMMENT "Build and then run all the tests and examples.") | |
170 | ||
171 | ||
172 | ############################################################################## | |
173 | # Setup subdirectories | |
174 | ############################################################################## | |
175 | enable_testing() | |
176 | add_subdirectory(benchmark) | |
177 | add_subdirectory(doc) | |
178 | add_subdirectory(example) | |
179 | add_subdirectory(experimental) | |
180 | add_subdirectory(test) | |
181 | ||
182 | ||
183 | ############################################################################## | |
184 | # Setup the 'install' target. | |
185 | # This copies the whole content of include/ to ${CMAKE_INSTALL_PREFIX}. | |
186 | ############################################################################## | |
187 | install(DIRECTORY include/boost DESTINATION include | |
188 | PATTERN ".DS_Store" EXCLUDE) | |
189 | ||
190 | # We also install an optional pkg-config file. | |
191 | configure_file(cmake/hana.pc.in hana.pc @ONLY) | |
192 | install(FILES ${CMAKE_CURRENT_BINARY_DIR}/hana.pc DESTINATION lib/pkgconfig) |