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

Add option to use shared scotch libs #1024

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
52 changes: 42 additions & 10 deletions cmake/FindSCOTCH.cmake
Original file line number Diff line number Diff line change
@@ -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}"
Expand Down
1 change: 1 addition & 0 deletions model/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down