-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
104 lines (81 loc) · 3.21 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
cmake_minimum_required(VERSION 3.21)
project(memstats LANGUAGES C CXX)
find_package(TBB)
find_package(Threads)
add_library(memstats)
target_sources(memstats PRIVATE memstats.cc)
target_link_libraries(memstats PRIVATE $<TARGET_NAME_IF_EXISTS:TBB::tbb> $<TARGET_NAME_IF_EXISTS:Threads::Threads>)
include(GNUInstallDirs)
install(FILES memstats.hh
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
target_include_directories(memstats PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src_stacktrace.cxx"
[[
#include <stacktrace>
#include <iostream>
#include <version>
int main(){
std::cout << std::stacktrace::current();
return (__cpp_lib_stacktrace < 202011L);
}]])
try_compile(stacktrace ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src_stacktrace.cxx CXX_STANDARD 23)
if (stacktrace)
message(STATUS "Performing Test stacktrace - Success")
target_compile_features(memstats PRIVATE cxx_std_23)
target_compile_definitions(memstats PRIVATE MEMSTAT_HAVE_STACKTRACE)
else()
message(STATUS "Performing Test stacktrace - Failed")
target_compile_features(memstats PRIVATE cxx_std_11)
endif()
file(WRITE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src_atomic_constexpr.cxx"
[[
#include <atomic>
constexpr static std::atomic<bool> atomic_flag = {};
int main(){
return 0;}
]])
try_compile(atomic_constexpr ${CMAKE_BINARY_DIR} ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/src_atomic_constexpr.cxx CXX_STANDARD 11)
if(atomic_constexpr)
message(STATUS "Performing Test atomic_constexpr - Success")
target_compile_definitions(memstats PRIVATE MEMSTAT_ATOMIC_CONSTEXPR)
else()
message(STATUS "Performing Test atomic_constexpr - Failed")
endif()
target_compile_definitions(memstats PRIVATE $<$<TARGET_EXISTS:TBB::tbb>:MEMSTAT_HAVE_TBB>)
set_target_properties(memstats PROPERTIES
CXX_VISIBILITY_PRESET hidden
EXPORT_NAME MemStats)
add_library(MemStats::MemStats ALIAS memstats)
install(TARGETS memstats EXPORT memstats-targets ARCHIVE)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/config.cmake.in
[[
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
find_dependency(TBB)
find_dependency(Threads)
include("${CMAKE_CURRENT_LIST_DIR}/memstats-targets.cmake")
]])
include(CMakePackageConfigHelpers)
configure_package_config_file(${CMAKE_CURRENT_BINARY_DIR}/config.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/memstats-config.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/memstats
)
install(EXPORT memstats-targets
FILE memstats-targets.cmake
NAMESPACE MemStats::
DESTINATION "${INSTALL_LIBDIR}/cmake/memstats"
)
export(EXPORT memstats-targets
NAMESPACE MemStats::
)
if(memstats_IS_TOP_LEVEL)
add_executable(example_01 example_01.cc)
target_link_libraries(example_01 PUBLIC MemStats::MemStats)
add_executable(example_02 example_02.cc)
target_link_libraries(example_02 PUBLIC MemStats::MemStats)
if(TARGET Threads::Threads)
add_executable(example_03 example_03.cc)
target_link_libraries(example_03 PUBLIC MemStats::MemStats)
target_compile_features(example_03 PUBLIC cxx_std_11)
endif()
endif()