• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (C) 2019 T. Zachary Laine
2#
3# Distributed under the Boost Software License, Version 1.0. (See
4# accompanying file LICENSE_1_0.txt or copy at
5# http://www.boost.org/LICENSE_1_0.txt)
6cmake_minimum_required(VERSION 3.5)
7list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
8
9project(stl_interfaces)
10
11##################################################
12# C++ standard version selection
13##################################################
14set(CXX_STD 14 CACHE STRING "Set to X to enable C++X builds.")
15message("-- Using -std=c++${CXX_STD}")
16
17
18##################################################
19# Sanitizers
20##################################################
21set(USE_ASAN false CACHE BOOL "Set to true to enable -fsanitize=address when building tests.")
22set(USE_UBSAN false CACHE BOOL "Set to true to enable -fsanitize=undefined when building tests.")
23if (USE_ASAN AND USE_UBSAN)
24    message(FATAL_ERROR "USE_ASAN and USE_UBSAN must not be enabled at the same time")
25elseif (USE_ASAN)
26    set(compile_flags -fsanitize=address)
27    set(link_flags -fsanitize=address)
28    message("-- Using -fsanitize=address")
29elseif (USE_UBSAN)
30    set(compile_flags -fsanitize=undefined)
31    set(link_flags -fsanitize=undefined)
32    message("-- Using -fsanitize=undefined")
33endif()
34
35
36##################################################
37# Code coverage
38##################################################
39if (UNIX)
40    set(BUILD_COVERAGE false CACHE BOOL "Set to true to enable code coverage when building tests.  Only Linux and Mac are supported.")
41    if (BUILD_COVERAGE)
42        message("-- Building for code coverage; disabling any sanitizers")
43        if (APPLE)
44            set(compile_flags -fprofile-arcs -ftest-coverage)
45            set(CMAKE_BUILD_TYPE Debug)
46            set(link_flags --coverage)
47        else ()
48            set(compile_flags --coverage)
49            set(CMAKE_BUILD_TYPE Debug)
50            set(link_flags --coverage)
51        endif ()
52    endif ()
53endif ()
54
55
56##################################################
57# Dependencies
58##################################################
59set(boost_components)
60include(dependencies)
61
62##################################################
63# stl_interfaces library
64##################################################
65add_library(stl_interfaces INTERFACE)
66
67target_include_directories(stl_interfaces INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}/include)
68target_link_libraries(stl_interfaces INTERFACE boost)
69if (link_flags)
70    target_link_libraries(stl_interfaces INTERFACE ${link_flags})
71    target_compile_options(stl_interfaces INTERFACE ${compile_flags})
72endif ()
73if (NOT MSVC)
74    target_compile_options(stl_interfaces INTERFACE -Wall)
75endif ()
76
77
78add_subdirectory(test)
79add_subdirectory(example)
80