Skip to content

Commit

Permalink
Setup CMake config for genten to be packaged and found by external pr…
Browse files Browse the repository at this point in the history
…ojects
  • Loading branch information
hnkolla committed Mar 20, 2021
1 parent 0cc9c64 commit c3b0995
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 34 deletions.
14 changes: 12 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ CMAKE_MINIMUM_REQUIRED (VERSION 3.10)
#---- Declaring the project name will define ${Genten_SOURCE_DIR} to be
#---- the path to this source file, and ${Genten_BINARY_DIR} to be the path
#---- to the directory where cmake has been invoked.
PROJECT (Genten)
project(Genten VERSION "0.0.0")

#---- Require C++14 without GNU extensions
SET(CMAKE_CXX_STANDARD 14)
Expand All @@ -54,8 +54,8 @@ SET(CMAKE_CXX_EXTENSIONS OFF)
#------------------------------------------------------------
#---- Package OPTIONS
#------------------------------------------------------------
# Note: OPTION is a binary thing and can't have string in them
OPTION(BUILD_SHARED_LIBS "Build shared libraries." OFF)
OPTION(KOKKOS_PATH "Path to Kokkos installation for external Kokkos builds. Setting this turns off the inline build with the bundled Kokkos source.")
OPTION(ENABLE_BOOST "Enable Boost for reading compressed tensor files" OFF)
OPTION(ENABLE_CALIPER "Enable Caliper for application profiling" OFF)
OPTION(ENABLE_MATLAB "Enable MATLAB linkage to Tensor Toolbox" OFF)
Expand All @@ -75,6 +75,7 @@ ELSE()
SET(GENTEN_INDEX_TYPE "size_t")
ENDIF()

# if the kokkos path is provided use the installation
IF(KOKKOS_PATH)
SET(KOKKOS_INLINE_BUILD OFF)
ELSE()
Expand Down Expand Up @@ -302,6 +303,7 @@ TARGET_LINK_LIBRARIES(
INSTALL (
TARGETS genten_mathlibs_c
DESTINATION ${CMAKE_INSTALL_LIBDIR}
EXPORT genten
)
SET(GENTEN_MATHLIBS
genten_mathlibs_c
Expand Down Expand Up @@ -372,6 +374,7 @@ SET(GENTEN_LINK_LIBS gentenlib ${GENTEN_MATHLIBS} ${GENTEN_LIBS} ${ROL_LIBRARIES
TARGET_LINK_LIBRARIES(${GENTEN_LINK_LIBS})
INSTALL (
TARGETS gentenlib
EXPORT genten
DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

Expand Down Expand Up @@ -482,6 +485,7 @@ ADD_EXECUTABLE (
TARGET_LINK_LIBRARIES (genten ${GENTEN_LINK_LIBS})
INSTALL (
TARGETS genten
EXPORT genten
DESTINATION ${CMAKE_INSTALL_BINDIR}
)

Expand Down Expand Up @@ -594,3 +598,9 @@ add_test(Genten_MTTKRP_aminoacid_atomic ${Genten_BINARY_DIR}/bin/perf_MTTKRP --n
add_test(Genten_MTTKRP_aminoacid_dupl ${Genten_BINARY_DIR}/bin/perf_MTTKRP --nc 16 --input ${Genten_BINARY_DIR}/data/aminoacid_data.txt --mttkrp-method duplicated)
add_test(Genten_MTTKRP_aminoacid_perm ${Genten_BINARY_DIR}/bin/perf_MTTKRP --nc 16 --input ${Genten_BINARY_DIR}/data/aminoacid_data.txt --mttkrp-method perm)
add_test(Genten_MTTKRP_random_dense ${Genten_BINARY_DIR}/bin/perf_MTTKRP --nc 16 --dims [30,40,50] --dense)

#------------------------------------------------------------
#---- Config
#------------------------------------------------------------
add_subdirectory(config)
install(EXPORT genten DESTINATION lib64/cmake/${PROJECT_NAME})
56 changes: 56 additions & 0 deletions config/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
###############################################################################
# export everything for a cmake build to be able to import with find_package
###############################################################################

if (NOT DEFINED GENTEN_INSTALL_INCLUDE_DIR)
set(GENTEN_INSTALL_INCLUDE_DIR "include")
endif()

if (NOT DEFINED GENTEN_INSTALL_CONFIG_DIR)
set(GENTEN_INSTALL_CONFIG_DIR "lib64")
endif()

if (NOT DEFINED GENTEN_INSTALL_LIB_DIR)
set(GENTEN_INSTALL_LIB_DIR "lib64")
endif()

if (NOT DEFINED GENTEN_INSTALL_BIN_DIR)
set(GENTEN_INSTALL_BIN_DIR "bin")
endif()

if (NOT DEFINED GENTEN_INSTALL_CMAKE_MODULE_DIR)
if(WIN32)
set(GENTEN_INSTALL_CMAKE_MODULE_DIR "cmake")
else()
set(GENTEN_INSTALL_CMAKE_MODULE_DIR "${GENTEN_INSTALL_CONFIG_DIR}/cmake/Genten")
endif()
endif()

include(CMakePackageConfigHelpers)
# write version heler
write_basic_package_version_file(
${CMAKE_CURRENT_BINARY_DIR}/GentenConfigVersion.cmake
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)

# write cmake package config file
configure_package_config_file(
GentenConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/GentenConfig.cmake
INSTALL_DESTINATION ${GENTEN_INSTALL_CMAKE_MODULE_DIR}
PATH_VARS
GENTEN_INSTALL_INCLUDE_DIR
GENTEN_INSTALL_LIB_DIR
GENTEN_INSTALL_BIN_DIR
GENTEN_INSTALL_CMAKE_MODULE_DIR
)

# install everything needed
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/GentenConfig.cmake
${CMAKE_CURRENT_BINARY_DIR}/GentenConfigVersion.cmake
genten_setup_deps.cmake
genten_setup_targets.cmake
DESTINATION ${GENTEN_INSTALL_CMAKE_MODULE_DIR})

40 changes: 40 additions & 0 deletions config/GentenConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
###############################################################################
# Note:
# This file is named XxxConfig.cmake because once upon a time
# when it was named xxx-config.cmake, we found that CMake's exported
# targets script includes all "xxx*.cmake" files. This logic would
# cause this script to be included more than once, seeding instability
# that caused great harm to the kingdom.
###############################################################################

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)

@PACKAGE_INIT@


if(NOT GENTEN_FOUND)

set(GENTEN_VERSION "@PROJECT_VERSION@")
set(GENTEN_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@")

set(GENTEN_KOKKOS_DIR "@KOKKOS_PATH@")

# advertise if mfem support is enabled
set(GENTEN_LAPACK_FOUND @LAPACK_FOUND@)
set(GENTEN_LAPACK_LIBS "@LAPACK_LIBS@")

# pull in vars with details about configured paths
get_filename_component(GENTEN_CMAKE_CONFIG_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)

# setup dependent pkgs (i.e., kokkos)
include(${GENTEN_CMAKE_CONFIG_DIR}/genten_setup_deps.cmake)

# include the main exported targets
include("${GENTEN_CMAKE_CONFIG_DIR}/genten.cmake")

# finish setup
include("${GENTEN_CMAKE_CONFIG_DIR}/genten_setup_targets.cmake")

set(GENTEN_FOUND TRUE)

endif()
12 changes: 12 additions & 0 deletions config/genten_setup_deps.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
if(GENTEN_KOKKOS_DIR)
if(NOT EXISTS ${GENTEN_KOKKOS_DIR}/lib64/cmake/Kokkos/KokkosConfig.cmake)
MESSAGE(FATAL_ERROR "Could not find kokkos CMake include file (${GENTEN_KOKKOS_DIR}/lib64/cmake/Kokkos/KokkosConfig.cmake)")
endif()

###############################################################################
# Import Kokkos CMake targets
###############################################################################
find_package(Kokkos REQUIRED
NO_DEFAULT_PATH
PATHS ${GENTEN_KOKKOS_DIR}/lib64/cmake/Kokkos)
endif()
15 changes: 15 additions & 0 deletions config/genten_setup_targets.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
set(GENTEN_INCLUDE_DIRS "${GENTEN_INSTALL_PREFIX}/include/genten")

add_library(genten::genten INTERFACE IMPORTED)

set_property(TARGET genten::genten
APPEND PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${GENTEN_INSTALL_PREFIX}/include/")

set_property(TARGET genten::genten
APPEND PROPERTY
INTERFACE_INCLUDE_DIRECTORIES "${GENTEN_INSTALL_PREFIX}/include/genten/")

set_property(TARGET genten::genten
PROPERTY INTERFACE_LINK_LIBRARIES
genten_mathlibs_c gentenlib gt_higher_moments)
48 changes: 16 additions & 32 deletions joint_moments/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,46 +1,30 @@
#--https://stackoverflow.com/questions/49857596/cmake-simple-config-file-example/49858236
#--https://stackoverflow.com/questions/20746936/what-use-is-find-package-if-you-need-to-specify-cmake-module-path-anyway
set(joint_moment_headers Genten_HigherMoments.hpp)

ADD_LIBRARY (
gt_higher_moments SHARED
${Genten_SOURCE_DIR}/joint_moments/Genten_HigherMoments.cpp
)
TARGET_LINK_LIBRARIES(gt_higher_moments PUBLIC ${GENTEN_LINK_LIBS})


INSTALL(
TARGETS genten_mathlibs_c gentenlib gt_higher_moments
DESTINATION ${CMAKE_INSTALL_LIBDIR}
EXPORT gt_higher_momentsConfig
INSTALL (
FILES ${joint_moment_headers}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/genten
PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
)

INSTALL(
EXPORT gt_higher_momentsConfig
DESTINATION cmake
TARGETS gt_higher_moments
DESTINATION ${CMAKE_INSTALL_LIBDIR}
EXPORT genten
)

#HK3
#HK3EXPORT(
#HK3 EXPORT gt_higher_momentsConfig
#HK3 NAMESPACE gt_higher_moments::
#HK3 FILE gt_higher_momentsConfig.cmake
#HK3 )
#HK3
#HK3EXPORT( PACKAGE gt_higher_moments)

#HKINSTALL (
#HK TARGETS gt_higher_moments
#HK DESTINATION ${CMAKE_INSTALL_LIBDIR}
#HK )
#HK
#HKinclude(CMakePackageConfigHelpers)
#HKconfigure_package_config_file(gt_higher_momentsConfig.cmake.in
#HK ${CMAKE_CURRENT_BINARY_DIR}/gt_higher_momentsConfig.cmake
#HK INSTALL_DESTINATION cmake)
#HK
#HKINSTALL(
#HK FILES
#HK ${CMAKE_CURRENT_BINARY_DIR}/gt_higher_momentsConfig.cmake
#HK DESTINATION cmake
#HK )


# the configure files will be installed by the config/cmake files
#
#INSTALL(
# EXPORT gt_higher_momentsConfig
# DESTINATION cmake
# )
#

0 comments on commit c3b0995

Please sign in to comment.