-
Notifications
You must be signed in to change notification settings - Fork 6
/
CMakeLists.txt
134 lines (123 loc) · 5.66 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
cmake_minimum_required (VERSION 2.6)
project(simplecpu)
include_directories ("${PROJECT_SOURCE_DIR}/../../include")
add_executable("pmda${PROJECT_NAME}" "${PROJECT_NAME}.cpp")
add_executable("pmda${PROJECT_NAME}-noboost" "${PROJECT_NAME}.cpp")
add_library("pmda_${PROJECT_NAME}" SHARED "${PROJECT_NAME}.cpp")
find_package(Boost COMPONENTS program_options REQUIRED)
target_link_libraries("pmda${PROJECT_NAME}" pcp pcp_pmda ${Boost_PROGRAM_OPTIONS_LIBRARY})
target_link_libraries("pmda${PROJECT_NAME}-noboost" pcp pcp_pmda)
target_link_libraries("pmda_${PROJECT_NAME}" pcp pcp_pmda ${Boost_PROGRAM_OPTIONS_LIBRARY})
set_property(
TARGET "pmda${PROJECT_NAME}-noboost"
PROPERTY COMPILE_DEFINITIONS PCP_CPP_NO_BOOST
)
# Detect the PCP environment.
find_program(
PCP_PMCONFIG_EXECUTABLE
NAMES pmconfig
PATHS /usr/lib/pcp/bin /usr/libexec/pcp/bin
)
if (PCP_PMCONFIG_EXECUTABLE)
message(STATUS "Found pmconfig: ${PCP_PMCONFIG_EXECUTABLE}")
execute_process(
COMMAND ${PCP_PMCONFIG_EXECUTABLE} PCP_BINADM_DIR PCP_PMDAS_DIR
OUTPUT_VARIABLE PCP_PMCONFIG_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE
)
STRING(REPLACE "\n" ";" PCP_PMCONFIG_OUTPUT ${PCP_PMCONFIG_OUTPUT})
foreach (PCP_PMCONFIG_LINE ${PCP_PMCONFIG_OUTPUT})
string(REGEX REPLACE "=.*$" "" PCP_PMCONFIG_NAME ${PCP_PMCONFIG_LINE})
string(REGEX REPLACE "^[A-Z_]+=" "" PCP_PMCONFIG_VALUE ${PCP_PMCONFIG_LINE})
set(${PCP_PMCONFIG_NAME} ${PCP_PMCONFIG_VALUE})
message(STATUS " ${PCP_PMCONFIG_NAME}: ${${PCP_PMCONFIG_NAME}}")
endforeach ()
endif ()
find_program(PCP_NEWHELP_EXECUTABLE NAMES newhelp HINTS ${PCP_BINADM_DIR})
if (PCP_NEWHELP_EXECUTABLE)
message(STATUS "Found newhelp: ${PCP_NEWHELP_EXECUTABLE}")
endif ()
# Setup the default installation directory.
if (PCP_PMDAS_DIR)
set(DEFAULT_PMDAS_INSTALL_DIR ${PCP_PMDAS_DIR}/pcp-pmda-cpp-examples/pmdas)
set(
PMDAS_INSTALL_DIR ${DEFAULT_PMDAS_INSTALL_DIR}
CACHE PATH "directory to install PMDAs to (${DEFAULT_PMDAS_INSTALL_DIR})"
)
endif()
# Create an install target, but only if the PMDAS_INSTALL_DIR directory was set.
if (PMDAS_INSTALL_DIR)
SET(PMDA_INSTALL_DIR ${PMDAS_INSTALL_DIR}/${PROJECT_NAME})
# Install the PMDA binaries.
install(
TARGETS "pmda${PROJECT_NAME}" "pmda${PROJECT_NAME}-noboost"
RUNTIME DESTINATION ${PMDA_INSTALL_DIR}
)
# Export the PMDA's support files (domain, help, pmns, etc).
install(
CODE "
message(\"-- Exporting: \$ENV{DESTDIR}${PMDA_INSTALL_DIR}/{domain.h,help,pmns,root}\")
execute_process(
COMMAND \$ENV{DESTDIR}${PMDA_INSTALL_DIR}/pmda${PROJECT_NAME} --export-all
WORKING_DIRECTORY \$ENV{DESTDIR}${PMDA_INSTALL_DIR}
RESULT_VARIABLE export_result
)
if (NOT \${export_result} EQUAL 0)
message(FATAL_ERROR \"Failed to export PMDA support files: \${export_result}\")
endif ()
if (EXISTS ${PCP_NEWHELP_EXECUTABLE})
message(\"-- Generating: \$ENV{DESTDIR}${PMDA_INSTALL_DIR}/help.{dir,pag}\")
execute_process(
COMMAND ${PCP_NEWHELP_EXECUTABLE} -n root help
WORKING_DIRECTORY \$ENV{DESTDIR}${PMDA_INSTALL_DIR}
RESULT_VARIABLE export_result
)
if (NOT \${export_result} EQUAL 0)
message(FATAL_ERROR \"Failed to generate help database: \${export_result}\")
endif ()
endif ()
"
)
# Install the PMDA source and registration scripts.
configure_file(Install.in ${CMAKE_CURRENT_SOURCE_DIR}/Install)
configure_file(Remove.in ${CMAKE_CURRENT_SOURCE_DIR}/Remove)
install(PROGRAMS Install Remove DESTINATION ${PMDA_INSTALL_DIR})
install(FILES ${PROJECT_NAME}.cpp DESTINATION ${PMDA_INSTALL_DIR})
endif()
# Enable (and stop on) compiler warnings.
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag(-Wall HAVE_WALL)
check_cxx_compiler_flag(-Werror HAVE_WERROR)
check_cxx_compiler_flag(-Wextra HAVE_WEXTRA)
if (HAVE_WALL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif()
if (HAVE_WERROR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
endif()
if (HAVE_WEXTRA)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wextra")
endif()
# Enable test coverage reporting.
check_cxx_compiler_flag(-ftest-coverage HAVE_TEST_COVERAGE)
if (HAVE_TEST_COVERAGE)
# Remove optimisation flags for accurate coverage reporting, but not
# if source fortification is enabled, since: "_FORTIFY_SOURCE requires
# compiling with optimization (-O)" (see /usr/include/features.h).
if (NOT ${CMAKE_CXX_FLAGS} MATCHES "-D_FORTIFY_SOURCE=[^0]")
string(REGEX REPLACE "(^| )-O[^ ]*( *|$)" "\\1" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0")
endif()
if (NOT ${CMAKE_CXX_FLAGS_DEBUG} MATCHES "-D_FORTIFY_SOURCE=[^0]")
string(REGEX REPLACE "(^| )-O[^ ]*( *|$)" "\\1" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0")
endif()
if (NOT ${CMAKE_CXX_FLAGS_RELEASE} MATCHES "-D_FORTIFY_SOURCE=[^0]")
string(REGEX REPLACE "(^| )-O[^ ]*( *|$)" "\\1" CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE})
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O0")
endif()
# Enable gcov code instrumentation for code coverage reporting.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fprofile-arcs -ftest-coverage")
endif()