Skip to content

Commit 649fc41

Browse files
committed
next petsc attempt...moved to FindPETSc and create my own targets based
on if it is STATIC or not
1 parent 708b844 commit 649fc41

4 files changed

Lines changed: 49 additions & 14 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,7 @@ if (PCMS_ENABLE_MESHFIELDS)
7676
message(STATUS "Found MeshFields: ${meshfields_DIR} (found version ${meshfields_VERSION})")
7777
endif()
7878

79-
find_package(PkgConfig REQUIRED)
80-
if(DEFINED PETSC_DIR)
81-
if(DEFINED PETSC_ARCH)
82-
set(ENV{PKG_CONFIG_PATH} "${PETSC_DIR}/${PETSC_ARCH}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}")
83-
else()
84-
set(ENV{PKG_CONFIG_PATH} "${PETSC_DIR}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}")
85-
endif()
86-
endif()
87-
pkg_check_modules(PETSC QUIET IMPORTED_TARGET PETSc)
88-
if(NOT PETSC_FOUND)
89-
pkg_check_modules(PETSC REQUIRED IMPORTED_TARGET petsc)
90-
endif()
79+
find_package(PETSc REQUIRED)
9180

9281
add_subdirectory(src)
9382

cmake/FindPETSc.cmake

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
find_package(PkgConfig REQUIRED)
2+
if(DEFINED PETSC_DIR)
3+
if(DEFINED PETSC_ARCH)
4+
set(ENV{PKG_CONFIG_PATH} "${PETSC_DIR}/${PETSC_ARCH}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}")
5+
else()
6+
set(ENV{PKG_CONFIG_PATH} "${PETSC_DIR}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}")
7+
endif()
8+
endif()
9+
10+
# we give an internal name _petsc
11+
# so we can fill up the PETSC_VARIABLE based
12+
# on static or not
13+
pkg_check_modules(_petsc PETSc)
14+
15+
if((_petsc_FOUND OR _petsc_STATIC_FOUND) AND _petsc_VERSION)
16+
set(PETSC_VERSION _petsc_VERSION)
17+
endif()
18+
19+
# note, there are a number of additional properties that
20+
# can be extracted / set on a target. We just do the basic
21+
# set for now. See: https://cmake.org/cmake/help/latest/module/FindPkgConfig.html
22+
if(_petsc_STATIC_FOUND)
23+
set(PETSC_LIBRARIES ${_petsc_STATIC_LINK_LIBRARIES})
24+
set(PETSC_INCLUDE_DIRS ${_petsc_STATIC_INCLUDE_DIRS})
25+
elseif(_petsc_FOUND)
26+
set(PETSC_LIBRARIES ${_petsc_LINK_LIBRARIES})
27+
set(PETSC_INCLUDE_DIRS ${_petsc_INCLUDE_DIRS})
28+
endif()
29+
message(WARNING "PETSC_LIBRARIES ${PETSC_LIBRARIES}")
30+
message(WARNING "PETSC_INCLUDE_DIRS ${PETSC_INCLUDE_DIRS}")
31+
32+
33+
if(NOT TARGET PETSc::PETSc)
34+
add_library(PETSc::PETSc INTERFACE IMPORTED GLOBAL)
35+
set_property(TARGET PETSc::PETSc PROPERTY INTERFACE_LINK_LIBRARIES ${PETSC_LIBRARIES})
36+
set_property(TARGET PETSc::PETSc PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${PETSC_INCLUDE_DIRS})
37+
endif()
38+
39+
40+
41+
include(FindPackageHandleStandardArgs)
42+
# TODO consider adding version check logic
43+
find_package_handle_standard_args(PETSc
44+
REQUIRED_VARS PETSC_LIBRARIES PETSC_INCLUDE_DIRS
45+
VERSION_VAR PETSC_VERSION)
46+

src/pcms/transfer/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ target_link_libraries(pcms_transfer PUBLIC
4848

4949
target_link_libraries(pcms_transfer PUBLIC meshfields::meshfields)
5050

51-
target_link_libraries(pcms_transfer PRIVATE PkgConfig::PETSC)
51+
target_link_libraries(pcms_transfer PRIVATE PETSc::PETSc)
5252

5353
target_include_directories(pcms_transfer INTERFACE
5454
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>

test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ if(Catch2_FOUND)
415415
# target_link_libraries(unit_tests PUBLIC meshfields::meshfields)
416416
# endif()
417417

418-
target_link_libraries(unit_tests PRIVATE PkgConfig::PETSC)
418+
target_link_libraries(unit_tests PRIVATE PETSc::PETSc)
419419

420420
target_link_libraries(unit_tests PUBLIC
421421
Catch2::Catch2

0 commit comments

Comments
 (0)