1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
--- a/cpp/dolfinx/CMakeLists.txt
+++ b/cpp/dolfinx/CMakeLists.txt
@@ -6,6 +6,13 @@
add_library(dolfinx)
target_compile_features(dolfinx PUBLIC cxx_std_20)
+if(PETSC_SCALAR_COMPLEX OR HAVE_SCALAR_COMPLEX)
+ set(LIB_NAME_EXT "_complex")
+else()
+ set(LIB_NAME_EXT "_real")
+endif()
+set_target_properties(dolfinx PROPERTIES OUTPUT_NAME "dolfinx${LIB_NAME_EXT}")
+
# ------------------------------------------------------------------------------
# Add source files to the target
set(DOLFINX_DIRS
@@ -324,10 +331,6 @@
string(REPLACE ";" " " PKG_CXXFLAGS "${CMAKE_CXX_FLAGS}")
string(REPLACE ";" " " PKG_LINKFLAGS "${CMAKE_EXE_LINKER_FLAGS}")
-# DOLFINX_EXTRA_CXX_FLAGS are used for the build (by adding to CMAKE_CXX_FLAGS)
-# but should not be included in the pkgconfig file (i.e. don't add to PKG_CXXFLAGS above)
-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DOLFINX_EXTRA_CXX_FLAGS}")
-
# Convert libraries to -L<libdir> -l<lib> form
foreach(_lib ${PKGCONFIG_DOLFINX_LIBS})
# Add -Wl,option directives
@@ -363,10 +366,10 @@
# Configure and install pkg-config file
configure_file(
${DOLFINX_SOURCE_DIR}/cmake/templates/dolfinx.pc.in
- ${CMAKE_BINARY_DIR}/dolfinx.pc @ONLY
+ ${CMAKE_BINARY_DIR}/dolfinx${LIB_NAME_EXT}.pc @ONLY
)
install(
- FILES ${CMAKE_BINARY_DIR}/dolfinx.pc
+ FILES ${CMAKE_BINARY_DIR}/dolfinx${LIB_NAME_EXT}.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
COMPONENT Development
)
--- a/cpp/cmake/templates/dolfinx.pc.in
+++ b/cpp/cmake/templates/dolfinx.pc.in
@@ -12,5 +12,5 @@
Version: @DOLFINX_VERSION@
Requires: @PKG_REQUIRES@
Conflicts:
-Libs: @PKG_LINKFLAGS@ -L${libdir} -ldolfinx
+Libs: @PKG_LINKFLAGS@ -L${libdir} -ldolfinx@LIB_NAME_EXT@
Cflags: @PKG_CXXFLAGS@ -DDOLFINX_VERSION=\"@DOLFINX_VERSION@\" ${definitions} -I${includedir} @PKG_INCLUDES@
--- a/python/test/unit/fem/test_custom_assembler.py
+++ b/python/test/unit/fem/test_custom_assembler.py
@@ -71,8 +71,10 @@
This function is not (yet) in the DOLFINx module because it is complicated
by needing to compile code.
"""
- if dolfinx.pkgconfig.exists("dolfinx"):
- dolfinx_pc = dolfinx.pkgconfig.parse("dolfinx")
+ has_petsc_complex = np.issubdtype(PETSc.ScalarType, np.complexfloating)
+ dolfinx_pc_name = "dolfinx_complex" if has_petsc_complex else "dolfinx_real"
+ if dolfinx.pkgconfig.exists(dolfinx_pc_name):
+ dolfinx_pc = dolfinx.pkgconfig.parse(dolfinx_pc_name)
else:
raise RuntimeError("Could not find DOLFINx pkg-config file")
--- a/cpp/cmake/templates/DOLFINXConfig.cmake.in
+++ b/cpp/cmake/templates/DOLFINXConfig.cmake.in
@@ -76,6 +76,9 @@
"$ENV{PETSC_DIR}/$ENV{PETSC_ARCH}/lib/pkgconfig:$ENV{PETSC_DIR}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}"
)
pkg_search_module(PETSC REQUIRED IMPORTED_TARGET PETSc petsc)
+ include(CheckSymbolExists)
+ set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${PETSC_INCLUDE_DIRS})
+ check_symbol_exists(PETSC_USE_COMPLEX petscconf.h PETSC_SCALAR_COMPLEX)
endif()
endif()
--- a/python/dolfinx/utils.py
+++ b/python/dolfinx/utils.py
@@ -27,11 +27,22 @@
RuntimeError: If PETSc library cannot be found for if more than
one library is found.
"""
+ import numpy as _np
import petsc4py as _petsc4py
petsc_dir = _petsc4py.get_config()["PETSC_DIR"]
petsc_arch = _petsc4py.lib.getPathArchPETSc()[1]
+ try:
+ if _np.issubdtype(_petsc4py.PETSc.ScalarType, _np.complexfloating):
+ scalar_type = "complex"
+ else:
+ scalar_type = "real"
+ except AttributeError:
+ # if petsc4py.PETSc is not available, read type from petsc_dir
+ scalar_type = "complex" if "complex" in petsc_dir else "real"
+
candidate_paths = [
+ os.path.join(petsc_dir, petsc_arch, "lib", f"libpetsc_{scalar_type}.so"),
os.path.join(petsc_dir, petsc_arch, "lib", "libpetsc.so"),
os.path.join(petsc_dir, petsc_arch, "lib", "libpetsc.dylib"),
]
--- a/cpp/CMakeLists.txt
+++ b/cpp/CMakeLists.txt
@@ -423,6 +423,12 @@
pkg_search_module(PETSC OPTIONAL IMPORTED_TARGET PETSc>=3.15 petsc>=3.15)
endif()
+ # Check if PETSc build uses real or complex scalars (this is configured in
+ # DOLFINxConfig.cmake.in)
+ include(CheckSymbolExists)
+ set(CMAKE_REQUIRED_INCLUDES ${PETSC_INCLUDE_DIRS})
+ check_symbol_exists(PETSC_USE_COMPLEX petscsystypes.h HAVE_SCALAR_COMPLEX)
+
# Setting for FeatureSummary
if(PETSC_FOUND)
message(
|