diff --git a/CMakeLists.txt b/CMakeLists.txt index 134a3da..0f3a3d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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 @@ -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 + $ + $ +) +add_library(ittapi::headers ALIAS ittapi_headers) + +# Internal headers for collector implementations. Including them changes the +# 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 + $ + $ +) +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() @@ -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} diff --git a/src/ittnotify_refcol/CMakeLists.txt b/src/ittnotify_refcol/CMakeLists.txt index e05d297..23d684a 100644 --- a/src/ittnotify_refcol/CMakeLists.txt +++ b/src/ittnotify_refcol/CMakeLists.txt @@ -21,9 +21,6 @@ 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 @@ -31,9 +28,14 @@ set_target_properties(ittnotify_refcol PROPERTIES 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) + # 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}) @@ -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()