Skip to content

Commit a5034f4

Browse files
authored
[PTI-SDK] Add Version Header File (#6)
Add version header generated by CMake. This includes macros for detecting the current version of PTI and a function for determining the compiled version of PTI. Move *toolchain.cmake files to a separate directory. Remove -gline-tables-only because it is not needed and it prevents gcc builds. Signed-off-by: Schilling, Matthew <[email protected]>
1 parent b1f975d commit a5034f4

14 files changed

+119
-25
lines changed

sdk/CMakeLists.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ if(PTI_FUZZ)
5656
CACHE BOOL "" FORCE)
5757
endif()
5858

59-
6059
include(GNUInstallDirs)
6160
set(PTI_INSTALL_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/pti")
6261
set(PTI_INSTALL_INCLUDE_DIR "${CMAKE_INSTALL_INCLUDEDIR}/pti")
@@ -105,6 +104,9 @@ set(PTI_DEFINE_FLAGS_EXPR
105104
$<$<CXX_COMPILER_ID:GNU>:$<$<NOT:$<BOOL:${PTI_SANITIZE}>>:_FORTIFY_SOURCE=2>>
106105
)
107106

107+
configure_file(${PROJECT_SOURCE_DIR}/include/pti_version.h.in
108+
${PROJECT_BINARY_DIR}/include/pti_version.h)
109+
108110
# https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html
109111
add_library(pti SHARED "${PROJECT_SOURCE_DIR}/src/pti.cc")
110112
add_library(Pti::pti ALIAS pti)
@@ -117,6 +119,7 @@ generate_export_header(pti)
117119
target_include_directories(
118120
pti
119121
PUBLIC "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>"
122+
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>"
120123
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
121124
"$<INSTALL_INTERFACE:${PTI_INSTALL_INCLUDE_DIR}>"
122125
PRIVATE "${PROJECT_SOURCE_DIR}/src" "${PROJECT_SOURCE_DIR}/src/levelzero"
@@ -133,13 +136,15 @@ target_compile_options(pti PRIVATE ${PTI_COMPILE_FLAGS_EXPR})
133136
target_link_options(pti PRIVATE ${PTI_LINK_FLAGS_EXPR})
134137
target_compile_definitions(pti PRIVATE ${PTI_DEFINE_FLAGS_EXPR})
135138

136-
add_library(pti_view SHARED "${PROJECT_SOURCE_DIR}/src/pti_view.cc")
139+
add_library(pti_view SHARED "${PROJECT_SOURCE_DIR}/src/pti_view.cc"
140+
"${PROJECT_SOURCE_DIR}/src/pti_version.cc")
137141
add_library(Pti::pti_view ALIAS pti_view)
138142
# add_library(pti_callback SHARED "..") add_library(pti_event SHARED "..")
139143
# add_library(pti_metric SHARED "..") add_library(pti_profiling SHARED "..") ..
140144
target_include_directories(
141145
pti_view
142146
PUBLIC "$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>"
147+
"$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>"
143148
"$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>"
144149
"$<INSTALL_INTERFACE:${PTI_INSTALL_INCLUDE_DIR}>"
145150
PRIVATE "${PROJECT_SOURCE_DIR}/src" "${PROJECT_SOURCE_DIR}/src/syclpi"
@@ -218,7 +223,7 @@ if(PTI_INSTALL)
218223
write_basic_package_version_file(
219224
"${PROJECT_BINARY_DIR}/PtiConfigVersion.cmake"
220225
VERSION "${PROJECT_VERSION}"
221-
COMPATIBILITY SameMajorVersion)
226+
COMPATIBILITY SameMinorVersion)
222227

223228
install(FILES "${PROJECT_BINARY_DIR}/PtiConfig.cmake"
224229
"${PROJECT_BINARY_DIR}/PtiConfigVersion.cmake"
@@ -239,9 +244,13 @@ if(PTI_INSTALL)
239244
install(FILES "${PROJECT_BINARY_DIR}/pti_export.h"
240245
DESTINATION "${PTI_INSTALL_INCLUDE_DIR}")
241246

242-
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/"
247+
install(FILES "${PROJECT_BINARY_DIR}/include/pti_version.h"
243248
DESTINATION "${PTI_INSTALL_INCLUDE_DIR}")
244249

250+
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/"
251+
DESTINATION "${PTI_INSTALL_INCLUDE_DIR}"
252+
FILES_MATCHING PATTERN "*.h")
253+
245254
install(
246255
EXPORT PtiTargets
247256
FILE PtiTargets.cmake

sdk/CMakePresets.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"binaryDir": "${sourceDir}/build",
1010
"cacheVariables": {
1111
"CMAKE_BUILD_TYPE": "Release",
12-
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/icpx_toolchain.cmake"
12+
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/icpx_toolchain.cmake"
1313
}
1414
},
1515
{
@@ -43,7 +43,7 @@
4343
"binaryDir": "${sourceDir}/build-${presetName}",
4444
"cacheVariables": {
4545
"CMAKE_BUILD_TYPE": "Debug",
46-
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/icpx_asan_toolchain.cmake",
46+
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/icpx_asan_toolchain.cmake",
4747
"PTI_SANITIZE": true
4848
},
4949
"environment": {
@@ -62,7 +62,7 @@
6262
"binaryDir": "${sourceDir}/build-${presetName}",
6363
"cacheVariables": {
6464
"PTI_FUZZ": true,
65-
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/icpx_fuzz_toolchain.cmake"
65+
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/icpx_fuzz_toolchain.cmake"
6666
}
6767
},
6868
{
@@ -71,7 +71,7 @@
7171
"displayName": "ThreadSanitizer Test Config",
7272
"description": "Build configuration for thread sanitizer.",
7373
"cacheVariables": {
74-
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/icpx_tsan_toolchain.cmake"
74+
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/icpx_tsan_toolchain.cmake"
7575
}
7676
},
7777
{
@@ -81,7 +81,7 @@
8181
"description": "Build Configuration for building PTI without ICPX",
8282
"cacheVariables": {
8383
"CMAKE_BUILD_TYPE": "Release",
84-
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/clang_toolchain.cmake"
84+
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/cmake/toolchains/clang_toolchain.cmake"
8585
}
8686
}
8787
],

sdk/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ From `build` directory:
7171
```console
7272
>> mkdir build
7373
>> cd build
74-
>> cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../cmake/icpx_toolchain.cmake -DBUILD_TESTING=OFF ..
74+
>> cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/icpx_toolchain.cmake -DBUILD_TESTING=OFF ..
7575
>> make -j
7676
>> cmake --install . --config Release --prefix "../out"
7777
```

sdk/include/pti.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#ifndef INCLUDE_PTI_H_
88
#define INCLUDE_PTI_H_
99

10+
#include "pti_version.h"
1011
#include "pti_view.h"
1112

1213
#endif // INCLUDE_PTI_H_

sdk/include/pti_version.h.in

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//==============================================================
2+
// Copyright (C) Intel Corporation
3+
//
4+
// SPDX-License-Identifier: MIT
5+
// =============================================================
6+
#ifndef INCLUDE_PTI_VERSION_H_
7+
#define INCLUDE_PTI_VERSION_H_
8+
9+
#include <stdint.h>
10+
11+
#include "pti_export.h"
12+
13+
#if defined(__cplusplus)
14+
extern "C" {
15+
#endif
16+
17+
/* clang-format off */
18+
#if !defined(PTI_VERSION)
19+
#define PTI_VERSION @PTI_VERSION@
20+
#endif
21+
22+
#define PTI_VERSION_STRING "@PTI_VERSION@"
23+
#define PTI_VERSION_MAJOR @PROJECT_VERSION_MAJOR@
24+
#define PTI_VERSION_MINOR @PROJECT_VERSION_MINOR@
25+
#define PTI_VERSION_PATCH @PROJECT_VERSION_PATCH@
26+
/* clang-format on */
27+
28+
typedef struct pti_version {
29+
uint32_t _major;
30+
uint32_t _minor;
31+
uint32_t _patch;
32+
} pti_version;
33+
34+
/**
35+
* @brief Returns the compiled version of PTI
36+
*
37+
* @return c-string with compiled version of PTI
38+
*/
39+
const char* PTI_EXPORT ptiVersionString();
40+
41+
/**
42+
* @brief Returns the compiled version of PTI
43+
*
44+
* @return pti_version struct with compiled version of PTI
45+
*/
46+
pti_version PTI_EXPORT ptiVersion();
47+
48+
#if defined(__cplusplus)
49+
}
50+
#endif
51+
52+
#endif // INCLUDE_PTI_VERSION_H_

0 commit comments

Comments
 (0)