forked from intel/pcm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
159 lines (129 loc) · 5.7 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
152
153
154
155
156
157
158
159
# SPDX-License-Identifier: BSD-3-Clause
# Copyright (c) 2022, Intel Corporation
cmake_minimum_required(VERSION 3.5)
project(PCM)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
include(GNUInstallDirs)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# Check for pcm*.x artifacts generated by an old build scenario using Makefiles
file(GLOB_RECURSE PCM_X_ARTIFACTS ${CMAKE_CURRENT_SOURCE_DIR}/*.x)
foreach(file ${PCM_X_ARTIFACTS})
file(REMOVE ${file})
message(STATUS "Removing old artifact from current source directory : ${file}")
endforeach()
if(PCM_X_ARTIFACTS)
message(WARNING
" Old pcm utilities (.x) were indicated in build folder.\n"
" Old binaries are expected to be installed in system.\n"
" Make sure to install the new binaries(run 'cmake --install .') after building.)")
endif()
message(STATUS "System: ${CMAKE_SYSTEM}")
if(UNIX AND NOT APPLE)
if(${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
set(FREE_BSD TRUE)
else()
set(LINUX TRUE)
endif()
endif()
if(UNIX) # APPLE, LINUX, FREE_BSD
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type (default Release)" FORCE)
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "initial CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message(STATUS "initial CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
# required PCM common flags
set (PCM_COMMON_FLAGS "-Wno-unknown-pragmas -fPIC")
if(LINUX)
set (PCM_COMMON_FLAGS "${PCM_COMMON_FLAGS} -Wextra -DPCM_USE_PERF")
if(NOT DEFINED LINUX_SYSTEMD)
set(LINUX_SYSTEMD FALSE)
endif()
if(NOT DEFINED LINUX_SYSTEMD_UNITDIR)
set(LINUX_SYSTEMD_UNITDIR /usr/lib/systemd/system)
endif()
if(LINUX_SYSTEMD)
message(STATUS "A systemd unit file will be generated")
message(STATUS "LINUX_SYSTEMD_UNITDIR:${LINUX_SYSTEMD_UNITDIR}")
else()
message(STATUS "Set LINUX_SYSTEMD=TRUE for a systemd unit file.")
endif()
endif(LINUX)
# adding the required PCM common flags
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${PCM_COMMON_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${PCM_COMMON_FLAGS}")
message(STATUS "CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}")
message(STATUS "CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}")
set(PCM_OPTIONAL_FLAGS "-Wall")
set(CMAKE_CXX_FLAGS_RELEASE "${PCM_OPTIONAL_FLAGS} -O3 -D_FORTIFY_SOURCE=1 -rdynamic")
set(CMAKE_CXX_FLAGS_DEBUG "${PCM_OPTIONAL_FLAGS} -O0 -g -rdynamic")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${PCM_OPTIONAL_FLAGS} -O3 -g -D_FORTIFY_SOURCE=1 -rdynamic")
if(FREE_BSD)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -lexecinfo")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -lexecinfo")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} -lexecinfo")
endif(FREE_BSD)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
endif(UNIX)
#######################
# Install
#######################
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
add_subdirectory(src)
add_subdirectory(examples)
add_subdirectory(tests)
message(STATUS "Install directory: ${CMAKE_INSTALL_PREFIX}")
#######################
# CPack (only UNIX)
#######################
if(UNIX)
if(EXISTS "/etc/debian_version") # for Debian family
set(CPACK_GENERATOR "DEB")
message(STATUS "CPACK_GENERATOR is DEB")
elseif(EXISTS "/etc/redhat-release") # for RHEL, Fedora, CentOs
set(CPACK_GENERATOR "RPM")
message(STATUS "CPACK_GENERATOR is RPM")
else()
if(EXISTS "/etc/os-release")
file(READ "/etc/os-release" OS_PARAMS)
string(REGEX MATCH "suse" OUT ${OS_PARAMS}) # for Suse-like systems
if(OUT STREQUAL "suse")
set(CPACK_GENERATOR "RPM")
message(STATUS "CPACK_GENERATOR is RPM")
else()
set(CPACK_GENERATOR "TXZ")
set(CPACK_SET_DESTDIR ON)
message(STATUS "CPACK_GENERATOR is TXZ")
endif()
else()
set(CPACK_GENERATOR "TXZ")
set(CPACK_SET_DESTDIR ON)
message(STATUS "CPACK_GENERATOR is TXZ")
endif()
endif()
set(CPACK_PACKAGE_CONTACT "intel <[email protected]>")
set(CPACK_PACKAGE_NAME "pcm")
set(CPACK_PACKAGE_VERSION "0000")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Intel(r) Performance Counter Monitor (Intel(r) PCM)")
set(CPACK_PACKAGE_DESCRIPTION "\
Intel(r) Performance Counter Monitor (Intel(r) PCM) is an application programming\n\
interface (API) and a set of tools based on the API to monitor\n\
performance and energy metrics of Intel(r) Core(tm), Xeon(r), Atom(tm)\n\
and Xeon Phi(tm) processors. PCM works on Linux, Windows, Mac OS X,\n\
FreeBSD and DragonFlyBSD operating systems.")
set(CPACK_RPM_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION})
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_RPM_PACKAGE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CMAKE_INSTALL_PREFIX})
set(CPACK_INSTALL_DEFAULT_DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE)
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_RPM_PACKAGE_RELOCATABLE TRUE)
set(CPACK_DEB_COMPONENT_INSTALL ON)
set(CPACK_RPM_COMPONENT_INSTALL ON)
include (CPack)
endif(UNIX)