Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ option(ITT_API_FORTRAN_SUPPORT "fortran support" OFF)
option(ITT_API_CPP_SUPPORT "C++ wrapper support" OFF)
option(ITT_API_REFERENCE_COLLECTOR "Build reference collector shared library" OFF)
option(ITT_API_INSTALL "Enable ITT API installation rules" ON)
option(ITT_API_INSTALL_COLLECTOR_HEADERS "Install internal headers for collector implementations" OFF)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "^(Apple)?Clang$")
# override default -O3
Expand All @@ -45,6 +46,8 @@ foreach(OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${LIBRARY_OUTPUT_PATH})
endforeach()

include(GNUInstallDirs)

set(ITT_PUBLIC_HDRS
include/ittnotify.h
include/jitprofiling.h
Expand Down Expand Up @@ -115,6 +118,39 @@ add_library(ittapi::ittnotify ALIAS ittnotify)
set(JITPROFILING_SRC "src/ittnotify/jitprofiling.c")
add_library(jitprofiling STATIC ${JITPROFILING_SRC})

# Public headers only.
add_library(ittapi_headers INTERFACE)
set_target_properties(ittapi_headers PROPERTIES EXPORT_NAME headers)
target_include_directories(ittapi_headers INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
add_library(ittapi::headers ALIAS ittapi_headers)

# Internal headers for collector implementations. Including them changes the

@mschilling0 mschilling0 Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like @eparshut suggestion. This is sort of exposing a public interface, regardless of intentions, so we need to be careful saying these are public or not. Use at your own risk. Otherwise, you want to change internal implementation of these files and boom - users complains when it changes and says you need to bump version.

Maybe a documented disclaimer, say collectors use at your own risk - API between collector and source is stable but not promising anything for internal stuff. Anything not in ittapi::headers is "use at your own risk"

# build of the including code, so they are kept apart from ittapi::headers.
# They are copied so that src/ittnotify, which holds other internal headers,
# is not exposed; the copies are laid out the same way as in the install tree.
set(ITT_COLLECTOR_HDRS
src/ittnotify/ittnotify_config.h
src/ittnotify/ittnotify_types.h
)
foreach(ITT_COLLECTOR_HDR ${ITT_COLLECTOR_HDRS})
get_filename_component(ITT_COLLECTOR_HDR_NAME ${ITT_COLLECTOR_HDR} NAME)
configure_file(${ITT_COLLECTOR_HDR}
${CMAKE_CURRENT_BINARY_DIR}/include/ittnotify/${ITT_COLLECTOR_HDR_NAME}
COPYONLY)
endforeach()

add_library(ittapi_collector_headers INTERFACE)
set_target_properties(ittapi_collector_headers PROPERTIES EXPORT_NAME collector_headers)
target_include_directories(ittapi_collector_headers INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include/ittnotify>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/ittnotify>
)
target_link_libraries(ittapi_collector_headers INTERFACE ittapi_headers)
add_library(ittapi::collector_headers ALIAS ittapi_collector_headers)

if(ITT_API_REFERENCE_COLLECTOR)
add_subdirectory(src/ittnotify_refcol)
endif()
Expand Down Expand Up @@ -158,10 +194,14 @@ endif()
# install

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

if(ITT_API_INSTALL)
install(TARGETS ittnotify EXPORT ittapi-targets INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(TARGETS ittapi_headers EXPORT ittapi-targets)
if(ITT_API_INSTALL_COLLECTOR_HEADERS)
install(TARGETS ittapi_collector_headers EXPORT ittapi-targets)
install(FILES ${ITT_COLLECTOR_HDRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/ittnotify)
endif()
if(ITT_API_CPP_SUPPORT)
install(TARGETS ittapi-cpp EXPORT ittapi-targets)
install(DIRECTORY cpp/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
Expand Down
20 changes: 10 additions & 10 deletions src/ittnotify_refcol/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,21 @@ else()
set(ITT_REFCOL_STANDALONE OFF)
endif()

set(ITT_REFCOL_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../include")
set(ITT_REFCOL_ITTNOTIFY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../ittnotify")

add_library(ittnotify_refcol SHARED itt_refcol_impl.c)

set_target_properties(ittnotify_refcol PROPERTIES
LINKER_LANGUAGE C
POSITION_INDEPENDENT_CODE ON
OUTPUT_NAME ittnotify_refcol)

target_include_directories(ittnotify_refcol PRIVATE
${ITT_REFCOL_INCLUDE_DIR}
${ITT_REFCOL_ITTNOTIFY_DIR})
if(ITT_REFCOL_STANDALONE)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user installs itt and tries to use their ITT headers with the reference collector, this will use ITT's current headers. Maybe check whether ittapi::collector_header exists first and redefine it with the two directories below if it doesn't?

Optional: up to @eparshut and @Skyb0rg007

# No root project to provide ittapi::collector_headers.
target_include_directories(ittnotify_refcol PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/../../include"
"${CMAKE_CURRENT_SOURCE_DIR}/../ittnotify")
else()
target_link_libraries(ittnotify_refcol PRIVATE ittapi::collector_headers)
endif()

target_link_libraries(ittnotify_refcol PRIVATE ${CMAKE_DL_LIBS})

Expand All @@ -59,10 +61,8 @@ set_target_properties(ittnotify_refcol PROPERTIES
option(ITT_API_REFCOL_SMOKE_TESTS "Build reference collector smoke tests" OFF)
if(ITT_API_REFCOL_SMOKE_TESTS AND NOT ITT_REFCOL_STANDALONE)
add_executable(refcol_smoke_test tests/smoke_test.c)
target_include_directories(refcol_smoke_test PRIVATE
${ITT_REFCOL_INCLUDE_DIR}
${ITT_REFCOL_ITTNOTIFY_DIR})
target_link_libraries(refcol_smoke_test PRIVATE ittnotify ${CMAKE_DL_LIBS})
target_link_libraries(refcol_smoke_test PRIVATE
ittnotify ittapi::collector_headers ${CMAKE_DL_LIBS})
set_target_properties(refcol_smoke_test PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${ITT_REFCOL_OUTPUT_DIR}")
endif()
Loading