Skip to content

Commit

Permalink
Fix test_install with PAPI.
Browse files Browse the repository at this point in the history
  • Loading branch information
tcojean committed Dec 2, 2019
1 parent efd4850 commit d274c9c
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 27 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ add_custom_target(test_install
COMMAND ${CMAKE_COMMAND} -G${CMAKE_GENERATOR} -H${Ginkgo_SOURCE_DIR}/test_install
-B${Ginkgo_BINARY_DIR}/test_install
-DCMAKE_PREFIX_PATH=${CMAKE_INSTALL_PREFIX}/${GINKGO_INSTALL_CONFIG_DIR}
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
COMMAND ${CMAKE_COMMAND} --build ${Ginkgo_BINARY_DIR}/test_install
COMMAND ${Ginkgo_BINARY_DIR}/test_install/test_install
COMMENT "Running a test on the installed binaries. This requires running `(sudo) make install` first.")
Expand Down
13 changes: 9 additions & 4 deletions cmake/GinkgoConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ set(GINKGO_HIP_NVCC_COMPILER_FLAGS @GINKGO_HIP_NVCC_COMPILER_FLAGS@)
set(GINKGO_HIP_PLATFORM @GINKGO_HIP_PLATFORM@)
set(GINKGO_HIP_AMDGPU @GINKGO_HIP_AMDGPU@)

set(GINKGO_HAVE_PAPI_SDE @GINKGO_HAVE_PAPI_SDE@)

# Ginkgo external package variables
set(GINKGO_USE_EXTERNAL_CAS "@GINKGO_USE_EXTERNAL_CAS@")
set(GINKGO_USE_EXTERNAL_GTEST "@GINKGO_USE_EXTERNAL_GTEST@")
Expand All @@ -87,10 +89,13 @@ set(TPL_RAPIDJSON_INCLUDE_DIRS "@TPL_RAPIDJSON_INCLUDE_DIRS@")
# Ginkgo installation configuration
set(GINKGO_CONFIG_FILE_PATH "${CMAKE_CURRENT_LIST_DIR}")
string(REPLACE "@GINKGO_INSTALL_CONFIG_DIR@" "" GINKGO_INSTALL_PREFIX "${GINKGO_CONFIG_FILE_PATH}")
set(GINKGO_INSTALL_INCLUDE_DIR "@GINKGO_INSTALL_INCLUDE_DIR@")
set(GINKGO_INSTALL_LIBRARY_DIR "@GINKGO_INSTALL_LIBRARY_DIR@")
set(GINKGO_INSTALL_PKGCONFIG_DIR "@GINKGO_INSTALL_PKGCONFIG_DIR@")
set(GINKGO_INSTALL_CONFIG_DIR "@GINKGO_INSTALL_CONFIG_DIR@")
set(GINKGO_INSTALL_INCLUDE_DIR "${GINKGO_INSTALL_PREFIX}/@GINKGO_INSTALL_INCLUDE_DIR@")
set(GINKGO_INSTALL_LIBRARY_DIR "${GINKGO_INSTALL_PREFIX}/@GINKGO_INSTALL_LIBRARY_DIR@")
set(GINKGO_INSTALL_PKGCONFIG_DIR "${GINKGO_INSTALL_PREFIX}/@GINKGO_INSTALL_PKGCONFIG_DIR@")
set(GINKGO_INSTALL_CONFIG_DIR "${GINKGO_INSTALL_PREFIX}/@GINKGO_INSTALL_CONFIG_DIR@")
set(GINKGO_INSTALL_MODULE_DIR "${GINKGO_INSTALL_PREFIX}/@GINKGO_INSTALL_MODULE_DIR@")
set(CMAKE_MODULE_PATH "${GINKGO_INSTALL_MODULE_DIR}")


set(GINKGO_INTERFACE_LINK_LIBRARIES "@GINKGO_INTERFACE_LINK_LIBRARIES@")
set(GINKGO_INTERFACE_LINK_FLAGS "@GINKGO_INTERFACE_LINK_FLAGS@")
Expand Down
47 changes: 24 additions & 23 deletions cmake/Modules/FindPAPI.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,31 @@ if(PAPI_INCLUDE_DIR)

if (PAPI_LIBRARY)
# find the components
foreach(component IN LISTS PAPI_FIND_COMPONENTS)
file(WRITE "${CMAKE_BINARY_DIR}/papi_${component}_detect.c"
"
#include <papi.h>
int main() {
int retval;
retval = PAPI_library_init(PAPI_VER_CURRENT);
if (retval != PAPI_VER_CURRENT && retval > 0)
return -1;
if (PAPI_get_component_index(\"${component}\") < 0)
return 0;
return 1;
}
")
try_run(PAPI_${component}_FOUND
gko_result_unused
"${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}/papi_${component}_detect.c"
LINK_LIBRARIES ${PAPI_LIBRARY}
)
enable_language(C)
foreach(component IN LISTS PAPI_FIND_COMPONENTS)
file(WRITE "${CMAKE_BINARY_DIR}/papi_${component}_detect.c"
"
#include <papi.h>
int main() {
int retval;
retval = PAPI_library_init(PAPI_VER_CURRENT);
if (retval != PAPI_VER_CURRENT && retval > 0)
return -1;
if (PAPI_get_component_index(\"${component}\") < 0)
return 0;
return 1;
}"
)
try_run(PAPI_${component}_FOUND
gko_result_unused
"${CMAKE_BINARY_DIR}"
"${CMAKE_BINARY_DIR}/papi_${component}_detect.c"
LINK_LIBRARIES ${PAPI_LIBRARY}
)

if (NOT PAPI_${component}_FOUND EQUAL 1)
unset(PAPI_${component}_FOUND)
endif()
if (NOT PAPI_${component}_FOUND EQUAL 1)
unset(PAPI_${component}_FOUND)
endif()
endforeach()
endif()
endif()
Expand Down
4 changes: 4 additions & 0 deletions cmake/install_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ set(GINKGO_INSTALL_INCLUDE_DIR "include")
set(GINKGO_INSTALL_LIBRARY_DIR "lib")
set(GINKGO_INSTALL_PKGCONFIG_DIR "lib/pkgconfig")
set(GINKGO_INSTALL_CONFIG_DIR "lib/cmake/Ginkgo")
set(GINKGO_INSTALL_MODULE_DIR "lib/cmake/Ginkgo/Modules")

function(ginkgo_install_library name subdir)
# install .so and .a files
Expand Down Expand Up @@ -33,6 +34,9 @@ function(ginkgo_install)
install(FILES "${Ginkgo_SOURCE_DIR}/third_party/papi_sde/papi_sde_interface.h"
DESTINATION "${GINKGO_INSTALL_INCLUDE_DIR}/third_party/papi_sde"
)
install(FILES "${Ginkgo_SOURCE_DIR}/cmake/Modules/FindPAPI.cmake"
DESTINATION "${GINKGO_INSTALL_MODULE_DIR}/"
)
endif()

# export targets
Expand Down
3 changes: 3 additions & 0 deletions test_install/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ find_package(Ginkgo REQUIRED
# Alternatively, use `cmake -DCMAKE_PREFIX_PATH=<ginkgo_install_dir>` to specify the install directory
)

if(GINKGO_HAVE_PAPI_SDE)
find_package(PAPI REQUIRED OPTIONAL_COMPONENTS sde)
endif()

# Needed because of a known issue with CUDA while linking statically.
# For details, see https://gitlab.kitware.com/cmake/cmake/issues/18614
Expand Down

0 comments on commit d274c9c

Please sign in to comment.