-
Notifications
You must be signed in to change notification settings - Fork 216
/
CMakeLists.txt
123 lines (104 loc) · 5.51 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# Copyright Louis Dionne 2013-2022
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
add_custom_target(tests COMMENT "Build all the unit tests.")
add_dependencies(hana_check tests)
##############################################################################
# Take note of files that depend on Boost
##############################################################################
file(GLOB_RECURSE TESTS_REQUIRING_BOOST "ext/boost/*.cpp"
"experimental/printable/*.cpp")
file(GLOB_RECURSE PUBLIC_HEADERS_REQUIRING_BOOST
RELATIVE "${Boost.Hana_SOURCE_DIR}/include"
"${Boost.Hana_SOURCE_DIR}/include/boost/hana/ext/boost/*.hpp"
"${Boost.Hana_SOURCE_DIR}/include/boost/hana/ext/boost.hpp"
"${Boost.Hana_SOURCE_DIR}/include/boost/hana/experimental/printable.hpp"
)
##############################################################################
# Caveats: Take note of public headers and tests that are not supported.
##############################################################################
if (NOT Boost_FOUND)
list(APPEND EXCLUDED_UNIT_TESTS ${TESTS_REQUIRING_BOOST})
list(APPEND EXCLUDED_PUBLIC_HEADERS ${PUBLIC_HEADERS_REQUIRING_BOOST})
endif()
##############################################################################
# Generate tests that include each public header.
# The headers that were excluded above due to caveats are ignored here.
##############################################################################
add_custom_target(test.headers COMMENT "Build all the header-inclusion unit tests.")
add_dependencies(tests test.headers)
file(GLOB_RECURSE PUBLIC_HEADERS
RELATIVE "${Boost.Hana_SOURCE_DIR}/include"
"${Boost.Hana_SOURCE_DIR}/include/*.hpp"
)
list(REMOVE_ITEM PUBLIC_HEADERS ${PUBLIC_HEADERS_REQUIRING_BOOST})
include(TestHeaders)
add_header_test(test.headers.standalone EXCLUDE_FROM_ALL
HEADERS ${PUBLIC_HEADERS}
EXCLUDE ${EXCLUDED_PUBLIC_HEADERS})
target_link_libraries(test.headers.standalone PRIVATE hana)
add_dependencies(test.headers test.headers.standalone)
if (Boost_FOUND)
add_header_test(test.headers.boost EXCLUDE_FROM_ALL
HEADERS ${PUBLIC_HEADERS_REQUIRING_BOOST}
EXCLUDE ${EXCLUDED_PUBLIC_HEADERS})
target_link_libraries(test.headers.boost PRIVATE hana Boost::boost)
add_dependencies(test.headers test.headers.boost)
endif()
##############################################################################
# Check for ODR violations when linking several translation units
# (GitHub issue 75)
##############################################################################
list(APPEND EXCLUDED_UNIT_TESTS "issues/github_75/*.cpp")
boost_hana_target_name_for(github_75 "${CMAKE_CURRENT_LIST_DIR}/issues/github_75")
add_executable(${github_75} EXCLUDE_FROM_ALL "issues/github_75/tu1.cpp" "issues/github_75/tu2.cpp")
boost_hana_set_test_properties(${github_75})
add_test(${github_75} "${CMAKE_CURRENT_BINARY_DIR}/${github_75}")
add_dependencies(tests ${github_75})
##############################################################################
# Add all the remaining unit tests
##############################################################################
file(GLOB_RECURSE UNIT_TESTS "*.cpp")
file(GLOB_RECURSE EXCLUDED_UNIT_TESTS ${EXCLUDED_UNIT_TESTS})
list(REMOVE_ITEM UNIT_TESTS ${EXCLUDED_UNIT_TESTS})
foreach(_file IN LISTS UNIT_TESTS)
boost_hana_target_name_for(_target "${_file}")
add_executable(${_target} EXCLUDE_FROM_ALL "${_file}")
boost_hana_set_test_properties(${_target})
if (_file IN_LIST TESTS_REQUIRING_BOOST)
target_link_libraries(${_target} PRIVATE Boost::boost)
endif()
target_include_directories(${_target} PRIVATE _include)
add_test(${_target} "${CMAKE_CURRENT_BINARY_DIR}/${_target}")
add_dependencies(tests ${_target})
endforeach()
##############################################################################
# Add the deployment test, which checks that we can indeed install `hana` and
# then use the provided `HanaConfig.cmake` config file to use `hana` from an
# external project.
##############################################################################
include(ExternalProject)
set(HANA_FAKE_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/deploy/fakeroot")
ExternalProject_Add(test.deploy.fakeroot
SOURCE_DIR "${PROJECT_SOURCE_DIR}"
EXCLUDE_FROM_ALL TRUE
BUILD_ALWAYS TRUE
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${HANA_FAKE_INSTALL_DIR}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
TEST_COMMAND "" # Disable test step
UPDATE_COMMAND "" # Disable source work-tree update
)
add_custom_target(test.deploy
DEPENDS test.deploy.fakeroot
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/deploy/build"
COMMAND ${CMAKE_COMMAND} -E chdir "${CMAKE_CURRENT_BINARY_DIR}/deploy/build"
${CMAKE_COMMAND} "${CMAKE_CURRENT_SOURCE_DIR}/deploy"
-DCMAKE_CXX_COMPILER="${CMAKE_CXX_COMPILER}"
-DCMAKE_PREFIX_PATH="${HANA_FAKE_INSTALL_DIR}"
-DCMAKE_GENERATOR=${CMAKE_GENERATOR}
-DCMAKE_TOOLCHAIN_FILE="${CMAKE_TOOLCHAIN_FILE}"
COMMAND ${CMAKE_COMMAND} --build "${CMAKE_CURRENT_BINARY_DIR}/deploy/build"
USES_TERMINAL
)
add_dependencies(hana_check test.deploy)