Skip to content
Open
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
13 changes: 13 additions & 0 deletions .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ jobs:
sudo cmake --install .
sudo ldconfig

- name: Run pkg-config test (C++)
working-directory: cpp/test/pkgconfig
run: |
make
make run

- name: Run tests via target (C++, serial and parallel)
working-directory: cpp/build
run: cmake --build . --target test
Expand Down Expand Up @@ -222,6 +228,13 @@ jobs:
cmake -B build -S . -DCMAKE_BUILD_TYPE=Developer -GNinja
cmake --build build

- name: Run pkg-config test (C++)
working-directory: cpp/test/pkgconfig
run: |
export PKG_CONFIG_PATH=$PETSC_DIR/$PETSC_ARCH/lib/pkgconfig:$SLEPC_DIR/$PETSC_ARCH/lib/pkgconfig:$PKG_CONFIG_PATH
make
make run

- name: Run tests (C++, serial)
working-directory: cpp/test/build
run: ctest -V --output-on-failure -R unittests_np_1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/fenicsx-refs.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
basix_repository=FEniCS/basix
basix_ref=main
basix_ref=jhale/add-pkgconfig
ufl_repository=FEniCS/ufl
ufl_ref=main
ffcx_repository=FEniCS/ffcx
Expand Down
2 changes: 1 addition & 1 deletion cpp/cmake/templates/dolfinx.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Version: @DOLFINX_VERSION@
Requires: @PKG_REQUIRES@
Conflicts:
Libs: @PKG_LINKFLAGS@ -L${libdir} -ldolfinx
Cflags: @PKG_CXXFLAGS@ -DDOLFINX_VERSION=\"@DOLFINX_VERSION@\" ${definitions} -I${includedir} @PKG_INCLUDES@
Cflags: @PKG_CXXFLAGS@ ${definitions} -I${includedir} @PKG_INCLUDES@
58 changes: 43 additions & 15 deletions cpp/dolfinx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,21 @@ install(
# Generate pkg-config file and install it

# Define packages that should be required by pkg-config file
set(PKG_REQUIRES "")
set(PKG_REQUIRES "spdlog")
list(APPEND PKG_REQUIRES "basix")
list(APPEND PKG_REQUIRES "pugixml")

if(TARGET PkgConfig::PETSC)
list(APPEND PKG_REQUIRES ${PETSC_MODULE_NAME})
endif()
if(TARGET PkgConfig::SLEPC)
list(APPEND PKG_REQUIRES ${SLEPC_MODULE_NAME})
endif()
if(TARGET PkgConfig::SUPERLU_DIST)
list(APPEND PKG_REQUIRES ${SUPERLU_DIST_MODULE_NAME})
endif()

string(REPLACE ";" " " PKG_REQUIRES "${PKG_REQUIRES}")

# Get link libraries and includes
get_target_property(
Expand All @@ -282,8 +296,13 @@ get_target_property(
get_target_property(
PKGCONFIG_DOLFINX_INCLUDE_DIRECTORIES
dolfinx
INTERFACE_SYSTEM_INCLUDE_DIRECTORIES
INTERFACE_INCLUDE_DIRECTORIES
)
if(PKGCONFIG_DOLFINX_INCLUDE_DIRECTORIES)
list(FILTER PKGCONFIG_DOLFINX_INCLUDE_DIRECTORIES EXCLUDE REGEX "^\\$<|>$")
else()
set(PKGCONFIG_DOLFINX_INCLUDE_DIRECTORIES "")
endif()

# Add imported targets to lists for creating pkg-config file
set(PKGCONFIG_DOLFINX_LIBS)
Expand Down Expand Up @@ -323,6 +342,24 @@ foreach(_target ${PKGCONFIG_DOLFINX_TARGET_LINK_LIBRARIES})
list(APPEND PKGCONFIG_DOLFINX_LIBS ${_libs})
endif()
endif()

# Special handling for ADIOS2 and HDF5 imported targets which expose
# IMPORTED_LOCATION_RELEASE (or IMPORTED_LOCATION) rather than
# INTERFACE_LINK_LIBRARIES
if(
"${_target}" MATCHES "^.*adios2::.*$"
OR "${_target}" MATCHES "^.*hdf5::.*$"
)
get_target_property(_libs ${_target} IMPORTED_LOCATION_RELEASE)

if(NOT _libs)
get_target_property(_libs ${_target} IMPORTED_LOCATION)
endif()

if(_libs)
list(APPEND PKGCONFIG_DOLFINX_LIBS ${_libs})
endif()
endif()
endif()
endforeach()

Expand All @@ -348,21 +385,12 @@ foreach(_def ${PKG_DOLFINX_DEFINITIONS})
set(PKG_DEFINITIONS "${PKG_DEFINITIONS} -D${_def}")
endforeach()

# Get basix definitions (this is required to propagate Basix definition to the
# pkg-config file, in the future Basix should create its own basix.pc file, see
# https://github.com/FEniCS/basix/issues/204)
get_target_property(
PKG_BASIX_DEFINITIONS
Basix::basix
INTERFACE_COMPILE_DEFINITIONS
)

foreach(_def ${PKG_BASIX_DEFINITIONS})
set(PKG_DEFINITIONS "${PKG_DEFINITIONS} -D${_def}")
endforeach()

# Convert compiler flags and definitions into space separated strings
string(REPLACE ";" " " PKG_CXXFLAGS "${CMAKE_CXX_FLAGS}")
get_target_property(_cxx_standard dolfinx CXX_STANDARD)
if(_cxx_standard)
string(APPEND PKG_CXXFLAGS " -std=c++${_cxx_standard}")
endif()
string(REPLACE ";" " " PKG_LINKFLAGS "${CMAKE_EXE_LINKER_FLAGS}")

# Convert libraries to -L<libdir> -l<lib> form
Expand Down
18 changes: 18 additions & 0 deletions cpp/test/pkgconfig/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
CXX = $(shell pkg-config --variable compiler dolfinx)
CXXFLAGS = $(shell pkg-config --cflags dolfinx)
LDLIBS = $(shell pkg-config --libs dolfinx)
LDFLAGS = -Wl,-rpath,$(shell pkg-config --variable=libdir dolfinx)

main.o: main.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@

main: main.o
$(CXX) $(LDFLAGS) $< -o $@ $(LDLIBS)

run: main
mpiexec -np 1 ./main

clean:
rm -f main main.o

.PHONY: run clean
24 changes: 24 additions & 0 deletions cpp/test/pkgconfig/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (C) 2025 Jack S. Hale
//
// This file is part of DOLFINx (https://www.fenicsproject.org)
//
// SPDX-License-Identifier: LGPL-3.0-or-later

#include <dolfinx/common/log.h>
#include <dolfinx/mesh/generation.h>
#include <mpi.h>

int main(int argc, char* argv[])
{
MPI_Init(&argc, &argv);
dolfinx::init_logging(argc, argv);

{
auto mesh = dolfinx::mesh::create_rectangle(
MPI_COMM_WORLD, {{{0.0, 0.0}, {1.0, 1.0}}}, {8, 8},
dolfinx::mesh::CellType::triangle);
}

MPI_Finalize();
return 0;
}
Loading