Skip to content

Commit

Permalink
Modify FindBlaze.cmake and FindSpectra.cmake to also allow finding in…
Browse files Browse the repository at this point in the history
…stallked Blaze and Spectra, respectively
  • Loading branch information
rserban committed Feb 23, 2025
1 parent b692226 commit 9854838
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 87 deletions.
100 changes: 71 additions & 29 deletions cmake/FindBlaze.cmake
Original file line number Diff line number Diff line change
@@ -1,43 +1,85 @@
# 2025-02-18 (Radu) modified to assume Blaze newer than 3.2 => no boost dependency
# Find Blaze
#
# This script requires one of the following input variables:
# - blaze_DIR: directory containing the Blaze package configuration script
# - blaze_INCLUDE_DIR: directory containing the subdirectory 'blaze/'
#
# This script provides the following outputs:
# - blaze_FOUND: a boolean variable indicating whether the library was found
# - blaze::blaze: imported target

# ----- Blaze library -----
set(Blaze_ROOT_TEMP ${Blaze_ROOT})
if(blaze_INCLUDE_DIR)

find_path(Blaze_ROOT NAMES blaze/Blaze.h PATHS ${Blaze_ROOT_TEMP} "/usr/include" "/usr/local/include")
if (NOT Blaze_ROOT)
message("WARNING Cannot find '<Blaze_ROOT>/blaze/system/Version.h'. Properly set Blaze_ROOT.")
if(EXISTS "${blaze_INCLUDE_DIR}/blaze/system/Version.h")
if(NOT TARGET blaze::blaze)
add_library(blaze::blaze INTERFACE IMPORTED)
set_target_properties(blaze::blaze PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${blaze_INCLUDE_DIR}")
endif()
set(blaze_FOUND TRUE)
if(NOT Blaze_FIND_QUIETLY)
message(STATUS "Found 'blaze/system/Version.h' in provided blaze_INCLUDE_DIR=${blaze_INCLUDE_DIR}")
endif()
else()
set(blaze_FOUND FALSE)
if(NOT Blaze_FIND_QUIETLY)
message(STATUS "Could not find 'blaze/system/Version.h' in the provided blaze_INCLUDE_DIR=${blaze_INCLUDE_DIR}")
endif()
endif()

else()

find_package(blaze NO_MODULE)

if(blaze_FOUND)
get_target_property(blaze_INCLUDE_DIR blaze::blaze INTERFACE_INCLUDE_DIRECTORIES)
if(NOT Blaze_FIND_QUIETLY)
message(STATUS "Blaze found through config script")
endif()
endif()

endif()

# Check Blaze version

if(NOT blaze_FOUND)
return()
endif()

# Extract Blaze version
find_file(Blaze_VERSION_FILENAME "Version.h" PATHS "${Blaze_ROOT}/blaze/system")
mark_as_advanced(FORCE Blaze_VERSION_FILENAME)
if(Blaze_VERSION_FILENAME)
file(READ ${Blaze_VERSION_FILENAME} Blaze_VERSION_FILE)
find_file(blaze_VERSION_FILENAME "Version.h" PATHS "${blaze_INCLUDE_DIR}/blaze/system")
mark_as_advanced(FORCE blaze_VERSION_FILENAME)

if(blaze_VERSION_FILENAME)

file(READ ${blaze_VERSION_FILENAME} Blaze_VERSION_FILE)

string(REGEX MATCH "#define BLAZE_MAJOR_VERSION ([0-9]*)" _Blaze_MAJOR_VERSION ${Blaze_VERSION_FILE})
set(Blaze_MAJOR_VERSION ${CMAKE_MATCH_1})
set(blaze_MAJOR_VERSION ${CMAKE_MATCH_1})
string(REGEX MATCH "#define BLAZE_MINOR_VERSION ([0-9]*)" _Blaze_MINOR_VERSION ${Blaze_VERSION_FILE})
set(Blaze_MINOR_VERSION ${CMAKE_MATCH_1})
set(Blaze_VERSION "${Blaze_MAJOR_VERSION}.${Blaze_MINOR_VERSION}")
set(blaze_MINOR_VERSION ${CMAKE_MATCH_1})
set(blaze_VERSION "${blaze_MAJOR_VERSION}.${blaze_MINOR_VERSION}")

if(NOT Blaze_FIND_QUIETLY)
message(STATUS "Blaze version file: ${Blaze_VERSION_FILENAME}")
message(STATUS "Blaze version: ${Blaze_VERSION}")
message(STATUS "Blaze version file: ${blaze_VERSION_FILENAME}")
message(STATUS "Blaze version: ${blaze_VERSION}")
endif()

if (blaze_VERSION VERSION_LESS "3.2")
set(blaze_FOUND FALSE)
if(NOT Blaze_FIND_QUIETLY)
mesage(STATUS "Blaze version older than 3.2.")
endif()
return()
endif()
set(Blaze_FOUND TRUE)

else()
message("WARNING Cannot find '<Blaze_ROOT>/blaze/system/Version.h'. Properly set Blaze_ROOT.")
endif()

# ----- BOOST -- required only for older versions of Blaze -----
set(blaze_FOUND FALSE)

if(NOT Blaze_FIND_QUIETLY)
message(STATUS "Cannot find header 'blaze/system/Version.h'")
endif()

if (Blaze_VERSION VERSION_LESS "3.2")
mesage("WARNING: Blaze newer than 3.2 required. Blaze support disabled.")
set(Blaze_FOUND FALSE)
return()
endif()

# Create Blaze::Blaze target
if (Blaze_ROOT AND NOT TARGET Blaze::Blaze)
add_library(Blaze::Blaze INTERFACE IMPORTED)
set_target_properties(Blaze::Blaze PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Blaze_ROOT}")
endif()

63 changes: 35 additions & 28 deletions cmake/FindSpectra.cmake
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@

#-------------------------------------------------------------------------------
# Find Spectra
# ATTENTION: Spectra library (https://github.com/yixuan/spectra) has its own spectra-config.cmake
# but needs to be installed; we provide an easier way

# This find script requires the following input variables:
# - Spectra_INCLUDE_DIR: shall contain the subdirectory named 'Spectra'
# This find script provides the following output variables/targets:
# - Spectra_FOUND: a boolean indicating whether the library was found
#
# This script requires one of the following input variables:
# - spectra_DIR: directory containing the Spectra package configuration script
# - spectra_INCLUDE_DIR: directory containing the subdirectory 'Spectra/'
#
# This script provides the following outputs:
# - spectra_FOUND: a boolean variable indicating whether the library was found
# - Spectra::Spectra: imported target

set(Spectra_FOUND TRUE)

find_path(Spectra_INCLUDE_DIR_INTERNAL NAMES SymEigsBase.h PATHS "${Spectra_INCLUDE_DIR}/Spectra" NO_CACHE)
mark_as_advanced(Spectra_INCLUDE_DIR_INTERNAL)

if (NOT Spectra_INCLUDE_DIR_INTERNAL)
message(NOTICE "Could not find '${Spectra_INCLUDE_DIR}/Spectra/SymEigsBase.h'. Set Spectra_INCLUDE_DIR to a folder containing the subfolder 'Spectra'.")
return()
endif()
if(spectra_INCLUDE_DIR)

if(EXISTS "${spectra_INCLUDE_DIR}/Spectra/KrylovSchurGEigsSolver.h")
if(NOT TARGET Spectra::Spectra)
add_library(Spectra::Spectra INTERFACE IMPORTED)
set_target_properties(Spectra::Spectra PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${spectra_INCLUDE_DIR}")
if(MSVC)
set_property(TARGET Spectra::Spectra PROPERTY INTERFACE_COMPILE_OPTIONS $<$<COMPILE_LANGUAGE:CXX>:/bigobj>)
endif()
endif()
set(spectra_FOUND TRUE)
if(NOT Spectra_FIND_QUIETLY)
message(STATUS "Found 'Spectra/KrylovSchurGEigsSolver.h' in provided spectra_INCLUDE_DIR=${spectra_INCLUDE_DIR}")
endif()
else()
set(spectra_FOUND FALSE)
if(NOT Spectra_FIND_QUIETLY)
message(STATUS "Could not find 'Spectra/KrylovSchurGEigsSolver.h' in the provided spectra_INCLUDE_DIR=${spectra_INCLUDE_DIR}")
endif()
endif()

set(Spectra_FOUND TRUE)
else()

if(Spectra_FOUND AND NOT TARGET Spectra::Spectra)
add_library(Spectra::Spectra INTERFACE IMPORTED)
set_target_properties(Spectra::Spectra PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Spectra_INCLUDE_DIR}")
if(MSVC)
set_property(TARGET Spectra::Spectra PROPERTY
INTERFACE_COMPILE_OPTIONS $<$<COMPILE_LANGUAGE:CXX>:/bigobj>)
find_package(spectra NO_MODULE)
if(spectra_FOUND)
get_target_property(spectra_INCLUDE_DIR Spectra::Spectra INTERFACE_INCLUDE_DIRECTORIES)
if(NOT Spectra_FIND_QUIETLY)
message(STATUS "Spectra found through config script")
endif()
endif()

endif()

endif()
24 changes: 14 additions & 10 deletions cmake/chrono-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -483,15 +483,17 @@ foreach(COMPONENT_UPPER ${Chrono_COMPONENTS})
set(CHRONO_${COMPONENT_UPPER}_FOUND OFF)
endif()

set(Blaze_ROOT "@Blaze_ROOT@" CACHE PATH "Blaze library location (should contain 'blaze/Blaze.h')")
set(blaze_INCLUDE_DIR "@blaze_INCLUDE_DIR@" CACHE PATH "Path to Blaze include directory (should contain a subdirectory 'blaze')")
find_package(Blaze QUIET)

if (NOT Blaze_FOUND)
message("WARNING: Chrono::Multicore requires Blaze, but Blaze was not found; set Blaze_ROOT to the Blaze installation directory")
if (NOT blaze_FOUND)
message("WARNING: Chrono::Multicore requires Blaze, but Blaze was not found; set blaze_INCLUDE_DIR or blaze_DIR")
set(CHRONO_${COMPONENT_UPPER}_FOUND OFF)
mark_as_advanced(CLEAR Blaze_ROOT)
mark_as_advanced(CLEAR blaze_INCLUDE_DIR)
mark_as_advanced(CLEAR blaze_DIR)
else()
mark_as_advanced(FORCE Blaze_ROOT)
mark_as_advanced(FORCE blaze_INCLUDE_DIR)
mark_as_advanced(FORCE blaze_DIR)
endif()

if (CHRONO_${COMPONENT_UPPER}_FOUND)
Expand All @@ -503,15 +505,17 @@ foreach(COMPONENT_UPPER ${Chrono_COMPONENTS})

elseif(${COMPONENT_UPPER} MATCHES "MODAL")

set(Spectra_INCLUDE_DIR "@Spectra_INCLUDE_DIR@" CACHE PATH "Path to Spectra include directory (should contain the subdirectory named 'Spectra')")
set(spectra_INCLUDE_DIR "@spectra_INCLUDE_DIR@" CACHE PATH "Path to Spectra include directory (should contain a subdirectory 'Spectra')")
find_package(Spectra QUIET)

if (NOT Spectra_FOUND)
message("WARNING: Chrono::modal requires Spectra, but Spectra was not found; set Spectra_INCLUDE_DIR to the Spectra include directory")
if (NOT spectra_FOUND)
message("WARNING: Chrono::modal requires Spectra, but Spectra was not found; set spectra_INCLUDE_DIR or spectra_DIR")
set(CHRONO_${COMPONENT_UPPER}_FOUND OFF)
mark_as_advanced(CLEAR Spectra_INCLUDE_DIR)
mark_as_advanced(CLEAR spectra_INCLUDE_DIR)
mark_as_advanced(CLEAR spectra_DIR)
else()
mark_as_advanced(FORCE Spectra_INCLUDE_DIR)
mark_as_advanced(FORCE spectra_INCLUDE_DIR)
mark_as_advanced(FORCE spectra_DIR)
endif()

if (CHRONO_${COMPONENT_UPPER}_FOUND)
Expand Down
3 changes: 2 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ endif()
#-----------------------------------------------------------------------------
# Eigen library
#-----------------------------------------------------------------------------
message(STATUS "Searching for Eigen3.")

message(STATUS "Searching for Eigen3")
find_package(Eigen3 3.3 QUIET)
if(EIGEN3_FOUND)
message(STATUS " Eigen3 found. EIGEN3_INCLUDE_DIR: ${EIGEN3_INCLUDE_DIR}")
Expand Down
35 changes: 23 additions & 12 deletions src/chrono_modal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
option(CH_ENABLE_MODULE_MODAL "Enable the Chrono Modal module" OFF)

# Return now if this module is not enabled
IF(NOT CH_ENABLE_MODULE_MODAL)
MARK_AS_ADVANCED(FORCE Spectra_INCLUDE_DIR)
RETURN()
ENDIF()

MESSAGE(STATUS "\n==== Chrono Modal module ====\n")
if(NOT CH_ENABLE_MODULE_MODAL)
mark_as_advanced(FORCE spectra_INCLUDE_DIR)
mark_as_advanced(FORCE spectra_DIR)
return()
endif()

MARK_AS_ADVANCED(CLEAR Spectra_INCLUDE_DIR)
message(STATUS "\n==== Chrono Modal module ====\n")

#-----------------------------------------------------------------------------

SET(Chrono_MODAL_SOURCES
set(Chrono_MODAL_SOURCES
ChModalAssembly.cpp
ChModalDamping.cpp
ChSymGenEigenvalueSolver.cpp
Expand All @@ -30,7 +29,7 @@ SET(Chrono_MODAL_SOURCES
ChKrylovSchurEig.cpp
)

SET(Chrono_MODAL_HEADERS
set(Chrono_MODAL_HEADERS
ChApiModal.h
ChModalAssembly.h
ChModalDamping.h
Expand All @@ -49,15 +48,27 @@ if(CH_ENABLE_MODULE_IRRLICHT)
)
endif()

SOURCE_GROUP("" FILES ${Chrono_MODAL_SOURCES} ${Chrono_MODAL_HEADERS})
source_group("" FILES ${Chrono_MODAL_SOURCES} ${Chrono_MODAL_HEADERS})

#-----------------------------------------------------------------------------
# Find Spectra
#-----------------------------------------------------------------------------

set(Spectra_INCLUDE_DIR "spectra/include" CACHE PATH "Path to Spectra include directory, shall contain the subdirectory named 'Spectra'.")

find_package(Spectra REQUIRED)
if(${spectra_FOUND})
message(STATUS "Spectra include dir: ${spectra_INCLUDE_DIR}")
mark_as_advanced(FORCE spectra_INCLUDE_DIR)
mark_as_advanced(FORCE spectra_DIR)
else()
message("ERROR: Spectra cannot be found. Set either spectra_INCLUDE_DIR to the location of the Spectra headers or provide location of spectra-config.cmake through spectra_DIR.")
set(spectra_INCLUDE_DIR "" CACHE PATH "Path to Spectra directory (should contain a subfolder named 'Spectra'")
set(spectra_DIR "" CACHE PATH "Path to Spectra config file (should contain the 'spectra-config.cmake' file")
mark_as_advanced(CLEAR spectra_INCLUDE_DIR)
mark_as_advanced(CLEAR spectra_DIR)
return()
endif()

set(spectra_INCLUDE_DIR ${spectra_INCLUDE_DIR} PARENT_SCOPE)

# ------------------------------------------------------------------------------
# Set dependencies on other Chrono modules
Expand Down
22 changes: 15 additions & 7 deletions src/chrono_multicore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ option(CH_ENABLE_MODULE_MULTICORE "Enable the Chrono Multicore module" OFF)
# Return now if this module is not enabled

if(NOT CH_ENABLE_MODULE_MULTICORE)
mark_as_advanced(FORCE Blaze_ROOT)
mark_as_advanced(FORCE blaze_INCLUDE_DIR)
mark_as_advanced(FORCE blaze_DIR)
mark_as_advanced(FORCE CH_USE_MULTICORE_DOUBLE)
return()
endif()
Expand All @@ -30,14 +31,21 @@ endif()

# Find Blaze
find_package(Blaze REQUIRED)
if(Blaze_FOUND)
mark_as_advanced(FORCE Blaze_ROOT)
if(blaze_FOUND)
message(STATUS "Blaze include dir: ${blaze_INCLUDE_DIR}")
mark_as_advanced(FORCE blaze_INCLUDE_DIR)
mark_as_advanced(FORCE blaze_DIR)
else()
set(Blaze_ROOT "" CACHE PATH "Blaze library location (should contain 'blaze/Blaze.h')")
mark_as_advanced(CLEAR Blaze_ROOT)
message(FATAL_ERROR "Chrono::Multicore requires Blaze, but Blaze was not found; set Blaze_ROOT to the Blaze installation directory")
message("ERROR: Blaze cannot be found. Set either blaze_INCLUDE_DIR to the location of the Blaze headers or provide location of blaze-config.cmake through blaze_DIR.")
set(blaze_INCLUDE_DIR "" CACHE PATH "Path to Blaze directory (should contain a subfolder named 'blaze'")
set(blaze_DIR "" CACHE PATH "Path to Blaze config file (should contain the 'blaze-config.cmake' file")
mark_as_advanced(CLEAR blaze_INCLUDE_DIR)
mark_as_advanced(CLEAR blaze_DIR)
return()
endif()

set(blaze_INCLUDE_DIR ${blaze_INCLUDE_DIR} PARENT_SCOPE)

mark_as_advanced(CLEAR CH_USE_MULTICORE_DOUBLE)

# ------------------------------------------------------------------------------
Expand Down Expand Up @@ -174,7 +182,7 @@ endif()
target_link_libraries(Chrono_multicore PRIVATE Chrono_core)
target_link_libraries(Chrono_multicore PRIVATE OpenMP::OpenMP_CXX)
target_link_libraries(Chrono_multicore PUBLIC Thrust::Thrust)
target_link_libraries(Chrono_multicore PUBLIC Blaze::Blaze)
target_link_libraries(Chrono_multicore PUBLIC blaze::blaze)
if(BOOST_REQUIRED)
target_include_directories(Chrono_multicore PRIVATE "${Boost_INCLUDE_DIRS}")
endif()
Expand Down

0 comments on commit 9854838

Please sign in to comment.