1
- # Copyright Louis Dionne 2013-2016
1
+ # Copyright Louis Dionne 2013-2017
2
2
# Distributed under the Boost Software License, Version 1.0.
3
3
# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
4
4
5
- cmake_minimum_required (VERSION 3.1 )
5
+ cmake_minimum_required (VERSION 3.7 )
6
6
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /cmake" )
7
7
8
8
@@ -33,12 +33,23 @@ include(CheckCxxCompilerSupport)
33
33
add_library (hana INTERFACE )
34
34
target_include_directories (hana INTERFACE include )
35
35
36
+ include (CheckCXXCompilerFlag)
37
+ # On Clang for Windows, -std=c++14 is not known, but -std=c++1y appears to work.
38
+ if (MSVC AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" )
39
+ check_cxx_compiler_flag(-std=c++1y BOOST_HANA_HAS_STD_CPP1Y)
40
+ if (BOOST_HANA_HAS_STD_CPP1Y)
41
+ target_add_compile_options(hana INTERFACE -std=c++1y)
42
+ endif ()
43
+ else ()
44
+ # TODO: Set these as interface properties when supported
45
+ set (CMAKE_CXX_STANDARD 14)
46
+ set (CMAKE_CXX_STANDARD_REQUIRED YES )
47
+ endif ()
48
+
36
49
37
50
##############################################################################
38
51
# Setup CMake options
39
52
##############################################################################
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
53
option (BOOST_HANA_ENABLE_CONCEPT_CHECKS "Enable concept checking in the interface methods." ON )
43
54
option (BOOST_HANA_ENABLE_DEBUG_MODE "Enable Hana's debug mode." OFF )
44
55
@@ -53,55 +64,49 @@ option(BOOST_HANA_ENABLE_EXCEPTIONS
53
64
54
65
55
66
##############################################################################
56
- # Setup compiler flags (more can be set on a per-target basis or in subdirectories)
67
+ # Function to setup common compiler flags on tests and examples
57
68
##############################################################################
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 ()
69
+ function (boost_hana_set_test_properties target )
70
+ target_link_libraries (${target} PRIVATE hana)
71
+ set_target_properties (${target} PROPERTIES CXX_EXTENSIONS NO )
65
72
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 ()
73
+ macro (setflag testname flag)
74
+ check_cxx_compiler_flag(${flag} ${testname} )
75
+ if (${testname} )
76
+ target_compile_options (${target} PRIVATE ${flag} )
77
+ endif ()
78
+ endmacro ()
71
79
72
- if (NOT BOOST_HANA_ENABLE_CONCEPT_CHECKS)
73
- add_definitions (-DBOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS)
74
- endif ()
80
+ setflag(BOOST_HANA_HAS_FDIAGNOSTICS_COLOR -fdiagnostics-color)
81
+ setflag(BOOST_HANA_HAS_FTEMPLATE_BACKTRACE_LIMIT -ftemplate-backtrace-limit=0)
82
+ setflag(BOOST_HANA_HAS_PEDANTIC -pedantic)
83
+ setflag(BOOST_HANA_HAS_WALL -Wall)
84
+ setflag(BOOST_HANA_HAS_WERROR -Werror)
85
+ setflag(BOOST_HANA_HAS_WEXTRA -Wextra)
86
+ setflag(BOOST_HANA_HAS_WNO_UNUSED_LOCAL_TYPEDEFS -Wno-unused-local-typedefs)
87
+ setflag(BOOST_HANA_HAS_WWRITE_STRINGS -Wwrite-strings )
75
88
76
- if (BOOST_HANA_ENABLE_DEBUG_MODE )
77
- add_definitions (-DBOOST_HANA_CONFIG_ENABLE_DEBUG_MODE )
78
- endif ()
89
+ if (NOT BOOST_HANA_ENABLE_EXCEPTIONS )
90
+ setflag(BOOST_HANA_HAS_FNO_EXCEPTIONS -fno-exceptions )
91
+ endif ()
79
92
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)
93
+ if (NOT BOOST_HANA_ENABLE_CONCEPT_CHECKS)
94
+ target_compile_definitions (${target} PRIVATE -DBOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS)
87
95
endif ()
88
- endif ()
89
96
90
- if (NOT BOOST_HANA_ENABLE_EXCEPTIONS )
91
- boost_hana_append_flag(BOOST_HANA_HAS_FNO_EXCEPTIONS -fno-exceptions )
92
- endif ()
97
+ if (BOOST_HANA_ENABLE_DEBUG_MODE )
98
+ target_compile_definitions ( ${target} PRIVATE -DBOOST_HANA_CONFIG_ENABLE_DEBUG_MODE )
99
+ endif ()
93
100
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 )
101
+ if (BOOST_HANA_ENABLE_STRING_UDL)
102
+ target_compile_definitions (${target} PRIVATE -DBOOST_HANA_CONFIG_ENABLE_STRING_UDL)
103
+ # GCC pretends to have the flag, but produces a "unrecognized command line option"
104
+ # warning when we use it.
105
+ if (NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" )
106
+ setflag(BOOST_HANA_HAS_WNO_GNU_STRING_UDL -Wno-gnu-string -literal-operator-template)
107
+ endif ()
108
+ endif ()
109
+ endfunction ()
105
110
106
111
107
112
##############################################################################
@@ -143,22 +148,6 @@ function(boost_hana_target_name_for out file)
143
148
set (${out} "${_name} " PARENT_SCOPE)
144
149
endfunction ()
145
150
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
151
163
152
##############################################################################
164
153
# Setup the `check` target to build and then run all the tests and examples.
@@ -170,13 +159,21 @@ add_custom_target(check
170
159
171
160
172
161
##############################################################################
173
- # Setup subdirectories
162
+ # Setup subdirectories and testing
174
163
##############################################################################
175
164
enable_testing ()
165
+ find_program (MEMORYCHECK_COMMAND valgrind)
166
+ if (MEMORYCHECK_COMMAND)
167
+ message (STATUS "Found Valgrind: ${MEMORYCHECK_COMMAND} " )
168
+ set (MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --error-exitcode=1" )
169
+ else ()
170
+ message ("Valgrind not found" )
171
+ endif ()
172
+ include (CTest)
173
+
176
174
add_subdirectory (benchmark)
177
175
add_subdirectory (doc )
178
176
add_subdirectory (example)
179
- add_subdirectory (experimental)
180
177
add_subdirectory (test )
181
178
182
179
0 commit comments