-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
151 lines (126 loc) · 4.74 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
cmake_minimum_required(VERSION 3.12.0 FATAL_ERROR)
project(memlogger VERSION 2.1.2 LANGUAGES CXX)
option(ENABLE_RELEASE "Enable release build" ON)
option(ENABLE_TOPDIR "Enable including package top dir to distribution" OFF)
include(CheckCXXSourceCompiles)
check_cxx_source_compiles("namespace Outer {namespace Inner { int i = 0; }}
using namespace Outer::Inner;
int foo() { return i; }
int main() { return foo(); }"
HAVE_NAMESPACES
)
if (HAVE_NAMESPACES)
check_cxx_source_compiles("#include <list>
#include <deque>
using namespace std;
int main() { list<int> x; x.push_back(5);
list<int>::iterator iter = x.begin();
if (iter != x.end()) ++iter;
return 0; }"
HAVE_STL
)
if (NOT HAVE_STL)
message(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER} has no STL.")
endif()
else()
message(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER} has no namespaces.")
endif()
include(CheckCXXCompilerFlag)
# Check and set highest possible C++ dialect
CHECK_CXX_COMPILER_FLAG("-std=c++20" COMPILER_SUPPORTS_CXX20)
CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
if (COMPILER_SUPPORTS_CXX20)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++20")
elseif (COMPILER_SUPPORTS_CXX17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")
elseif (COMPILER_SUPPORTS_CXX14)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
elseif (COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
else()
message(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER} has no C++11 support.")
endif()
find_package(Threads)
if (Threads_FOUND AND CMAKE_USE_PTHREADS_INIT)
set(HAVE_PTHREAD_H 1)
set(_REENTRANT 1)
endif()
# Check and set compiler specific options
if (CMAKE_CXX_COMPILER_ID MATCHES SunPro)
add_compile_options(-xO4 -mt=yes -xatomic=studio)
CHECK_CXX_COMPILER_FLAG("-xlinkopt=2" COMPILER_SUPPORTS_LINKOPT)
if (COMPILER_SUPPORTS_LINKOPT)
add_compile_options(-xlinkopt=2)
endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES Clang)
add_compile_options(-O3 -stdlib=libc++ -flto=thin)
add_link_options(-lpthread)
CHECK_CXX_COMPILER_FLAG("-flto=thin" COMPILER_SUPPORTS_LTOTHIN)
if (COMPILER_SUPPORTS_LTOTHIN)
add_compile_options(-flto=thin)
endif()
elseif (CMAKE_CXX_COMPILER_ID MATCHES GNU)
add_compile_options(-O3 -pthread -flto)
add_link_options(-lpthread)
CHECK_CXX_COMPILER_FLAG("-flto" COMPILER_SUPPORTS_LTO)
if (COMPILER_SUPPORTS_LTO)
add_compile_options(-flto)
endif()
else()
add_compile_options(-O3 -pthread)
add_link_options(-lpthread)
endif()
if (ENABLE_RELEASE)
# Strip binary for release builds
add_link_options(-s)
endif()
include(CheckFunctionExists)
include(CheckIncludeFiles)
check_include_files(dlfcn.h HAVE_DLFCN_H)
check_include_files(unistd.h HAVE_UNISTD_H)
check_include_files(sys/mman.h HAVE_SYS_MMAN_H)
check_function_exists(malloc_usable_size HAVE_MALLOC_USABLE_SIZE)
add_subdirectory(${PROJECT_SOURCE_DIR}/src)
configure_file(${PROJECT_SOURCE_DIR}/src/autoconf.h.cmake.in ${PROJECT_SOURCE_DIR}/src/autoconf.h)
install(FILES LICENSE TYPE LIB)
if (NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
endif()
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_SOURCE_PACKAGE_FILE_NAME ${PROJECT_NAME}-${PROJECT_VERSION})
set(CPACK_SYSTEM_NAME ${CMAKE_SYSTEM}-${CMAKE_SYSTEM_PROCESSOR})
set(CPACK_PACKAGE_DESCRIPTION "\
Very simple memory logger, designed to profile the application by the nature of memory allocations in accordance with the size of the chunks.\
Feel free to check project wiki at https://github.com/yvoinov/memlogger/wiki\
")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/yvoinov/memlogger")
set(CPACK_SET_DESTDIR ON)
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY ${ENABLE_TOPDIR})
set(CPACK_SOURCE_GENERATOR "TBZ2;TGZ")
set(CPACK_GENERATOR "TBZ2;TGZ")
set(CPACK_SOURCE_IGNORE_FILES
/.git
/.libs
/.deps
/autom4te.cache
/.*build.*
/*~$
/dist.sh
/libtool$
/Makefile$
/autoconf.h$
/config.log
/config.status
/stamp-.*
/libmemlogger.*
/*.gz
/*.bz2
)
include(CPack)