Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cmake for installation to a location #233

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 60 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ project(libROM
HOMEPAGE_URL "https://github.com/LLNL/libROM"
LANGUAGES C CXX Fortran)

include(GNUInstallDirs)

set(libROM_CMAKE_PATH ${CMAKE_SOURCE_DIR}/cmake)
set(libROM_CMAKE_MODULE_PATH ${libROM_CMAKE_PATH}/modules)
list(APPEND CMAKE_MODULE_PATH ${libROM_CMAKE_MODULE_PATH})
Expand Down Expand Up @@ -111,14 +113,27 @@ find_package(Doxygen 1.8.5)

find_package(GTest 1.6.0)

# Print the locations of the following libraries as it can be beneficial
# to specify them manually. Use for instance "-DMFEM_DIR=dir" as cmake
# input option to specify an external location for MFEM.
if (USE_MFEM)
find_library(MFEM mfem "${CMAKE_SOURCE_DIR}/dependencies/mfem" "${MFEM_DIR}/lib")
find_library(HYPRE HYPRE "${CMAKE_SOURCE_DIR}/dependencies/hypre/src/hypre/lib" "${HYPRE_DIR}/lib")
find_library(PARMETIS parmetis "${CMAKE_SOURCE_DIR}/dependencies/parmetis-4.0.3/build/lib/libparmetis" "${PARMETIS_DIR}/lib")
find_library(METIS metis "${CMAKE_SOURCE_DIR}/dependencies/parmetis-4.0.3/build/lib/libmetis" "${METIS_DIR}/lib")
find_path(MFEM_INCLUDES mfem.hpp "${CMAKE_SOURCE_DIR}/dependencies/mfem" "${MFEM_DIR}/include")
find_path(HYPRE_INCLUDES HYPRE.h "${CMAKE_SOURCE_DIR}/dependencies/hypre/src/hypre/include" "${HYPRE_DIR}/include")
find_path(PARMETIS_INCLUDES metis.h "${CMAKE_SOURCE_DIR}/dependencies/parmetis-4.0.3/metis/include" "${PARMETIS_DIR}/metis/include")
find_library(MFEM mfem "${MFEM_DIR}/lib" "${CMAKE_SOURCE_DIR}/dependencies/mfem")
find_path(MFEM_INCLUDES mfem.hpp "${MFEM_DIR}/include" "${CMAKE_SOURCE_DIR}/dependencies/mfem")
message("Found MFEM in: ${MFEM}")
message("Found MFEM_INCLUDES in: ${MFEM_INCLUDES}")

find_library(HYPRE HYPRE "${HYPRE_DIR}/lib" "${CMAKE_SOURCE_DIR}/dependencies/hypre/src/hypre/lib")
find_path(HYPRE_INCLUDES HYPRE.h "${HYPRE_DIR}/include" "${CMAKE_SOURCE_DIR}/dependencies/hypre/src/hypre/include")
message("Found HYPRE in: ${HYPRE}")
message("Found HYPRE_INCLUDES in: ${HYPRE_INCLUDES}")

find_library(METIS metis "${METIS_DIR}/lib" "${CMAKE_SOURCE_DIR}/dependencies/parmetis-4.0.3/build/lib/libmetis")
message("Found METIS in: ${METIS}")

find_library(PARMETIS parmetis "${PARMETIS_DIR}/lib" "${CMAKE_SOURCE_DIR}/dependencies/parmetis-4.0.3/build/lib/libparmetis")
find_path(PARMETIS_INCLUDES metis.h "${PARMETIS_DIR}/metis/include" "${CMAKE_SOURCE_DIR}/dependencies/parmetis-4.0.3/metis/include")
message("Found PARMETIS in: ${PARMETIS}")
message("Found PARMETIS_INCLUDES in: ${PARMETIS_INCLUDES}")
endif()

add_subdirectory(lib)
Expand Down Expand Up @@ -299,3 +314,41 @@ if(DOXYGEN_FOUND)
add_dependencies(doxygen_tagfile documentation)

endif(DOXYGEN_FOUND)

#-------------------------------------------------------------------------------
# Installation
# Configure CMake find_package() config files
#-------------------------------------------------------------------------------

# Default option
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()

include(CMakePackageConfigHelpers)

# Extract the enabled languages required to use ROM
get_property(ROM_ENABLED_LANGUAGES GLOBAL PROPERTY ENABLED_LANGUAGES)

configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
PATH_VARS
ROM_ENABLED_LANGUAGES
)

write_basic_package_version_file(
"${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)

install(FILES
${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
DESTINATION
${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
)

26 changes: 26 additions & 0 deletions cmake/libROMConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
###############################################################################
#
# Copyright (c) 2013-2023, Lawrence Livermore National Security, LLC
# and other libROM project developers. See the top-level COPYRIGHT
# file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
#
###############################################################################

@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@_Targets.cmake")

check_required_components("@PROJECT_NAME@")
check_required_components("ROM")

# Variables required for linking etc.
set(libROM_LIBRARIES ROM)
set(libROM_ENABLED_LANGUAGES "@ROM_ENABLED_LANGUAGES@")

check_required_components("@PROJECT_NAME@")
check_required_components("ROM")


# Somehow the dependencies should go here -> Did not yet get this working
45 changes: 41 additions & 4 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ list(APPEND source_files
linalg/Options.h
librom.h)

if (USE_MFEM)
if (USE_MFEM OR USE_EXTERNAL_MFEM)
list(APPEND source_files
mfem/PointwiseSnapshot.hpp
mfem/PointwiseSnapshot.cpp
Expand Down Expand Up @@ -129,12 +129,49 @@ target_link_libraries(ROM
${LAPACK_LIBRARIES} ${BLAS_LIBRARIES} ${MFEM} ${HYPRE} ${PARMETIS} ${METIS}
PRIVATE ${ZLIB_LIBRARIES} ZLIB::ZLIB)

target_include_directories(ROM PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}
target_include_directories(ROM
PUBLIC
${MFEM_INCLUDES}
${HYPRE_INCLUDES}
${PARMETIS_INCLUDES}
${HDF5_C_INCLUDE_DIRS}
${MPI_C_INCLUDE_DIRS}
${MFEM_C_INCLUDE_DIRS}
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> # Same as below with installation of headers
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)

#-------------------------------------------------------------------------------
# Installation
dreamer2368 marked this conversation as resolved.
Show resolved Hide resolved
#-------------------------------------------------------------------------------
# Set version information
set_target_properties(ROM
PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR})

# Default option
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()

install(TARGETS ROM
EXPORT libROM_Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

# Target information about that artefact
install(EXPORT libROM_Targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libROM
)

# Install headers
install(DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN *.h
PATTERN *.inl
PATTERN *.hpp
PATTERN *.ih
)

4 changes: 2 additions & 2 deletions lib/mfem/SampleMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -883,8 +883,8 @@ void Finish_s2sp_augmented(const int rank, const int nprocs,
{
if (s2sp_[i] == -1)
s2sp_[i] = s2sp[i];

MFEM_VERIFY(s2sp_[i] >= 0 && s2sp_[i] == s2sp[i], "");
else
MFEM_VERIFY(s2sp_[i] == s2sp[i], "Consistency check");
}
}
}
Expand Down