-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
115 lines (80 loc) · 3.29 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
cmake_minimum_required(VERSION 2.8.11)
project(bard)
set(VERSION_MAJOR 2)
set(VERSION_MINOR 0)
set(VERSION_PATCH 1)
set(PROJECT_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=gnu99")
include_directories(${PROJECT_SOURCE_DIR}/inc)
if(CMAKE_HOST_UNIX)
include(GNUInstallDirs)
else()
set(CMAKE_INSTALL_BINDIR bin)
set(CMAKE_INSTALL_LIBDIR lib)
set(CMAKE_INSTALL_INCLUDEDIR include)
endif()
# Test Dependencies
if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
# Determine if we should link with librt for targets that use "clock_gettime"
include(CheckFunctionExists)
CHECK_FUNCTION_EXISTS(clock_gettime HAVE_CLOCK_GETTIME)
if(NOT HAVE_CLOCK_GETTIME)
find_library(LIBRT NAMES rt)
endif()
endif()
find_package(PkgConfig)
if (PKG_CONFIG_FOUND)
pkg_check_modules(HBS heartbeats-simple)
pkg_check_modules(ENERGYMON energymon-default)
endif()
# Library
# OVERFLOW flag, causing POET fixed point to check for overflows print error statements
if(${OVERFLOW})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DPOET_MATH_OVERFLOW -DOVERFLOW_WARNING -DUNDERFLOW_WARNING")
endif()
# FIXED_POINT flag, for compiling the fixed point version of POET
if(${FIXED_POINT})
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFIXED_POINT")
endif()
add_library(bard src/poet.c src/poet_config_linux.c)
if(BUILD_SHARED_LIBS)
set_target_properties(bard PROPERTIES VERSION ${PROJECT_VERSION}
SOVERSION ${VERSION_MAJOR})
endif()
# Binaries
add_executable(bard_idle src/bard_idle.c)
# Tests
add_executable(math_ut test/math_ut.c)
add_executable(poet_config_test test/poet_config_test.c)
target_link_libraries(poet_config_test bard pthread)
if (HBS_FOUND AND ENERGYMON_FOUND)
include_directories(${HBS_INCLUDE_DIRS} ${ENERGYMON_INCLUDE_DIRS})
add_executable(double_loop_test test/double_loop_test.c)
target_link_libraries(double_loop_test bard -L${HBS_LIBDIR} ${HBS_LIBRARIES} -L${ENERGYMON_LIBDIR} ${ENERGYMON_STATIC_LIBRARIES} ${LIBRT})
add_executable(processor_speed_test test/processor_speed_test.c)
target_link_libraries(processor_speed_test bard -L${HBS_LIBDIR} ${HBS_LIBRARIES} -L${ENERGYMON_LIBDIR} ${ENERGYMON_STATIC_LIBRARIES} ${LIBRT})
endif()
# pkg-config
set(PKG_CONFIG_EXEC_PREFIX "\${prefix}")
set(PKG_CONFIG_LIBDIR "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
set(PKG_CONFIG_INCLUDEDIR "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}")
set(PKG_CONFIG_CFLAGS "-I\${includedir}")
set(PKG_CONFIG_NAME "${PROJECT_NAME}")
set(PKG_CONFIG_DESCRIPTION "Performance with Optimal Energy Toolkit")
set(PKG_CONFIG_LIBS "-L\${libdir} -lbard")
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/pkgconfig.in
${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/bard.pc
)
# Install
install(TARGETS bard DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(TARGETS bard_idle DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES inc/poet.h inc/poet_config.h inc/poet_math.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})
install(DIRECTORY ${CMAKE_BINARY_DIR}/pkgconfig/ DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
# Uninstall
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake
@ONLY
)
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)