Detecting SLEPc via CMake
Hello, great package.
Is there a canonical way to detect slepc via CMake/pkg_config?
Is there a best practice, especially in conjunction with PETSc?
Designs
- Show closed items
Activity
-
Newest first Oldest first
-
Show all activity Show comments only Show history only
- Owner
For CMake, there is no official module to find SLEPc libraries, but if you google
slepc cmake module
you will find a couple of them that may be useful. I am not an expert in CMake.Regarding pkg-config, the following sample makefile should work.
default: ex1 ex1f PETSc.pc := $(PETSC_DIR)/$(PETSC_ARCH)/lib/pkgconfig/PETSc.pc SLEPc.pc := $(SLEPC_DIR)/$(PETSC_ARCH)/lib/pkgconfig/SLEPc.pc CC := $(shell pkg-config --variable=ccompiler $(PETSc.pc)) CXX := $(shell pkg-config --variable=cxxcompiler $(PETSc.pc)) FC := $(shell pkg-config --variable=fcompiler $(PETSc.pc)) CFLAGS := $(shell pkg-config --variable=cflags_extra $(PETSc.pc)) $(shell pkg-config --cflags-only-other $(PETSc.pc)) FFLAGS := $(shell pkg-config --variable=fflags_extra $(SLEPc.pc)) CPPFLAGS := $(shell pkg-config --cflags-only-I $(SLEPc.pc)) LDFLAGS := $(shell pkg-config --libs-only-L --libs-only-other $(SLEPc.pc)) LDFLAGS += $(patsubst -L%, $(shell pkg-config --variable=ldflag_rpath $(PETSc.pc))%, $(shell pkg-config --libs-only-L $(SLEPc.pc))) LDLIBS := $(shell pkg-config --libs-only-l $(SLEPc.pc)) print: @echo CC=$(CC) @echo CFLAGS=$(CFLAGS) @echo CPPFLAGS=$(CPPFLAGS) @echo LDFLAGS=$(LDFLAGS) @echo LDLIBS=$(LDLIBS)
- Author
Thanks for the quick answer.
Is there any plan to add CMake Support? I found a couple of CMake Modules for SLEPc, but considering the multitude of configuration options and the dependency on PETSc + the MPI problems, I thought you might have a silver bullet.
Cheers Jens
- Owner
No. Currently I don't have time or resources for this. And my knowledge of CMake is very limited.
- Owner
Thanks @jedbrown. I have tried the following
CMakeLists.txt
file and it works for me. Hope it is useful.cmake_minimum_required(VERSION 3.14) project(ex1-with-cmake C) find_package(PkgConfig REQUIRED) find_package(MPI REQUIRED) include_directories(${MPI_INCLUDE_PATH}) pkg_check_modules(PETSC_PKG REQUIRED IMPORTED_TARGET PETSc) pkg_check_modules(SLEPC_PKG REQUIRED IMPORTED_TARGET SLEPc) add_executable(ex1 ex1.c) if(MPI_COMPILE_FLAGS) set_target_properties(ex1 PROPERTIES COMPILE_FLAGS "${MPI_COMPILE_FLAGS}") endif() if(MPI_LINK_FLAGS) set_target_properties(ex1 PROPERTIES LINK_FLAGS "${MPI_LINK_FLAGS}") endif() target_link_libraries(ex1 PUBLIC ${MPI_LIBRARIES} PkgConfig::PETSC_PKG PkgConfig::SLEPC_PKG)
- Author
@jedbrown @joseroman thank you both. This is very helpful.
- Jose E. Roman closed
closed