diff --git a/ci/build_cpp.sh b/ci/build_cpp.sh index db4ef0469a..32fb90bcfa 100755 --- a/ci/build_cpp.sh +++ b/ci/build_cpp.sh @@ -73,6 +73,17 @@ else fi fi +if test -d "${source_dir}/lib/papi" +then + { echo "papi already in lib... not downloading, building, and installing"; } 2>/dev/null +else + cd "${source_dir}/lib" + git clone https://github.com/icl-utk-edu/papi.git + cd papi/src + ./configure --prefix=${source_dir}/lib/papi/install + make && make install +fi + if test "${VT_ZOLTAN_ENABLED:-0}" -eq 1 then export Zoltan_DIR=${ZOLTAN_DIR:-""} diff --git a/cmake/FindPAPI.cmake b/cmake/FindPAPI.cmake new file mode 100644 index 0000000000..6ccab46b3c --- /dev/null +++ b/cmake/FindPAPI.cmake @@ -0,0 +1,21 @@ +# Set minimum CMake version +cmake_minimum_required(VERSION 3.23 FATAL_ERROR) + +set(PAPI_ROOT "${CMAKE_SOURCE_DIR}/lib/papi/install") + +# Find the PAPI include directory and library +find_path(PAPI_INCLUDE_DIR NAMES papi.h HINTS ${PAPI_ROOT}/include) +find_library(PAPI_LIBRARY NAMES papi HINTS ${PAPI_ROOT}/lib) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(PAPI DEFAULT_MSG PAPI_LIBRARY PAPI_INCLUDE_DIR) + +if(PAPI_FOUND AND NOT TARGET PAPI::PAPI) + add_library(PAPI::PAPI UNKNOWN IMPORTED) + set_target_properties(PAPI::PAPI PROPERTIES + IMPORTED_LOCATION "{PAPI_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${PAPI_INCLUDE_DIR}" + ) +endif() + +mark_as_advanced(PAPI_INCLUDE_DIR PAPI_LIBRARY) diff --git a/cmake/link_vt.cmake b/cmake/link_vt.cmake index 8b6303404b..26d25b8298 100644 --- a/cmake/link_vt.cmake +++ b/cmake/link_vt.cmake @@ -33,6 +33,7 @@ function(link_target_with_vt) LINK_FORT LINK_JSON LINK_BROTLI + LINK_PAPI ) set( multiValueArg @@ -41,7 +42,7 @@ function(link_target_with_vt) set(allKeywords ${noValOption} ${singleValArg} ${multiValueArg}) cmake_parse_arguments( - ARG "${noValOption}" "${singleValArg}" "${multiValueArgs}" ${ARGN} + ARG "${noValOption}" "${singleValArg}" "${multiValueArg}" ${ARGN} ) if (${ARG_DEBUG_LINK}) @@ -211,6 +212,15 @@ function(link_target_with_vt) ) endif() + if (NOT DEFINED ARG_LINK_PAPI AND ${ARG_DEFAULT_LINK_SET} OR ARG_LINK_PAPI) + if (${ARG_DEBUG_LINK}) + message(STATUS "link_target_with_vt: papi=${ARG_LINK_PAPI}") + endif() + target_link_libraries( + ${ARG_TARGET} PUBLIC ${ARG_BUILD_TYPE} ${PAPI_LIBRARY} + ) + endif() + if (${vt_mimalloc_enabled}) if (${ARG_DEBUG_LINK}) message(STATUS "link_target_with_vt: mimalloc=${vt_mimalloc_enabled}") diff --git a/cmake/load_packages.cmake b/cmake/load_packages.cmake index 7bf97150c9..eaa9566e45 100644 --- a/cmake/load_packages.cmake +++ b/cmake/load_packages.cmake @@ -18,5 +18,8 @@ include(cmake/load_doxygen.cmake) # Optionally link with Zoltan include(cmake/load_zoltan_package.cmake) +# Link with PAPI +include(cmake/load_papi.cmake) + # Tests include(cmake/test_vt.cmake) diff --git a/cmake/load_papi.cmake b/cmake/load_papi.cmake new file mode 100644 index 0000000000..82eff87c61 --- /dev/null +++ b/cmake/load_papi.cmake @@ -0,0 +1,3 @@ +find_package(PAPI REQUIRED) +message(STATUS: "FOUND PAPI: PAPI LIBRARY: ${PAPI_LIBRARY}\n PAPI INCLUDE DIR: ${PAPI_INCLUDE_DIR}") +set(vt_papi_found "1")