-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
148 lines (127 loc) · 5.42 KB
/
Copy pathCMakeLists.txt
File metadata and controls
148 lines (127 loc) · 5.42 KB
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
################################################################################
# MIT License
#
# Copyright (c) 2025 Advanced Micro Devices, Inc. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
################################################################################
cmake_minimum_required(VERSION 3.22 FATAL_ERROR)
project(
nexus
VERSION 0.1.0
DESCRIPTION "Mapping packets to code"
HOMEPAGE_URL "https://github.com/AARInternal/nexus"
LANGUAGES CXX C
)
# CMake modules
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# helper functions
include(cmake/NexusCompilerOptions.cmake)
# disable in-source builds to avoid source tree corruption
if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
message(FATAL_ERROR
"In-source builds are not supported. Please create a directory for build files and delete CMakeCache.txt and \
the CMakefiles directory."
)
endif()
# check if it is built as part of a different project
string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" is_top_level)
if (NOT "${is_top_level}")
message(STATUS "Top-level project is ${CMAKE_PROJECT_NAME}")
endif ()
# default build type
set(DEFAULT_BUILD_TYPE "Release")
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to default '${DEFAULT_BUILD_TYPE}' as none was specified.")
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build." FORCE)
# possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif ()
# enable tests if requested
option(NEXUS_BUILD_TESTS "Build the test suite" ON)
# Prevent dependencies from installing to system directories
# This ensures CPM-fetched dependencies don't try to install headers/libs globally
set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY TRUE)
# target
add_library(nexus SHARED)
add_library(nexus::nexus ALIAS nexus)
target_include_directories(nexus
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/csrc/include>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>"
"$<BUILD_INTERFACE:/tmp>"
"$<INSTALL_INTERFACE:include>"
PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/csrc/src"
)
set(CMAKE_CXX_FLAGS "-O0 -g")
set(CMAKE_C_FLAGS "-O0 -g")
# library properties
set_target_properties(nexus
PROPERTIES
CXX_STANDARD 23
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF
CXX_VISIBILITY_PRESET hidden
VISIBILITY_INLINES_HIDDEN ON
POSITION_INDEPENDENT_CODE ON
VERSION "${PROJECT_VERSION}"
SOVERSION "${PROJECT_VERSION_MAJOR}"
EXPORT_NAME nexus
OUTPUT_NAME nexus
PUBLIC_HEADER "${PUBLIC_HEADERS}"
# enable RPATH during both build and installation; use relative RPATH as well
SKIP_BUILD_RPATH FALSE
BUILD_WITH_INSTALL_RPATH TRUE
INSTALL_RPATH_USE_LINK_PATH TRUE
BUILD_RPATH "\$ORIGIN"
INSTALL_RPATH "\$ORIGIN"
# organize lib / bin in the build directory
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin
)
# Install the library into the Python package directory so it sits next to
# nexus/__init__.py in site-packages. When building via scikit-build-core,
# SKBUILD_PLATLIB_DIR is set to the wheel's platlib (site-packages); installing
# to ${SKBUILD_PLATLIB_DIR}/nexus ensures the .so is copied into the package.
if(DEFINED SKBUILD_PLATLIB_DIR)
set(NEXUS_PKG_DEST "${SKBUILD_PLATLIB_DIR}/nexus")
else()
set(NEXUS_PKG_DEST "nexus")
endif()
install(TARGETS nexus
LIBRARY DESTINATION ${NEXUS_PKG_DEST}
RUNTIME DESTINATION ${NEXUS_PKG_DEST}
)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
# sources
add_subdirectory(csrc/src)
# Install kernelDB library (dependency) to the nexus package
if(TARGET kernelDB64)
install(TARGETS kernelDB64
LIBRARY DESTINATION ${NEXUS_PKG_DEST}
RUNTIME DESTINATION ${NEXUS_PKG_DEST}
)
endif()
if(NEXUS_BUILD_TESTS AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test")
message("Building tests...")
add_subdirectory(test)
endif()