Skip to content

Commit c46358b

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 c46358b

7 files changed

Lines changed: 87 additions & 15 deletions

File tree

.github/workflows/clang-tidy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ jobs:
203203
-DCMAKE_CXX_COMPILER=mpicxx \
204204
-DCMAKE_Fortran_COMPILER=mpifort \
205205
-DPCMS_ENABLE_PETSC=ON \
206+
-DPCMS_LINK_PETSC_STATIC=ON \
206207
-DPETSC_DIR=${{ runner.temp }}/petsc-openmpi \
207208
-DPETSC_ARCH=ubuntu-kokkos \
208209
-DPCMS_TIMEOUT=10 \

.github/workflows/cmake-test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ jobs:
224224
-DCMAKE_Fortran_COMPILER=`which mpifort`
225225
-DMPIEXEC_PREFLAGS="--oversubscribe"
226226
-DPCMS_ENABLE_PETSC=ON
227+
-DPCMS_LINK_PETSC_STATIC=ON
227228
-DPETSC_DIR=${{ runner.temp }}/petsc
228229
-DPETSC_ARCH=ubuntu-kokkos
229230
-DPCMS_TIMEOUT=10

.github/workflows/self-hosted.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ jobs:
189189
-DPCMS_TIMEOUT=20 \
190190
-DPCMS_ENABLE_SPDLOG=OFF \
191191
-DPCMS_ENABLE_PETSC=ON \
192+
-DPCMS_LINK_PETSC_STATIC=ON \
192193
-DPETSC_DIR=${workDir}/petsc \
193194
-DPETSC_ARCH=cuda-kokkos \
194195
-Dredev_DIR=$rdbdir/install/lib64/cmake/redev/ \
@@ -218,4 +219,4 @@ jobs:
218219
if: ${{ !cancelled() }}
219220
run: |
220221
echo "PCMS_WORK_DIR $PCMS_WORK_DIR"
221-
rm -rf $PCMS_WORK_DIR
222+
rm -rf $PCMS_WORK_DIR

CMakeLists.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ option(PCMS_ENABLE_Python "Enable pcms Python api" OFF)
2929
option(PCMS_ENABLE_PRINT "PCMS print statements enabled" ON)
3030
option(PCMS_ENABLE_SPDLOG "use spdlog for logging" ON)
3131

32+
if(DEFINED BUILD_SHARED_LIBS)
33+
set(_pcms_link_petsc_static_default "${BUILD_SHARED_LIBS}")
34+
else()
35+
set(_pcms_link_petsc_static_default OFF)
36+
endif()
37+
38+
option(PCMS_LINK_PETSC_STATIC "Use pkg-config --static results for PETSc"
39+
${_pcms_link_petsc_static_default})
40+
41+
unset(_pcms_link_petsc_static_default)
42+
3243
if(PCMS_ENABLE_SPDLOG)
3344
find_package(spdlog REQUIRED)
3445
endif()
@@ -76,18 +87,7 @@ if (PCMS_ENABLE_MESHFIELDS)
7687
message(STATUS "Found MeshFields: ${meshfields_DIR} (found version ${meshfields_VERSION})")
7788
endif()
7889

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()
90+
find_package(PETSc REQUIRED)
9191

9292
add_subdirectory(src)
9393

cmake/FindPETSc.cmake

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
find_file(_petsc_PC_FILE petsc.pc
16+
PATHS ${_petsc_LIBRARY_DIRS}/../lib/pkgconfig
17+
${_petsc_STATIC_LIBRARY_DIRS}/../lib/pkgconfig
18+
ENV PKG_CONFIG_PATH
19+
NO_DEFAULT_PATH)
20+
if(_petsc_PC_FILE)
21+
file(READ "${_petsc_PC_FILE}" _petsc_PC_CONTENTS)
22+
message(STATUS "PETSc .pc file: ${_petsc_PC_FILE}")
23+
message(STATUS "PETSc .pc contents:\n${_petsc_PC_CONTENTS}")
24+
endif()
25+
26+
if(_petsc_FOUND AND _petsc_VERSION)
27+
set(PETSC_VERSION ${_petsc_VERSION})
28+
endif()
29+
30+
# note, there are a number of additional properties that
31+
# can be extracted / set on a target. We just do the basic
32+
# set for now. See: https://cmake.org/cmake/help/latest/module/FindPkgConfig.html
33+
if(PCMS_LINK_PETSC_STATIC)
34+
message(STATUS "STATIC PETSC BUILD")
35+
set(PETSC_LIBRARIES ${_petsc_STATIC_LINK_LIBRARIES})
36+
set(PETSC_INCLUDE_DIRS ${_petsc_STATIC_INCLUDE_DIRS})
37+
set(PETSC_LIBRARY_DIRS ${_petsc_STATIC_LIBRARY_DIRS})
38+
set(PETSC_LDFLAGS ${_petsc_STATIC_LDFLAGS})
39+
set(PETSC_LDFLAGS_OTHER ${_petsc_STATIC_LDFLAGS_OTHER})
40+
elseif(_petsc_FOUND)
41+
message(STATUS "SHARED PETSC BUILD")
42+
set(PETSC_LIBRARIES ${_petsc_LINK_LIBRARIES})
43+
set(PETSC_INCLUDE_DIRS ${_petsc_INCLUDE_DIRS})
44+
set(PETSC_LIBRARY_DIRS ${_petsc_LIBRARY_DIRS})
45+
set(PETSC_LDFLAGS ${_petsc_LDFLAGS})
46+
set(PETSC_LDFLAGS_OTHER ${_petsc_LDFLAGS_OTHER})
47+
endif()
48+
message(STATUS "PETSC_LIBRARIES ${PETSC_LIBRARIES}")
49+
message(STATUS "PETSC_INCLUDE_DIRS ${PETSC_INCLUDE_DIRS}")
50+
message(STATUS "PETSC_LIBRARY_DIRS ${PETSC_LIBRARY_DIRS}")
51+
message(STATUS "PETSC_LDFLAGS ${PETSC_LDFLAGS}")
52+
message(STATUS "PETSC_LDFLAGS_OTHER ${PETSC_LDFLAGS_OTHER}")
53+
54+
55+
if(NOT TARGET PETSc::PETSc)
56+
add_library(PETSc::PETSc INTERFACE IMPORTED GLOBAL)
57+
set_target_properties(PETSc::PETSc PROPERTIES INTERFACE_LINK_LIBRARIES "${PETSC_LIBRARIES}"
58+
INTERFACE_INCLUDE_DIRECTORIES "${PETSC_INCLUDE_DIRS}"
59+
INTERFACE_LINK_DIRECTORIES "${PETSC_LIBRARY_DIRS}"
60+
INTERFACE_LINK_OPTIONS "${PETSC_LDFLAGS_OTHER}")
61+
endif()
62+
63+
64+
65+
include(FindPackageHandleStandardArgs)
66+
# TODO consider adding version check logic
67+
find_package_handle_standard_args(PETSc
68+
REQUIRED_VARS PETSC_LIBRARIES PETSC_INCLUDE_DIRS
69+
VERSION_VAR PETSC_VERSION)

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)