-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
126 lines (107 loc) · 5.07 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
cmake_minimum_required(VERSION 3.17)
# CMake version is set at 3.17 because of find_package(CUDAToolkit)
# TODO: find a workaround to be able to lower the version requirement
project(hwmalloc VERSION 0.3.0 LANGUAGES CXX)
# ---------------------------------------------------------------------
# CMake setup, C++ version, build type, modules, etc
# ---------------------------------------------------------------------
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
if(NOT CMAKE_BUILD_TYPE) # AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
set(HWMALLOC_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
list(APPEND CMAKE_MODULE_PATH "${HWMALLOC_MODULE_PATH}")
# ---------------------------------------------------------------------
# Define main hwmalloc library
# ---------------------------------------------------------------------
include(hwmalloc_macros)
add_library(hwmalloc SHARED)
hwmalloc_target_compile_options(hwmalloc)
add_library(HWMALLOC::hwmalloc ALIAS hwmalloc)
# ---------------------------------------------------------------------
# NUMA setup
# ---------------------------------------------------------------------
if(UNIX AND NOT APPLE)
find_package(NUMA REQUIRED)
target_link_libraries(hwmalloc PRIVATE NUMA::libnuma)
set(HWMALLOC_NUMA_THROWS OFF CACHE BOOL "True if numa_tools may throw during initialization")
if (HWMALLOC_NUMA_THROWS)
target_compile_definitions(hwmalloc PRIVATE HWMALLOC_NUMA_THROWS)
endif()
set(HWMALLOC_NUMA_FOR_LOCAL ON CACHE BOOL "Use numa_tools for local node allocations")
if (HWMALLOC_NUMA_FOR_LOCAL)
target_compile_definitions(hwmalloc PRIVATE HWMALLOC_NUMA_FOR_LOCAL)
endif()
else()
message(WARNING "${CMAKE_PROJECT_NAME} configured without NUMA support on Mac")
endif()
# ---------------------------------------------------------------------
# Boost setup
# ---------------------------------------------------------------------
find_package(Boost REQUIRED)
target_link_libraries(hwmalloc PRIVATE Boost::boost)
# ---------------------------------------------------------------------
# GPU device support
# ---------------------------------------------------------------------
set(HWMALLOC_ENABLE_DEVICE OFF CACHE BOOL "True if GPU support shall be enabled")
# ---------------------------------------------------------------------
# Logging
# ---------------------------------------------------------------------
set(HWMALLOC_ENABLE_LOGGING OFF CACHE BOOL "print logging info to cerr")
# ---------------------------------------------------------------------
# include paths
# ---------------------------------------------------------------------
target_include_directories(hwmalloc PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>)
# ---------------------------------------------------------------------
# main src subdir
# ---------------------------------------------------------------------
add_subdirectory(src)
# ---------------------------------------------------------------------
# Generate hwmalloc config file
# ---------------------------------------------------------------------
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.hpp.in
${CMAKE_CURRENT_BINARY_DIR}/include/hwmalloc/config.hpp @ONLY)
# ---------------------------------------------------------------------
# testing
# ---------------------------------------------------------------------
set(HWMALLOC_WITH_TESTING OFF CACHE BOOL "True if tests shall be built")
if (HWMALLOC_WITH_TESTING)
enable_testing()
add_subdirectory(test)
endif()
# ---------------------------------------------------------------------
# install rules
# ---------------------------------------------------------------------
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
install(TARGETS hwmalloc
EXPORT HWMALLOC-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES ${PROJECT_BINARY_DIR}/include/hwmalloc/config.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/hwmalloc)
install(EXPORT HWMALLOC-targets
FILE HWMALLOC-targets.cmake
NAMESPACE HWMALLOC::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/hwmalloc/cmake)
configure_package_config_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/HWMALLOCConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/HWMALLOCConfig.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/hwmalloc/cmake)
write_basic_package_version_file(HWMALLOCConfigVersion.cmake
VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion)
install(
FILES
${CMAKE_CURRENT_BINARY_DIR}/HWMALLOCConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/HWMALLOCConfigVersion.cmake
${CMAKE_CURRENT_LIST_DIR}/cmake/FindNUMA.cmake
DESTINATION
${CMAKE_INSTALL_LIBDIR}/hwmalloc/cmake)
export(EXPORT HWMALLOC-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/HWMALLOC-targets.cmake")