3 # Copyright 2013 Google Inc. All Rights Reserved.
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 cmake_minimum_required(VERSION 2.8.12)
26 include(BackwardConfig.cmake)
28 # check if compiler is nvcc or nvcc_wrapper
29 set(COMPILER_IS_NVCC false)
30 get_filename_component(COMPILER_NAME ${CMAKE_CXX_COMPILER} NAME)
31 if (COMPILER_NAME MATCHES "^nvcc")
32 set(COMPILER_IS_NVCC true)
36 set(CMAKE_CXX_STANDARD_REQUIRED True)
37 set(CMAKE_CXX_STANDARD 11)
38 if (${COMPILER_IS_NVCC})
39 # GNU CXX extensions are not supported by nvcc
40 set(CMAKE_CXX_EXTENSIONS OFF)
43 ###############################################################################
45 ###############################################################################
47 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCXX)
48 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
49 if (NOT ${COMPILER_IS_NVCC})
50 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors")
52 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
55 # Anbox: allow old-style cast, unknown pragmas
56 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-error=old-style-cast -Wno-error=unknown-pragmas -Wno-error=switch-default")
58 ###############################################################################
60 ###############################################################################
62 add_library(backward_object OBJECT backward.cpp)
63 target_compile_definitions(backward_object PRIVATE ${BACKWARD_DEFINITIONS})
64 target_include_directories(backward_object PRIVATE ${BACKWARD_INCLUDE_DIRS})
65 set(BACKWARD_ENABLE $<TARGET_OBJECTS:backward_object> CACHE STRING
66 "Link with this object to setup backward automatically")
69 ###############################################################################
70 # BACKWARD LIBRARY (Includes backward.cpp)
71 ###############################################################################
72 option(BACKWARD_SHARED "Build dynamic backward-cpp shared lib" OFF)
77 add_library(backward ${libtype} backward.cpp)
78 target_compile_definitions(backward PUBLIC ${BACKWARD_DEFINITIONS})
79 target_include_directories(backward PUBLIC ${BACKWARD_INCLUDE_DIRS})
81 ###############################################################################
83 ###############################################################################
88 add_library(test_main SHARED test/_test_main.cpp)
90 macro(backward_add_test src)
91 get_filename_component(name ${src} NAME_WE)
92 set(test_name "test_${name}")
94 add_executable(${test_name} ${src} ${ARGN})
96 target_link_libraries(${test_name} PRIVATE Backward::Backward test_main)
98 add_test(NAME ${name} COMMAND ${test_name})
101 # Tests without backward.cpp
109 foreach(test ${TESTS})
110 backward_add_test(test/${test}.cpp)
113 # Tests with backward.cpp
118 foreach(test ${TESTS})
119 backward_add_test(test/${test}.cpp ${BACKWARD_ENABLE})
125 DESTINATION ${CMAKE_INSTALL_PREFIX}/include
128 FILES "BackwardConfig.cmake"
129 DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/backward