22# Distributed under the Boost Software License, Version 1.0.
33# (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
44
5- cmake_minimum_required (VERSION 3.7 )
5+ cmake_minimum_required (VERSION 3.8 )
66list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR} /cmake" )
77
88
@@ -28,24 +28,28 @@ include(CheckCxxCompilerSupport)
2828
2929
3030##############################################################################
31- # Setup the 'hana' header-only library target.
31+ # Setup the 'hana' header-only library target, along with its install target
32+ # and exports.
3233##############################################################################
3334add_library (hana INTERFACE )
34- target_include_directories (hana INTERFACE include )
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 )
35+ target_include_directories (hana INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} /include>"
36+ $<INSTALL_INTERFACE:include >)
37+ # With Clang on Windows, the -std=c++14 flag is incorrectly set and the compiler
38+ # complains about the unkown option. TODO: Remove this workaround once the
39+ # underlying bug is fixed in CMake: https://gitlab.kitware.com/cmake/cmake/issues/17015
40+ if (NOT (MSVC AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" ))
41+ target_compile_features (hana INTERFACE cxx_std_14)
4742endif ()
4843
44+ # Export the `hana` library into a HanaConfig.cmake file
45+ install (TARGETS hana EXPORT HanaConfig)
46+ install (EXPORT HanaConfig DESTINATION lib/cmake/hana)
47+ install (DIRECTORY include /boost DESTINATION include FILES_MATCHING PATTERN "*.hpp" )
48+
49+ # Also install an optional pkg-config file
50+ configure_file (cmake/hana.pc.in hana.pc @ONLY)
51+ install (FILES "${CMAKE_CURRENT_BINARY_DIR} /hana.pc" DESTINATION lib/pkgconfig)
52+
4953
5054##############################################################################
5155# Setup CMake options
@@ -66,6 +70,7 @@ option(BOOST_HANA_ENABLE_EXCEPTIONS
6670##############################################################################
6771# Function to setup common compiler flags on tests and examples
6872##############################################################################
73+ include (CheckCXXCompilerFlag)
6974function (boost_hana_set_test_properties target )
7075 target_link_libraries (${target} PRIVATE hana)
7176 set_target_properties (${target} PROPERTIES CXX_EXTENSIONS NO )
@@ -110,17 +115,11 @@ endfunction()
110115
111116
112117##############################################################################
113- # Setup include paths. More include paths can be added in subdirectories .
118+ # Look for the rest of Boost, which is an optional dependency of some tests .
114119##############################################################################
115- include_directories (${Boost.Hana_SOURCE_DIR}/include )
116-
117120find_package (Boost 1.59)
118- if (Boost_FOUND)
119- include_directories (${Boost_INCLUDE_DIRS} )
120- else ()
121- message (WARNING
122- "The Boost library headers were not found; targets depending "
123- "on Boost won't be available." )
121+ if (NOT Boost_FOUND)
122+ message (WARNING "The rest of Boost was not found; some tests and examples will be disabled." )
124123endif ()
125124
126125
@@ -142,9 +141,9 @@ function(boost_hana_target_name_for out file)
142141 set (_extension "${ARGV2} " )
143142 endif ()
144143
145- file (RELATIVE_PATH _relative ${Boost.Hana_SOURCE_DIR} ${file} )
146- string (REPLACE "${_extension} " "" _name ${_relative} )
147- string (REGEX REPLACE "/" "." _name ${_name} )
144+ file (RELATIVE_PATH _relative " ${Boost.Hana_SOURCE_DIR}" " ${file} " )
145+ string (REPLACE "${_extension} " "" _name " ${_relative} " )
146+ string (REGEX REPLACE "/" "." _name " ${_name} " )
148147 set (${out} "${_name} " PARENT_SCOPE)
149148endfunction ()
150149
@@ -154,7 +153,7 @@ endfunction()
154153##############################################################################
155154add_custom_target (check
156155 COMMAND ${CMAKE_CTEST_COMMAND} --output -on -failure
157- WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
156+ WORKING_DIRECTORY " ${CMAKE_CURRENT_BINARY_DIR} "
158157 COMMENT "Build and then run all the tests and examples." )
159158
160159
@@ -175,15 +174,3 @@ add_subdirectory(benchmark)
175174add_subdirectory (doc )
176175add_subdirectory (example)
177176add_subdirectory (test )
178-
179-
180- ##############################################################################
181- # Setup the 'install' target.
182- # This copies the whole content of include/ to ${CMAKE_INSTALL_PREFIX}.
183- ##############################################################################
184- install (DIRECTORY include /boost DESTINATION include
185- PATTERN ".DS_Store" EXCLUDE )
186-
187- # We also install an optional pkg-config file.
188- configure_file (cmake/hana.pc.in hana.pc @ONLY)
189- install (FILES ${CMAKE_CURRENT_BINARY_DIR} /hana.pc DESTINATION lib/pkgconfig)
0 commit comments