diff --git a/cmake/FindSCOTCH.cmake b/cmake/FindSCOTCH.cmake index c2a3272f4..7f811e2ec 100644 --- a/cmake/FindSCOTCH.cmake +++ b/cmake/FindSCOTCH.cmake @@ -1,28 +1,60 @@ +if(USE_SHARED_SCOTCH) + set(LIB_EXT so) + set(LIBRARY_TYPE "Shared") +else() + set(LIB_EXT a) + set(LIBRARY_TYPE "Static") +endif() + +message(STATUS "Searching for ${LIBRARY_TYPE} SCOTCH libraries.") + message(STATUS "Searching for PTSCOTCHparmetis library ...") -find_library(ptscotchparmetis_lib NAMES libptscotchparmetisv3.a HINTS ENV SCOTCH_PATH PATH_SUFFIXES lib) +find_library(ptscotchparmetis_lib NAMES libptscotchparmetisv3.${LIB_EXT} HINTS ENV SCOTCH_PATH PATH_SUFFIXES lib) find_path(ptscotchparmetis_inc parmetis.h HINTS ENV SCOTCH_PATH PATH_SUFFIXES include) message(STATUS "Searching for SCOTCH library ...") -find_library(scotch_lib NAMES libscotch.a HINTS ENV SCOTCH_PATH PATH_SUFFIXES lib) +find_library(scotch_lib NAMES libscotch.${LIB_EXT} HINTS ENV SCOTCH_PATH PATH_SUFFIXES lib) find_path(scotch_inc scotch.h HINTS ENV SCOTCH_PATH PATH_SUFFIXES include) message(STATUS "Searching for PTSCOTCH library ...") -find_library(ptscotch_lib NAMES libptscotch.a HINTS ENV SCOTCH_PATH PATH_SUFFIXES lib) +find_library(ptscotch_lib NAMES libptscotch.${LIB_EXT} HINTS ENV SCOTCH_PATH PATH_SUFFIXES lib) find_path(ptscotch_inc ptscotch.h HINTS ENV SCOTCH_PATH PATH_SUFFIXES include) message(STATUS "Searching for SCOTCHerr library ...") -find_library(scotcherr_lib NAMES libscotcherr.a HINTS ENV SCOTCH_PATH PATH_SUFFIXES lib) +find_library(scotcherr_lib NAMES libscotcherr.${LIB_EXT} HINTS ENV SCOTCH_PATH PATH_SUFFIXES lib) find_path(scotcherr_inc scotch.h HINTS ENV SCOTCH_PATH PATH_SUFFIXES include) message(STATUS "Searching for PTSCOTCHerr library ...") -find_library(ptscotcherr_lib NAMES libptscotcherr.a HINTS ENV SCOTCH_PATH PATH_SUFFIXES lib) +find_library(ptscotcherr_lib NAMES libptscotcherr.${LIB_EXT} HINTS ENV SCOTCH_PATH PATH_SUFFIXES lib) find_path(ptscotcherr_inc ptscotch.h HINTS ENV SCOTCH_PATH PATH_SUFFIXES include) -add_library(PTSCOTCHparmetis::PTSCOTCHparmetis STATIC IMPORTED) -add_library(SCOTCH::SCOTCH STATIC IMPORTED) -add_library(PTSCOTCH::PTSCOTCH STATIC IMPORTED) -add_library(SCOTCHerr::SCOTCHerr STATIC IMPORTED) -add_library(PTSCOTCHerr::PTSCOTCHerr STATIC IMPORTED) +set(required_libs ${ptscotchparmetis_lib} ${scotch_lib} ${ptscotch_lib} ${scotcherr_lib} ${ptscotcherr_lib}) + +foreach(lib ${required_libs}) + string(REGEX REPLACE "-NOTFOUND$" "" lib_path "${lib}") + if(NOT EXISTS ${lib_path}) + list(APPEND not_found_libs "${lib_path}.${LIB_EXT}") + endif() +endforeach() + +if(not_found_libs) + message(FATAL_ERROR "The following libraries were not found:\n${not_found_libs}\nPlease ensure the required libraries are available.") +endif() + + +if(USE_SHARED_SCOTCH) + add_library(PTSCOTCHparmetis::PTSCOTCHparmetis SHARED IMPORTED) + add_library(SCOTCH::SCOTCH SHARED IMPORTED) + add_library(PTSCOTCH::PTSCOTCH SHARED IMPORTED) + add_library(SCOTCHerr::SCOTCHerr SHARED IMPORTED) + add_library(PTSCOTCHerr::PTSCOTCHerr SHARED IMPORTED) +else() + add_library(PTSCOTCHparmetis::PTSCOTCHparmetis STATIC IMPORTED) + add_library(SCOTCH::SCOTCH STATIC IMPORTED) + add_library(PTSCOTCH::PTSCOTCH STATIC IMPORTED) + add_library(SCOTCHerr::SCOTCHerr STATIC IMPORTED) + add_library(PTSCOTCHerr::PTSCOTCHerr STATIC IMPORTED) +endif() set_target_properties(SCOTCH::SCOTCH PROPERTIES IMPORTED_LOCATION "${scotch_lib}" diff --git a/model/src/CMakeLists.txt b/model/src/CMakeLists.txt index 7dd7d82a2..b6946140c 100644 --- a/model/src/CMakeLists.txt +++ b/model/src/CMakeLists.txt @@ -158,6 +158,7 @@ endif() # Handle PDLIB, SCRIP, SCRIPNC build files directly instead of through configuration file if("PDLIB" IN_LIST switches) if("SCOTCH" IN_LIST switches) + set(USE_SHARED_SCOTCH OFF CACHE BOOL "Use shared SCOTCH") find_package(SCOTCH REQUIRED) target_sources(ww3_lib PRIVATE ${pdlib_src}) target_link_libraries(ww3_lib PUBLIC PTSCOTCHparmetis::PTSCOTCHparmetis)