-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
133 lines (108 loc) · 4.62 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
cmake_minimum_required(VERSION 3.9)
cmake_policy(SET CMP0048 NEW)
project(x86_energy VERSION 2.0)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to 'Debug' as none was specified.")
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
add_library(x86_energy SHARED
src/architecture/architecture.c
src/architecture/overflow_thread.c
src/architecture/parse_architecture.c
src/access/msr_fam15.c
src/access/msr_fam23.c
src/access/msr.c
src/access/perf.c
src/access/procfs.c
src/access/sysfs_fam15.c
src/access/sysfs.c
src/error/error.c
)
add_library(x86_energy-static STATIC
src/architecture/architecture.c
src/architecture/overflow_thread.c
src/architecture/parse_architecture.c
src/access/msr_fam15.c
src/access/msr_fam23.c
src/access/msr.c
src/access/perf.c
src/access/procfs.c
src/access/sysfs_fam15.c
src/access/sysfs.c
src/error/error.c
)
target_link_libraries(x86_energy PUBLIC Threads::Threads m)
target_link_libraries(x86_energy-static PUBLIC Threads::Threads m)
find_package(X86Adapt)
if (X86Adapt_FOUND)
target_include_directories(x86_energy PRIVATE ${X86_ADAPT_INCLUDE_DIRS})
target_sources(x86_energy PRIVATE src/access/x86_adapt.c src/access/x86_adapt_fam23.c)
target_compile_definitions(x86_energy PRIVATE USEX86_ADAPT)
target_link_libraries(x86_energy PUBLIC ${X86_ADAPT_LIBRARIES})
target_include_directories(x86_energy-static PRIVATE ${X86_ADAPT_INCLUDE_DIRS})
target_sources(x86_energy-static PRIVATE src/access/x86_adapt.c src/access/x86_adapt_fam23.c)
target_compile_definitions(x86_energy-static PRIVATE USEX86_ADAPT)
target_link_libraries(x86_energy-static PUBLIC ${X86_ADAPT_LIBRARIES})
endif()
find_package(Likwid)
if (LIKWID_FOUND)
target_include_directories(x86_energy PRIVATE ${LIKWID_INCLUDE_DIRS})
target_sources(x86_energy PRIVATE src/access/likwid.c)
target_compile_definitions(x86_energy PRIVATE USELIKWID)
target_link_libraries(x86_energy PUBLIC ${LIKWID_LIBRARIES})
target_include_directories(x86_energy-static PRIVATE ${LIKWID_INCLUDE_DIRS})
target_sources(x86_energy-static PRIVATE src/access/likwid.c)
target_compile_definitions(x86_energy-static PRIVATE USELIKWID)
target_link_libraries(x86_energy-static PUBLIC ${LIKWID_LIBRARIES})
endif()
target_include_directories(x86_energy PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
set_target_properties(x86_energy PROPERTIES PUBLIC_HEADER "include/x86_energy.h;include/x86_energy.hpp")
target_compile_features(x86_energy PUBLIC c_std_99)
target_include_directories(x86_energy-static PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
set_target_properties(x86_energy-static PROPERTIES
POSITION_INDEPENDENT_CODE TRUE
OUTPUT_NAME "x86_energy"
)
target_compile_features(x86_energy-static PUBLIC c_std_99)
add_library(x86_energy::x86_energy ALIAS x86_energy-static)
add_library(x86_energy_cxx INTERFACE)
target_link_libraries(x86_energy_cxx INTERFACE x86_energy::x86_energy)
target_compile_features(x86_energy_cxx INTERFACE cxx_std_11)
add_library(x86_energy::x86_energy_cxx ALIAS x86_energy_cxx)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
# build Debug with all warnings
target_compile_options(x86_energy INTERFACE $<$<CONFIG:Debug>:-Wall -pedantic -Wextra>)
target_compile_options(x86_energy-static INTERFACE $<$<CONFIG:Debug>:-Wall -pedantic -Wextra>)
add_subdirectory(test)
install(TARGETS x86_energy x86_energy-static x86_energy_cxx
EXPORT x86_energyTargets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include
)
install(EXPORT x86_energyTargets
DESTINATION share/cmake/x86_energy
NAMESPACE x86_energy::
)
include(CMakePackageConfigHelpers)
write_basic_package_version_File("x86_energyConfigVersion.cmake"
VERSION ${x86_energy_VERSION}
COMPATIBILITY SameMajorVersion
)
install(FILES "x86_energyConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/x86_energyConfigVersion.cmake"
DESTINATION share/cmake/x86_energy
)
else()
set_target_properties(x86_energy-static x86_energy PROPERTIES EXCLUDE_FROM_ALL TRUE)
endif()