Skip to content

Instantly share code, notes, and snippets.

@pkestene
Created April 22, 2023 09:19
Show Gist options
  • Save pkestene/50a0aaebb93a9e199a1e5f7e3cfdd7a9 to your computer and use it in GitHub Desktop.
Save pkestene/50a0aaebb93a9e199a1e5f7e3cfdd7a9 to your computer and use it in GitHub Desktop.
p4est cmake detection
# let say we require to use at least p4est version 2.8.5
set(P4EST_MINIMAL_VERSION 2.8.5)
# first try to detect P4ESTConfig.cmake somewhere in the CMAKE_PREFIX_PATH
# if found, we're ready to go using target P4EST::P4EST
find_package(P4EST ${P4EST_MINIMAL_VERSION} CONFIG QUIET)
if(P4EST_FOUND)
message(STATUS "P4EST was found with find_package, with version ${P4EST_VERSION}")
endif()
# if not found, we may try to detect p4est through pkgconfig (an autotools based build of p4est will provide it)
if(NOT P4EST_FOUND)
# use pkgconfig
find_package(PkgConfig REQUIRED)
pkg_check_modules(PC_P4EST QUIET IMPORTED_TARGET p4est>=${P4EST_MINIMAL_VERSION}) # <=======
if(PC_P4EST_FOUND)
message(STATUS "P4EST was found with pkgconfig, with version ${PC_P4EST_VERSION}")
add_library(P4EST::P4EST ALIAS PkgConfig::PC_P4EST)
endif()
endif()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment