diff --git a/CMakeLists.txt b/CMakeLists.txt index be24be9865..227de370b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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) @@ -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() @@ -302,6 +303,7 @@ TARGET_LINK_LIBRARIES( INSTALL ( TARGETS genten_mathlibs_c DESTINATION ${CMAKE_INSTALL_LIBDIR} + EXPORT genten ) SET(GENTEN_MATHLIBS genten_mathlibs_c @@ -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} ) @@ -482,6 +485,7 @@ ADD_EXECUTABLE ( TARGET_LINK_LIBRARIES (genten ${GENTEN_LINK_LIBS}) INSTALL ( TARGETS genten + EXPORT genten DESTINATION ${CMAKE_INSTALL_BINDIR} ) @@ -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}) diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt new file mode 100644 index 0000000000..58b947c0e7 --- /dev/null +++ b/config/CMakeLists.txt @@ -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}) + diff --git a/config/GentenConfig.cmake.in b/config/GentenConfig.cmake.in new file mode 100644 index 0000000000..2ee4f19e77 --- /dev/null +++ b/config/GentenConfig.cmake.in @@ -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() diff --git a/config/genten_setup_deps.cmake b/config/genten_setup_deps.cmake new file mode 100644 index 0000000000..89db4eec76 --- /dev/null +++ b/config/genten_setup_deps.cmake @@ -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() diff --git a/config/genten_setup_targets.cmake b/config/genten_setup_targets.cmake new file mode 100644 index 0000000000..813cd2036e --- /dev/null +++ b/config/genten_setup_targets.cmake @@ -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) diff --git a/joint_moments/CMakeLists.txt b/joint_moments/CMakeLists.txt index 970822d26c..8319ae0ebd 100644 --- a/joint_moments/CMakeLists.txt +++ b/joint_moments/CMakeLists.txt @@ -1,5 +1,7 @@ #--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 @@ -7,40 +9,22 @@ ADD_LIBRARY ( 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 +# ) +#